|
| 1 | +namespace SymbolCollector.Core; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// A decorator for <see cref="ClientMetrics"/> that also emits metrics to Sentry's trace-connected metrics API. |
| 5 | +/// </summary> |
| 6 | +/// <remarks> |
| 7 | +/// This integrates with Sentry SDK 6.1.0's new experimental trace-connected metrics feature. |
| 8 | +/// Metrics are attached to the current trace/span for correlation in Sentry's UI. |
| 9 | +/// Access via <c>SentrySdk.Experimental.Metrics</c> after enabling with <c>options.Experimental.EnableMetrics = true</c>. |
| 10 | +/// </remarks> |
| 11 | +public class SentryClientMetrics : ClientMetrics |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Records a file processed event, incrementing both local and Sentry counters. |
| 15 | + /// </summary> |
| 16 | + public new void FileProcessed() |
| 17 | + { |
| 18 | + base.FileProcessed(); |
| 19 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.files_processed", 1); |
| 20 | + } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Records a Mach-O file discovery. |
| 24 | + /// </summary> |
| 25 | + public new void MachOFileFound() |
| 26 | + { |
| 27 | + base.MachOFileFound(); |
| 28 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.debug_images_found", 1, |
| 29 | + [new KeyValuePair<string, object>("format", "macho")]); |
| 30 | + } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Records an ELF file discovery. |
| 34 | + /// </summary> |
| 35 | + public new void ElfFileFound() |
| 36 | + { |
| 37 | + base.ElfFileFound(); |
| 38 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.debug_images_found", 1, |
| 39 | + [new KeyValuePair<string, object>("format", "elf")]); |
| 40 | + } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Records a Fat Mach-O file discovery. |
| 44 | + /// </summary> |
| 45 | + public new void FatMachOFileFound() |
| 46 | + { |
| 47 | + base.FatMachOFileFound(); |
| 48 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.debug_images_found", 1, |
| 49 | + [new KeyValuePair<string, object>("format", "fat_macho")]); |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Records a failed upload. |
| 54 | + /// </summary> |
| 55 | + public new void FailedToUpload() |
| 56 | + { |
| 57 | + base.FailedToUpload(); |
| 58 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.uploads", 1, |
| 59 | + [new KeyValuePair<string, object>("status", "failed")]); |
| 60 | + } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Records a parse failure. |
| 64 | + /// </summary> |
| 65 | + public new void FailedToParse() |
| 66 | + { |
| 67 | + base.FailedToParse(); |
| 68 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.parse_failures", 1); |
| 69 | + } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Records a successful upload. |
| 73 | + /// </summary> |
| 74 | + public new void SuccessfulUpload() |
| 75 | + { |
| 76 | + base.SuccessfulUpload(); |
| 77 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.uploads", 1, |
| 78 | + [new KeyValuePair<string, object>("status", "success")]); |
| 79 | + } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Records when a file already existed on the server. |
| 83 | + /// </summary> |
| 84 | + public new void AlreadyExisted() |
| 85 | + { |
| 86 | + base.AlreadyExisted(); |
| 87 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.uploads", 1, |
| 88 | + [new KeyValuePair<string, object>("status", "already_exists")]); |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Removes jobs from the in-flight count. |
| 93 | + /// </summary> |
| 94 | + public new void JobsInFlightRemove(int tasksCount) |
| 95 | + { |
| 96 | + base.JobsInFlightRemove(tasksCount); |
| 97 | + SentrySdk.Experimental.Metrics.RecordGauge("symbol_collector.jobs_in_flight", JobsInFlightCount); |
| 98 | + } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Adds jobs to the in-flight count. |
| 102 | + /// </summary> |
| 103 | + public new void JobsInFlightAdd(int tasksCount) |
| 104 | + { |
| 105 | + base.JobsInFlightAdd(tasksCount); |
| 106 | + SentrySdk.Experimental.Metrics.RecordGauge("symbol_collector.jobs_in_flight", JobsInFlightCount); |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Records bytes uploaded, emitting as a distribution for percentile analysis. |
| 111 | + /// </summary> |
| 112 | + public new void UploadedBytesAdd(long bytes) |
| 113 | + { |
| 114 | + base.UploadedBytesAdd(bytes); |
| 115 | + // Use distribution for uploaded bytes to capture percentiles and histograms |
| 116 | + SentrySdk.Experimental.Metrics.RecordDistribution("symbol_collector.uploaded_bytes", bytes, "byte"); |
| 117 | + } |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Records an unauthorized access error. |
| 121 | + /// </summary> |
| 122 | + public new void FileOrDirectoryUnauthorizedAccess() |
| 123 | + { |
| 124 | + base.FileOrDirectoryUnauthorizedAccess(); |
| 125 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.access_errors", 1, |
| 126 | + [new KeyValuePair<string, object>("type", "unauthorized")]); |
| 127 | + } |
| 128 | + |
| 129 | + /// <summary> |
| 130 | + /// Records a directory not found error. |
| 131 | + /// </summary> |
| 132 | + public new void DirectoryDoesNotExist() |
| 133 | + { |
| 134 | + base.DirectoryDoesNotExist(); |
| 135 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.access_errors", 1, |
| 136 | + [new KeyValuePair<string, object>("type", "directory_not_found")]); |
| 137 | + } |
| 138 | + |
| 139 | + /// <summary> |
| 140 | + /// Records a file not found error. |
| 141 | + /// </summary> |
| 142 | + public new void FileDoesNotExist() |
| 143 | + { |
| 144 | + base.FileDoesNotExist(); |
| 145 | + SentrySdk.Experimental.Metrics.AddCounter("symbol_collector.access_errors", 1, |
| 146 | + [new KeyValuePair<string, object>("type", "file_not_found")]); |
| 147 | + } |
| 148 | +} |
0 commit comments