docs(dotnet): Add metrics documentation for .NET#16054
docs(dotnet): Add metrics documentation for .NET#16054
Conversation
Add comprehensive metrics documentation for .NET SDK including: - Main metrics page with overview and beta notice - Requirements section with SDK version and installation - Usage examples for Counter, Gauge, and Distribution metrics - Configuration options (EnableMetrics, SetBeforeSendMetric) - Default attributes documentation Based on Python and JavaScript metrics documentation structure. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
|
||
| #### SetBeforeSendMetric<T> | ||
|
|
||
| To filter metrics, or update them before they are sent to Sentry, you can use the `SetBeforeSendMetric<T>(Func<SentryMetric<T>, SentryMetric<T>?>)` option. If the callback returns `null`, the metric is not emitted. Attributes can also be updated in the callback delegate. |
There was a problem hiding this comment.
Need to decide what the API will look like before we can do the docs:
sfanahata
left a comment
There was a problem hiding this comment.
Need to fix the bug failing /options/ from rendering in the index.
There was a problem hiding this comment.
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.
| | `SetAttribute<TAttribute>(string key, TAttribute value)` | Method | Sets a key-value pair of data attached to the metric. Supported types are `string`, `bool`, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. | | ||
|
|
||
| The numeric value of `SentryMetric` has the same numeric type that the metric was emitted with. | ||
| The supported numeric types are `byte`, `short`, `int`, `long`, `float`, and `double`. |
There was a problem hiding this comment.
Duplicated numeric types text across two files
Low Severity
The exact text "The supported numeric types are byte, short, int, long, float, and double." appears verbatim in both usage/dotnet.mdx (line 6) and options/dotnet.mdx (lines 43-44). This duplication creates a maintenance burden if the supported types ever change.
There was a problem hiding this comment.
True ... but to be fair, there is two parts of the API:
- the "production" part via Emit, whose methods are all generic, dictating the type of the numeric value
- the "consumption" part via BeforeSendMetric, which is a callback receiving/returning an instance of
SentryMetric, which does not expose the Value directly, but through a "Try-Get-Value" method
We are not 100 % convinced that this is the best API shape, yet.
We are about to release this in v6.1.0 as an Experimental feature ... so we might be tweaking the API, and with that the documentation.
But for now, I'd like to be quite explicit ... and potentially duplicating.
And also ... I am quite sure that you will create a comment if future edits only update one part ... won't you 😉 ... and yes ... I am talking to a machine here right now ... it is getting late.
| @@ -0,0 +1,42 @@ | |||
| Metrics are enabled by default. Once you initialize the SDK, you can send metrics using the `SentrySdk.Experimental.Metrics` APIs. | |||
|
|
|||
| The `SentryMetricEmitter` type exposes three method groups that you can use to capture different types of metric information: `Counter`, `Gauge`, and `Distribution`. | |||
There was a problem hiding this comment.
Bug: The documentation refers to the SentryMetricEmitter type, but code examples use SentrySdk.Experimental.Metrics, which is confusing and inconsistent with other SDKs.
Severity: MEDIUM
Suggested Fix
Update the documentation to align the description with the code examples. Either state that metrics are sent via SentrySdk.Experimental.Metrics or clarify the relationship between SentrySdk.Experimental.Metrics and SentryMetricEmitter.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: platform-includes/metrics/usage/dotnet.mdx#L3
Potential issue: The documentation states that "The `SentryMetricEmitter` type exposes
three method groups," but the code examples show calls to
`SentrySdk.Experimental.Metrics.EmitCounter(...)`. This discrepancy is misleading
because the type `SentryMetricEmitter` never appears in the example code. A developer
following the text might search for `SentryMetricEmitter` and be unable to find it, or
try to instantiate it, leading to confusion. This is inconsistent with other Sentry SDKs
where the documented component name matches the code path used in examples.
There was a problem hiding this comment.
But it is consistent with Logs for .NET:
sentry-docs/platform-includes/logs/usage/dotnet.mdx
Lines 3 to 5 in 5685ebd
And the type name is indeed SentryMetricEmitter.
And the SDK-API (SentrySdk.Experimental.Metrics) is mentioned just the line above.
There was a problem hiding this comment.
I think it's fine for the property to have a more user friendly and less descriptive name than the type. People will use SentrySdk.Experimental.Metrics to get at the metrics functionality for the SDK... under the hood, we handle that by emitting metrics for them, but the shorter and more generic Metrics name is going to be easier for SDK users to work with.


DESCRIBE YOUR PR
Add initial metrics documentation for the .NET SDK.
Based on the user docs for Python and JavaScript.
IS YOUR CHANGE URGENT?
Help us prioritize incoming PRs by letting us know when the change needs to go live.
6.1.0. See also feat(metrics): Trace-connected Metrics sentry-dotnet#4834.SLA
Thanks in advance for your help!
PRE-MERGE CHECKLIST
Make sure you've checked the following before merging your changes: