Skip to content

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Jan 15, 2026

based on

My little weekend-project:
Add a Diagnostic-Analyzer to our Compiler-Extensions, that warn users when a metric would not be emitted due to an unsupported numeric value type.

Context:
For the numeric type of a Metric, we currently allow 64-bit sized integral (signed) and floating-point numbers.
That means that e.g. ulong, System.Int128, or decimal are currently not supported by Sentry.
The compile-time constraint of Sentry.SentryMetric<T> only constrains to non-nullable value types.
Alternatively, we could have implemented respectively types overloads for the method groups:

public void EmitCounter<T>(string name, long value);
public void EmitCounter<T>(string name, float value);
public void EmitCounter<T>(string name, double value);
public void EmitCounter<T>(string name, long value, Scope? scope)
public void EmitCounter<T>(string name, float value, Scope? scope)
public void EmitCounter<T>(string name, double value, Scope? scope)
public void EmitCounter<T> ..

public void EmitGauge<T> ..
public void EmitDistribution<T> ..

To avoid this explosion of overloads per method group,
and be similar to the implementation of System.Diagnostics.Metrics,
we are not compile-time constraining unsupported types,
but are instead run-time constraining unsupported types (no-op and Debug-Diagnostic-Logging).

To still warn users unfamiliar with the System.Diagnostics.Metrics.Meter-based APIs,
I built an Analyzer over two weekends to guide new users.

SentrySdk.Experimental.Metrics.EmitCounter("my.counter", 1);
SentrySdk.Experimental.Metrics.EmitCounter("my.counter", 1m); //SENTRY1001
SentrySdk.Experimental.Metrics.EmitCounter("my.counter", StringComparison.CurrentCultureIgnoreCase); //SENTRY1001
SentrySdk.Experimental.Metrics.EmitCounter<ulong>("my.counter", default); //SENTRY1001

#skip-changelog

@Flash0ver Flash0ver self-assigned this Jan 15, 2026
@Flash0ver Flash0ver added Roslyn The .NET Compiler Platform, Roslyn Components and Extensions, Microsoft.CodeAnalysis Metrics labels Jan 15, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 15, 2026

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

Generated by 🚫 dangerJS against e7bb36f

@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

❌ Patch coverage is 73.58491% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.60%. Comparing base (d730432) to head (e7bb36f).

Files with missing lines Patch % Lines
...ensions/Analyzers/TraceConnectedMetricsAnalyzer.cs 70.83% 7 Missing and 7 partials ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##           feat/trace-connected-metrics    #4840      +/-   ##
================================================================
+ Coverage                         72.58%   72.60%   +0.01%     
================================================================
  Files                               495      497       +2     
  Lines                             17893    17946      +53     
  Branches                           3523     3533      +10     
================================================================
+ Hits                              12988    13029      +41     
- Misses                             4048     4054       +6     
- Partials                            857      863       +6     

☔ 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 16, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Metrics Roslyn The .NET Compiler Platform, Roslyn Components and Extensions, Microsoft.CodeAnalysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants