Skip to content

Commit ba6e2d3

Browse files
authored
feat(Unity): Metrics (#9421)
1 parent d2c60d1 commit ba6e2d3

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: Set Up Metrics
3+
description: "Learn how to measure the data points you care about by configuring Metrics in your Unity project."
4+
sidebar_order: 9000
5+
---
6+
7+
<Include name="feature-stage-alpha-metrics.mdx" />
8+
9+
<Note>
10+
11+
Metrics for Unity are supported with Sentry Unity SDK version `2.0.0` and above.
12+
13+
</Note>
14+
15+
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.
16+
17+
## Initialization
18+
19+
To enable metrics, opt in to the metrics feature:
20+
21+
```csharp
22+
public class SentryRuntimeConfiguration : SentryRuntimeOptionsConfiguration
23+
{
24+
public override void Configure(SentryUnityOptions options)
25+
{
26+
// Initialize some (non null) ExperimentalMetricsOptions to enable Sentry Metrics,
27+
options.ExperimentalMetrics = new ExperimentalMetricsOptions { EnableCodeLocations = true };
28+
}
29+
}
30+
```
31+
32+
## Emit a Counter
33+
34+
Counters are one of the more basic types of metrics and can be used to count certain event occurrences.
35+
36+
To emit a counter, do the following:
37+
38+
```csharp
39+
// Incrementing a counter by one for each button click.
40+
SentrySdk.Metrics.Increment("ButtonClicked",
41+
tags: new Dictionary<string, string> {{ "region", "us-west-1" }});
42+
```
43+
44+
## Emit a Distribution
45+
46+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
47+
48+
To emit a distribution, do the following:
49+
50+
```csharp
51+
// Adding '15' to a distribution used to track the loading time.
52+
SentrySdk.Metrics.Distribution("LoadingTime",
53+
15,
54+
unit: MeasurementUnit.Duration.Millisecond,
55+
tags: new Dictionary<string, string> {{ "region", "us-west-1" }});
56+
```
57+
58+
## Emit a Set
59+
60+
Sets are useful for looking at unique occurrences and counting the unique elements you added.
61+
62+
To emit a set, do the following:
63+
64+
```csharp
65+
// Adding a set of unique occurrences.
66+
SentrySdk.Metrics.Set("UserView", "Rufus",
67+
unit: MeasurementUnit.Custom("username"),
68+
tags: new Dictionary<string, string> {{ "region", "us-west-1" }});
69+
```
70+
71+
## Emit a Gauge
72+
73+
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.
74+
75+
To emit a gauge, do the following:
76+
77+
```csharp
78+
// Adding '15' to a gauge used to track the loading time.
79+
SentrySdk.Metrics.Gauge("LoadingTime",
80+
15,
81+
unit: MeasurementUnit.Duration.Millisecond,
82+
tags: new Dictionary<string, string> {{ "region", "us-west-1" }});
83+
```
84+
85+
## Emit a Timer
86+
87+
Timers can be used to measure the execution time of a specific block of code. They're implemented like distributions, but measured in seconds.
88+
89+
To emit a timer, do the following:
90+
91+
```csharp
92+
// Measure the time of execution within the using block
93+
using (SentrySdk.Metrics.StartTimer("bingo"))
94+
{
95+
// Your code goes here
96+
}
97+
```

docs/product/metrics/metrics-set-up.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Metrics are currently available on the following platforms:
2727
- [React Native](/platforms/react-native/metrics/)
2828
- [Remix](/platforms/javascript/guides/remix/metrics/)
2929
- [SvelteKit](/platforms/javascript/guides/sveltekit/metrics/)
30+
- [Unity](/platforms/unity/metrics/)
3031
- [Vanilla JavaScript](/platforms/javascript/metrics/)

0 commit comments

Comments
 (0)