Skip to content

Commit bf37ff6

Browse files
bruno-garciaclaude
andcommitted
feat: upgrade Sentry SDK to 6.1.0-alpha.1 and add trace-connected metrics
Upgrades Sentry .NET SDK from 6.0.0 to 6.1.0-alpha.1 to test the new experimental trace-connected metrics API from PR getsentry/sentry-dotnet#4834. Changes: - Upgrade Sentry SDK to 6.1.0-alpha.1 - Add SentryClientMetrics decorator that emits metrics to Sentry - Enable experimental metrics in all apps (Server, Console, Android) - Use SentryClientMetrics in DI registrations The new metrics API provides: - AddCounter: for counting events (files, uploads, errors) - RecordDistribution: for value distributions (uploaded bytes) - RecordGauge: for point-in-time values (jobs in flight) Metrics are automatically correlated with the active trace/span. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 78b2455 commit bf37ff6

File tree

6 files changed

+155
-3
lines changed

6 files changed

+155
-3
lines changed

src/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
<SentryVersion>6.0.0</SentryVersion>
4+
<SentryVersion>6.1.0-alpha.1</SentryVersion>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageVersion Include="Sentry" Version="$(SentryVersion)" />

src/SymbolCollector.Android.Library/Host.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static IHost Init(Context context, string dsn, string? sentryTrace = null
4040
{
4141
o.CaptureFailedRequests = true;
4242
o.EnableLogs = true;
43+
o.Experimental.EnableMetrics = true;
4344

4445
o.SetBeforeSend(@event =>
4546
{

src/SymbolCollector.Console/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SymbolCollector.Console;
1313

1414
internal class Program
1515
{
16-
private static readonly ClientMetrics Metrics = new ClientMetrics();
16+
private static readonly SentryClientMetrics Metrics = new SentryClientMetrics();
1717

1818
static async Task<int> Main(
1919
string? upload = null,
@@ -221,6 +221,7 @@ private static void Bootstrap(Args args)
221221
o.IsGlobalModeEnabled = true;
222222
o.CaptureFailedRequests = true;
223223
o.EnableLogs = true;
224+
o.Experimental.EnableMetrics = true;
224225

225226
#if DEBUG
226227
o.Environment = "development";
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+
}

src/SymbolCollector.Server/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private static IHostBuilder CreateHostBuilder(string[] args) =>
7575
o.MinimumBreadcrumbLevel = LogLevel.Debug;
7676
o.CaptureFailedRequests = true;
7777
o.EnableLogs = true;
78+
o.Experimental.EnableMetrics = true;
7879

7980
// https://github.com/getsentry/symbol-collector/issues/205
8081
// o.CaptureBlockingCalls = true;

src/SymbolCollector.Server/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public void ConfigureServices(IServiceCollection services)
2424

2525
services.AddSingleton<ObjectFileParser>();
2626
services.AddSingleton<FatBinaryReader>();
27-
services.AddSingleton<ClientMetrics>();
27+
services.AddSingleton<SentryClientMetrics>();
28+
services.AddSingleton<ClientMetrics>(sp => sp.GetRequiredService<SentryClientMetrics>());
2829
services.AddSingleton<IBatchFinalizer, SymsorterBatchFinalizer>();
2930
services.AddSingleton<ISymbolGcsWriter, SymbolGcsWriter>();
3031
services.AddSingleton<IStorageClientFactory, StorageClientFactory>();

0 commit comments

Comments
 (0)