-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: upgrade Sentry SDK to 6.1.0-alpha.1 and add trace-connected met… #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3452a2a
feat: upgrade Sentry SDK to 6.1.0-alpha.1 and add trace-connected met…
bruno-garcia d2655d6
test: add unit tests for SentryClientMetrics
bruno-garcia f299ca9
refactor: use IHub for SentryClientMetrics to improve testability
bruno-garcia 3991bd7
Delete test/SymbolCollector.Core.Tests/SentryClientMetricsTests.cs
bruno-garcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| #pragma warning disable SENTRYTRACECONNECTEDMETRICS // IHub.Metrics is experimental | ||
| using Sentry; | ||
| using Sentry.Extensibility; | ||
|
|
||
| namespace SymbolCollector.Core; | ||
|
|
||
| /// <summary> | ||
| /// A decorator for <see cref="ClientMetrics"/> that also emits metrics to Sentry's trace-connected metrics API. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This integrates with Sentry SDK 6.1.0's new experimental trace-connected metrics feature. | ||
| /// Metrics are attached to the current trace/span for correlation in Sentry's UI. | ||
| /// Enable with <c>options.Experimental.EnableMetrics = true</c>. | ||
| /// </remarks> | ||
| public class SentryClientMetrics : ClientMetrics | ||
| { | ||
| private readonly IHub _hub; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance using the default <see cref="HubAdapter.Instance"/>. | ||
| /// </summary> | ||
| public SentryClientMetrics() : this(HubAdapter.Instance) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance with the specified hub for metrics emission. | ||
| /// </summary> | ||
| /// <param name="hub">The Sentry hub to use for emitting metrics.</param> | ||
| public SentryClientMetrics(IHub hub) | ||
| { | ||
| _hub = hub; | ||
| } | ||
|
|
||
| private SentryTraceMetrics Metrics => _hub.Metrics; | ||
|
|
||
| /// <summary> | ||
| /// Records a file processed event, incrementing both local and Sentry counters. | ||
| /// </summary> | ||
| public override void FileProcessed() | ||
| { | ||
| base.FileProcessed(); | ||
| Metrics.AddCounter("symbol_collector.files_processed", 1); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a Mach-O file discovery. | ||
| /// </summary> | ||
| public override void MachOFileFound() | ||
| { | ||
| base.MachOFileFound(); | ||
| Metrics.AddCounter("symbol_collector.debug_images_found", 1, | ||
| [new KeyValuePair<string, object>("format", "macho")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records an ELF file discovery. | ||
| /// </summary> | ||
| public override void ElfFileFound() | ||
| { | ||
| base.ElfFileFound(); | ||
| Metrics.AddCounter("symbol_collector.debug_images_found", 1, | ||
| [new KeyValuePair<string, object>("format", "elf")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a Fat Mach-O file discovery. | ||
| /// </summary> | ||
| public override void FatMachOFileFound() | ||
| { | ||
| base.FatMachOFileFound(); | ||
| Metrics.AddCounter("symbol_collector.debug_images_found", 1, | ||
| [new KeyValuePair<string, object>("format", "fat_macho")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a failed upload. | ||
| /// </summary> | ||
| public override void FailedToUpload() | ||
| { | ||
| base.FailedToUpload(); | ||
| Metrics.AddCounter("symbol_collector.uploads", 1, | ||
| [new KeyValuePair<string, object>("status", "failed")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a parse failure. | ||
| /// </summary> | ||
| public override void FailedToParse() | ||
| { | ||
| base.FailedToParse(); | ||
| Metrics.AddCounter("symbol_collector.parse_failures", 1); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a successful upload. | ||
| /// </summary> | ||
| public override void SuccessfulUpload() | ||
| { | ||
| base.SuccessfulUpload(); | ||
| Metrics.AddCounter("symbol_collector.uploads", 1, | ||
| [new KeyValuePair<string, object>("status", "success")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records when a file already existed on the server. | ||
| /// </summary> | ||
| public override void AlreadyExisted() | ||
| { | ||
| base.AlreadyExisted(); | ||
| Metrics.AddCounter("symbol_collector.uploads", 1, | ||
| [new KeyValuePair<string, object>("status", "already_exists")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Removes jobs from the in-flight count. | ||
| /// </summary> | ||
| public override void JobsInFlightRemove(int tasksCount) | ||
| { | ||
| base.JobsInFlightRemove(tasksCount); | ||
| Metrics.RecordGauge("symbol_collector.jobs_in_flight", JobsInFlightCount); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds jobs to the in-flight count. | ||
| /// </summary> | ||
| public override void JobsInFlightAdd(int tasksCount) | ||
| { | ||
| base.JobsInFlightAdd(tasksCount); | ||
| Metrics.RecordGauge("symbol_collector.jobs_in_flight", JobsInFlightCount); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records bytes uploaded, emitting as a distribution for percentile analysis. | ||
| /// </summary> | ||
| public override void UploadedBytesAdd(long bytes) | ||
| { | ||
| base.UploadedBytesAdd(bytes); | ||
| Metrics.RecordDistribution("symbol_collector.uploaded_bytes", bytes, "byte"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records an unauthorized access error. | ||
| /// </summary> | ||
| public override void FileOrDirectoryUnauthorizedAccess() | ||
| { | ||
| base.FileOrDirectoryUnauthorizedAccess(); | ||
| Metrics.AddCounter("symbol_collector.access_errors", 1, | ||
| [new KeyValuePair<string, object>("type", "unauthorized")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a directory not found error. | ||
| /// </summary> | ||
| public override void DirectoryDoesNotExist() | ||
| { | ||
| base.DirectoryDoesNotExist(); | ||
| Metrics.AddCounter("symbol_collector.access_errors", 1, | ||
| [new KeyValuePair<string, object>("type", "directory_not_found")]); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Records a file not found error. | ||
| /// </summary> | ||
| public override void FileDoesNotExist() | ||
| { | ||
| base.FileDoesNotExist(); | ||
| Metrics.AddCounter("symbol_collector.access_errors", 1, | ||
| [new KeyValuePair<string, object>("type", "file_not_found")]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.