Skip to content

Commit d70f629

Browse files
feat(apple): Add metrics docs (#9554)
Add metrics docs for the Cocoa/Apple SDK.
1 parent 226c36c commit d70f629

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
title: Set Up Metrics
3+
description: "Learn how to measure the data points you care about by configuring Metrics in your app."
4+
---
5+
6+
<Include name="feature-stage-beta-metrics.mdx" />
7+
<Note>
8+
9+
Metrics are supported with Sentry Cocoa SDK version `8.23.0` and above.
10+
11+
</Note>
12+
13+
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.
14+
15+
## Enabling the Metrics Feature
16+
17+
Here's how to add Metrics to your application:
18+
19+
```swift {tabTitle:Swift}
20+
import Sentry
21+
22+
SentrySDK.start { options in
23+
options.dsn = "___PUBLIC_DSN___"
24+
25+
options.enableMetrics = true
26+
}
27+
```
28+
29+
```objc {tabTitle:Objective-C}
30+
@import Sentry;
31+
32+
[SentrySDK startWithConfigureOptions:^(SentryOptions * options) {
33+
options.Dsn = @"___PUBLIC_DSN___";
34+
35+
options.enableMetrics = YES;
36+
}];
37+
```
38+
39+
## Emit a Counter
40+
41+
Counters are one of the more basic types of metrics and can be used to count certain event occurrences.
42+
43+
To emit a counter, do the following:
44+
45+
```swift {tabTitle:Swift}
46+
import Sentry
47+
48+
SentrySDK.metrics
49+
.increment(key: "button_login_click",
50+
value: 1.0,
51+
tags: ["screen": "login"]
52+
)
53+
```
54+
55+
```objc {tabTitle:Objective-C}
56+
@import Sentry;
57+
58+
[SentrySDK.metrics
59+
incrementWithKey :@"button_login_click"
60+
value: 1.0
61+
unit: SentryMeasurementUnit.none
62+
tags: @{ @"screen" : @"login" }
63+
];
64+
```
65+
66+
## Emit a Distribution
67+
68+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
69+
70+
To emit a distribution, do the following:
71+
72+
```swift {tabTitle:Swift}
73+
import Sentry
74+
75+
SentrySDK.metrics
76+
.distribution(key: "image_download_duration",
77+
value: 150.0,
78+
unit: MeasurementUnitDuration.millisecond,
79+
tags: ["screen": "login"]
80+
)
81+
```
82+
83+
```objc {tabTitle:Objective-C}
84+
@import Sentry;
85+
86+
[SentrySDK.metrics
87+
distributionWithKey: @"button_login_click"
88+
value: 150.0
89+
unit: SentryMeasurementUnitDuration.millisecond
90+
tags: @{ @"screen" : @"login" }
91+
];
92+
```
93+
94+
## Emit a Set
95+
96+
Sets are useful for looking at unique occurrences and counting the unique elements you added.
97+
98+
To emit a set, do the following:
99+
100+
```swift {tabTitle:Swift}
101+
import Sentry
102+
103+
SentrySDK.metrics
104+
.set(key: "user_view",
105+
value: "jane",
106+
unit: MeasurementUnit(unit: "username"),
107+
tags: ["screen": "login"]
108+
)
109+
```
110+
111+
```objc {tabTitle:Objective-C}
112+
@import Sentry;
113+
114+
[SentrySDK.metrics
115+
setWithKey :@"button_login_click"
116+
value: @"jane"
117+
unit: [[SentryMeasurementUnit alloc] initWithUnit:@"username"]
118+
tags: @{ @"screen" : @"login" }
119+
];
120+
```
121+
122+
## Emit a Gauge
123+
124+
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.
125+
126+
To emit a gauge, do the following:
127+
128+
```swift {tabTitle:Swift}
129+
SentrySDK.metrics
130+
.gauge(key: "page_load",
131+
value: "jane",
132+
unit: MeasurementUnitDuration.millisecond,
133+
tags: ["screen": "login"]
134+
)
135+
```
136+
137+
```objc {tabTitle:Objective-C}
138+
@import Sentry;
139+
140+
[SentrySDK.metrics
141+
gaugeWithKey: @"page_load"
142+
value: 1.0
143+
unit: SentryMeasurementUnitDuration.millisecond
144+
tags: @{ @"screen" : @"login" }
145+
];
146+
```

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Metrics are currently available on the following platforms:
1616

1717
- [.NET](/platforms/dotnet/metrics/)
1818
- [Android](/platforms/android/metrics/)
19+
- [Apple](/platforms/apple/metrics/)
1920
- [Astro](/platforms/javascript/guides/astro/metrics/)
2021
- [Electron](/platforms/javascript/guides/electron/metrics/)
2122
- [Java](/platforms/java/metrics/)

0 commit comments

Comments
 (0)