-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(dotnet): Add metrics documentation for .NET #16054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Flash0ver
wants to merge
3
commits into
master
Choose a base branch
from
docs/dotnet-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| --- | ||
|
|
||
| <Alert> | ||
| 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. | ||
| </Alert> | ||
|
|
||
| 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 | ||
|
|
||
| <PlatformContent includePath="metrics/requirements" /> | ||
|
|
||
| ## Usage | ||
|
|
||
| <PlatformContent includePath="metrics/usage" /> | ||
|
|
||
| ## Options | ||
|
|
||
| <PlatformContent includePath="metrics/options" /> | ||
|
|
||
| ## Default Attributes | ||
|
|
||
| <PlatformContent includePath="metrics/default-attributes" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| The .NET SDK automatically sets several default attributes on all metrics to provide context and improve debugging: | ||
|
|
||
| <Include name="metrics/default-attributes/core" /> | ||
|
|
||
| <Include name="metrics/default-attributes/server" /> | ||
|
|
||
| <Include name="metrics/default-attributes/user" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #### EnableMetrics | ||
|
|
||
| Set to `false` in order to disable the `SentrySdk.Experimental.Metrics` APIs. | ||
|
|
||
| #### 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. | ||
|
|
||
| ```csharp | ||
| SentrySdk.Init(options => | ||
| { | ||
| options.Dsn = "___PUBLIC_DSN___"; | ||
| options.Experimental.SetBeforeSendMetric<int>(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<T>` 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<TAttribute>(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<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 `SentryMetric<T>` is generic, where the provided type argument defines the type of `SentryMetric<T>.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`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Metrics for .NET are supported in Sentry .NET SDK version `6.1.0` and above. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<string, object>("browser", "Firefox"), new KeyValuePair<string, object>("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<string, object>("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<string, object>("page", "/home")]); | ||
| ``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to decide what the API will look like before we can do the docs: