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.

Related changesets

Related issues and discussions

Follow-ups

@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 d730432

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 17.02703% with 307 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.58%. Comparing base (2370080) to head (d730432).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/SentryMetric.cs 0.00% 96 Missing and 2 partials ⚠️
src/Sentry/SentryMetric.Factory.cs 0.00% 41 Missing ⚠️
src/Sentry/SentryTraceMetricsCallbacks.cs 0.00% 36 Missing ⚠️
src/Sentry/Internal/DefaultSentryTraceMetrics.cs 26.31% 28 Missing ⚠️
src/Sentry/SentryUnits.cs 0.00% 24 Missing ⚠️
src/Sentry/Protocol/TraceMetric.cs 0.00% 14 Missing ⚠️
src/Sentry/SentryTraceMetrics.Distribution.cs 0.00% 10 Missing ⚠️
src/Sentry/SentryTraceMetrics.Gauge.cs 0.00% 10 Missing ⚠️
src/Sentry/SentryMetricType.cs 0.00% 9 Missing ⚠️
src/Sentry/SentryTraceMetrics.Counter.cs 0.00% 8 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4834      +/-   ##
==========================================
- Coverage   73.79%   72.58%   -1.21%     
==========================================
  Files         483      495      +12     
  Lines       17551    17893     +342     
  Branches     3461     3523      +62     
==========================================
+ Hits        12952    12988      +36     
- Misses       3746     4048     +302     
- Partials      853      857       +4     

☔ 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
Comment on lines 170 to 175
public void SetAttribute(string key, object value)
{
_attributes ??= new Dictionary<string, object>();

_attributes[key] = new SentryAttribute(value);
}

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in e65db5f

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>
foreach (var attribute in attributes)
{
_attributes[attribute.Key] = new SentryAttribute(attribute.Value);
}
Copy link

Choose a reason for hiding this comment

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

Missing null value check in SetAttributes methods

Medium Severity

The documentation states that null attribute values should be "ignored", and the public SetAttribute<T> method correctly returns early when value is null. However, the internal SetAttributes methods that accept IEnumerable<KeyValuePair<string, object>> and ReadOnlySpan<KeyValuePair<string, object>> don't check if attribute.Value is null before passing it to new SentryAttribute(attribute.Value). This inconsistency means users passing attribute dictionaries with null values get different behavior than documented, and could cause issues depending on how SentryAttribute handles null.

Additional Locations (1)

Fix in Cursor Fix in Web

Flash0ver and others added 3 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>
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