From 4541e1708e5ffc25fdbab91cc2fdb452fc59d790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 16 Jan 2026 18:54:22 +0100 Subject: [PATCH 1/2] feat(dotnet): Add metrics documentation 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 --- .../platforms/dotnet/common/metrics/index.mdx | 32 ++++++++++++++ .../metrics/default-attributes/dotnet.mdx | 7 ++++ platform-includes/metrics/options/dotnet.mdx | 42 +++++++++++++++++++ .../metrics/requirements/dotnet.mdx | 1 + platform-includes/metrics/usage/dotnet.mdx | 42 +++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 docs/platforms/dotnet/common/metrics/index.mdx create mode 100644 platform-includes/metrics/default-attributes/dotnet.mdx create mode 100644 platform-includes/metrics/options/dotnet.mdx create mode 100644 platform-includes/metrics/requirements/dotnet.mdx create mode 100644 platform-includes/metrics/usage/dotnet.mdx diff --git a/docs/platforms/dotnet/common/metrics/index.mdx b/docs/platforms/dotnet/common/metrics/index.mdx new file mode 100644 index 0000000000000..384a794c4a71d --- /dev/null +++ b/docs/platforms/dotnet/common/metrics/index.mdx @@ -0,0 +1,32 @@ +--- +title: Set Up Metrics +sidebar_title: Metrics +description: "Metrics allow you to send, view and query counters, gauges and measurements sent from your applications within Sentry." +sidebar_order: 7 +sidebar_section: features +beta: true +--- + + +This feature is currently in open beta. Please reach out on [GitHub](https://github.com/getsentry/sentry-dotnet/discussions/4838) if you have feedback or questions. Features in beta are still in-progress and may have bugs. We recognize the irony. + + +Sentry metrics help you pinpoint and solve issues that impact user experience and app performance by measuring the data points that are important to you. You can track things like processing time, event size, user signups, and conversion rates, then correlate them back to tracing data in order to get deeper insights and solve issues faster. + +Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes. + +## Requirements + + + +## Usage + + + +## Options + + + +## Default Attributes + + diff --git a/platform-includes/metrics/default-attributes/dotnet.mdx b/platform-includes/metrics/default-attributes/dotnet.mdx new file mode 100644 index 0000000000000..9595fabe71d37 --- /dev/null +++ b/platform-includes/metrics/default-attributes/dotnet.mdx @@ -0,0 +1,7 @@ +The .NET SDK automatically sets several default attributes on all metrics to provide context and improve debugging: + + + + + + diff --git a/platform-includes/metrics/options/dotnet.mdx b/platform-includes/metrics/options/dotnet.mdx new file mode 100644 index 0000000000000..f131bddbd0d76 --- /dev/null +++ b/platform-includes/metrics/options/dotnet.mdx @@ -0,0 +1,42 @@ +#### EnableMetrics + +Set to `false` in order to disable the `SentrySdk.Experimental.Metrics` APIs. + +#### SetBeforeSendMetric + +To filter metrics, or update them before they are sent to Sentry, you can use the `SetBeforeSendMetric(Func, SentryMetric?>)` option. If the callback returns `null`, the metric is not emitted. Attributes can also be updated in the callback delegate. + +```csharp +SentrySdk.Init(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + options.Experimental.SetBeforeSendMetric(static metric => + { + if (metric.Name == "removed-metric") + { + return null; + } + + metric.SetAttribute("extra", "foo"); + + return metric; + }; +}); +``` + +The `beforeSendMetric` delegate receives a metric object, and should return the metric object if you want it to be sent to Sentry, or `null` if you want to discard it. + +The metric object of type `SentryMetric` has the following members: +- `Timestamp` Property: (`DateTimeOffset`) Timestamp indicating when the metric was emitted. +- `TraceId` Property: (`SentryId`) The trace ID of the trace this metric belongs to. +- `Type` Property: (`SentryMetricType`) The type of metric. One of `Counter`, `Gauge`, `Distribution`. +- `Name` Property: (`string`) The name of the metric. +- `Value` Property: (`T`) The numeric value of the metric. +- `SpanId` Property: (`SpanId?`) The span ID of the span that was active when the metric was emitted. +- `Unit` Property: (`string?`) The unit of measurement for the metric value. Applies to `Gauge` and `Distribution` only. +- `TryGetAttribute(string key, out TAttribute value)` Method: Gets the attribute value associated with the specified key. Returns `true` if the metric contains an attribute with the specified key and its value is of type `TAttribute`, otherwise `false`. +- `SetAttribute(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 `SentryMetric` is generic, where the provided type argument defines the type of `SentryMetric.Value` and has the same numeric type that the metric was emitted with. +You can register one callback per supported numeric type. +The supported numeric types are `byte`, `short`, `int`, `long`, `float`, and `double`. diff --git a/platform-includes/metrics/requirements/dotnet.mdx b/platform-includes/metrics/requirements/dotnet.mdx new file mode 100644 index 0000000000000..ec3462f59ca3b --- /dev/null +++ b/platform-includes/metrics/requirements/dotnet.mdx @@ -0,0 +1 @@ +Metrics for .NET are supported in Sentry .NET SDK version `6.1.0` and above. diff --git a/platform-includes/metrics/usage/dotnet.mdx b/platform-includes/metrics/usage/dotnet.mdx new file mode 100644 index 0000000000000..2c963e8b69cb5 --- /dev/null +++ b/platform-includes/metrics/usage/dotnet.mdx @@ -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 `SentryTraceMetrics` type exposes three method groups that you can use to capture different types of metric information: `Counter`, `Gauge`, and `Distribution`. + +All methods are generic, where the provided type argument defines the numeric value type that the metric is emitted with. +The supported numeric types are `byte`, `short`, `int`, `long`, `float`, and `double`. + +## Emit a Counter + +Counters are one of the more basic types of metrics and can be used to count certain event occurrences. + +To emit a counter, do the following: + +```csharp +// Record five total button clicks +SentrySdk.Experimental.Metrics.EmitCounter("button_click", 5, + [new KeyValuePair("browser", "Firefox"), new KeyValuePair("app_version", "1.0.0")]); +``` + +## Emit a Distribution + +Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`. + +To emit a distribution, do the following: + +```csharp +// Add '15.0' to a distribution used for tracking the loading times per page. +SentrySdk.Experimental.Metrics.EmitDistribution("page_load", 15.0, SentryUnits.Duration.Millisecond, + [new KeyValuePair("page", "/home")]); +``` + +## Emit a Gauge + +Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. They can be represented in a more space-efficient way than distributions, but they can't be used to get percentiles. If percentiles aren't important to you, we recommend using gauges. + +To emit a gauge, do the following: + +```csharp +// Add '15.0' to a gauge used for tracking the loading times for a page. +SentrySdk.Experimental.Metrics.EmitGauge("page_load", 15.0, SentryUnits.Duration.Millisecond, + [new KeyValuePair("page", "/home")]); +``` From 540b231238ad9d39773c884b45c29da2a6070a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 16 Jan 2026 21:49:50 +0100 Subject: [PATCH 2/2] ref(dotnet): increment Heading of Metric-Types for Usage --- platform-includes/metrics/usage/dotnet.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform-includes/metrics/usage/dotnet.mdx b/platform-includes/metrics/usage/dotnet.mdx index 2c963e8b69cb5..4d1f5cbb6eac5 100644 --- a/platform-includes/metrics/usage/dotnet.mdx +++ b/platform-includes/metrics/usage/dotnet.mdx @@ -5,7 +5,7 @@ The `SentryTraceMetrics` type exposes three method groups that you can use to ca All methods are generic, where the provided type argument defines the numeric value type that the metric is emitted with. The supported numeric types are `byte`, `short`, `int`, `long`, `float`, and `double`. -## Emit a Counter +### Emit a Counter Counters are one of the more basic types of metrics and can be used to count certain event occurrences. @@ -17,7 +17,7 @@ SentrySdk.Experimental.Metrics.EmitCounter("button_click", 5, [new KeyValuePair("browser", "Firefox"), new KeyValuePair("app_version", "1.0.0")]); ``` -## Emit a Distribution +### Emit a Distribution Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`. @@ -29,7 +29,7 @@ SentrySdk.Experimental.Metrics.EmitDistribution("page_load", 15.0, SentryUnits.D [new KeyValuePair("page", "/home")]); ``` -## Emit a Gauge +### Emit a Gauge Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. They can be represented in a more space-efficient way than distributions, but they can't be used to get percentiles. If percentiles aren't important to you, we recommend using gauges.