Skip to content

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Jan 9, 2026

Implementation of Trace-connected Metrics
See https://develop.sentry.dev/sdk/telemetry/metrics/

This changeset contains the initial implementation of Trace-connected Metrics for Sentry.

Changes

  • made Batch-Buffer generic, so that it can be used for both Structured Logging and Trace-connected Metrics
  • added new types (SentryTraceMetrics and derived), which follow the same pattern and structure from Structured Logs
  • the SDK-APIs are generic, which are inspired by the System.Diagnostics.Metrics APIs of the BCL / System.Diagnostics.DiagnosticSource package
  • naming of the public APIs differs a bit from the SDK spec in order to be idiomatic .NET
  • currently, made APIs experimental

Please see the discussion comments below to discuss these design decisions.

Related changesets

Related issues and discussions

Follow-ups

Enable public beta

  • Sentry Docs: dotnet platform
  • Sentry Docs: Supported Platforms overview
  • Sentry Onboarding
  • then, enable in Sentry "Platform Categories"

@Flash0ver Flash0ver self-assigned this Jan 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 0798441

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 79.33884% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.88%. Comparing base (c25d450) to head (0798441).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/SentryMetricEmitter.Distribution.cs 30.00% 14 Missing ⚠️
src/Sentry/SentryMetricEmitter.Gauge.cs 30.00% 14 Missing ⚠️
src/Sentry/Internal/DefaultSentryMetricEmitter.cs 68.42% 9 Missing and 3 partials ⚠️
src/Sentry/Internal/Polyfills.cs 0.00% 10 Missing ⚠️
src/Sentry/SentryMetric.cs 87.32% 7 Missing and 2 partials ⚠️
src/Sentry/SentryMetric.Factory.cs 76.19% 5 Missing ⚠️
src/Sentry/SentryMetricEmitter.Counter.cs 50.00% 4 Missing ⚠️
src/Sentry/BindableSentryOptions.cs 25.00% 2 Missing and 1 partial ⚠️
src/Sentry/Internal/BatchProcessor.cs 96.36% 0 Missing and 2 partials ⚠️
src/Sentry/Internal/DisabledSentryMetricEmitter.cs 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4834      +/-   ##
==========================================
+ Coverage   73.85%   73.88%   +0.02%     
==========================================
  Files         483      494      +11     
  Lines       17578    17868     +290     
  Branches     3464     3509      +45     
==========================================
+ Hits        12983    13201     +218     
- Misses       3741     3808      +67     
- Partials      854      859       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Flash0ver Flash0ver marked this pull request as ready for review January 9, 2026 21:09
bruno-garcia added a commit to getsentry/symbol-collector that referenced this pull request Jan 11, 2026
…rics

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 <noreply@anthropic.com>
bruno-garcia added a commit to getsentry/symbol-collector that referenced this pull request Jan 11, 2026
…rics

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 (Core, Server, Console)
- Fix duplicate ClientMetrics registration in Core/Startup.cs

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 <noreply@anthropic.com>
bruno-garcia added a commit to getsentry/symbol-collector that referenced this pull request Jan 11, 2026
…rics

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
- Make ClientMetrics methods virtual for proper polymorphism
- Enable experimental metrics in all apps (Server, Console, Android)
- Use SentryClientMetrics in DI registrations (Core, Server, Console)
- Fix duplicate ClientMetrics registration in Core/Startup.cs

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 <noreply@anthropic.com>
bruno-garcia added a commit to getsentry/symbol-collector that referenced this pull request Jan 12, 2026
#252)

* 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
- Make ClientMetrics methods virtual for proper polymorphism
- Enable experimental metrics in all apps (Server, Console, Android)
- Use SentryClientMetrics in DI registrations (Core, Server, Console)
- Fix duplicate ClientMetrics registration in Core/Startup.cs

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 <noreply@anthropic.com>

* test: add unit tests for SentryClientMetrics

Adds tests to verify that:
- SentryClientMetrics emits trace_metric items to Sentry
- All metric types (Counter, Distribution, Gauge) are emitted
- Base class counters are also incremented (dual emission)
- Polymorphism works correctly (override vs new)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: use IHub for SentryClientMetrics to improve testability

- SentryClientMetrics now accepts IHub in constructor (defaults to HubAdapter.Instance)
- Tests use isolated SDK instances with recording transport
- Each test initializes/disposes its own SDK for proper isolation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Delete test/SymbolCollector.Core.Tests/SentryClientMetricsTests.cs

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Flash0ver and others added 4 commits January 16, 2026 13:21
Provides hierarchical constants for metric units supported by Sentry Relay,
organized into Duration, Information, and Fraction categories.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@Flash0ver Flash0ver mentioned this pull request Feb 4, 2026
@Flash0ver Flash0ver changed the title feat(metrics): Trace-connected Metrics (Implementation) feat(metrics): Trace-connected Metrics Feb 5, 2026
@jamescrosswell
Copy link
Collaborator

@Flash0ver is there anything outstanding on this PR now or are we good to go?

@Flash0ver
Copy link
Member Author

@Flash0ver is there anything outstanding on this PR now or are we good to go?

@jamescrosswell, not from my perspective, considering the follow-ups #4882 and #4894.

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think we're good to go 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants