Skip to content

Commit 37294bb

Browse files
committed
restores 'metrics'
1 parent 8c5b443 commit 37294bb

File tree

1 file changed

+100
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)