Skip to content

Commit 14f190c

Browse files
kahestArthurKnaus
andauthored
feat(metrics): Add metrics onboarding docs for iOS (#69020)
Adds metrics onboarding docs for iOS. Also updates Swift snippet for experimental features and adds an Objective-C version of the snippet. closes getsentry/sentry-docs#9614 <img width="578" alt="Screenshot 2024-04-16 at 20 35 54" src="https://github.com/getsentry/sentry/assets/2005158/0c60ed1f-0cfb-4d6e-b205-bb4d8be068f0"> --------- Co-authored-by: ArthurKnaus <arthur.knaus@sentry.io>
1 parent b3fede3 commit 14f190c

File tree

2 files changed

+177
-5
lines changed

2 files changed

+177
-5
lines changed

static/app/data/platformCategories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ const customMetricBackendPlatforms: readonly PlatformKey[] = [
513513

514514
const customMetricFrontendPlatforms: readonly PlatformKey[] = [
515515
'android',
516+
'apple-ios',
516517
'electron',
517518
'flutter',
518519
'java-android',

static/app/gettingStartedDocs/apple/apple-ios.tsx

Lines changed: 176 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,86 @@
11
import ExternalLink from 'sentry/components/links/externalLink';
2+
import Link from 'sentry/components/links/link';
23
import List from 'sentry/components/list/';
34
import ListItem from 'sentry/components/list/listItem';
45
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
56
import type {
67
Docs,
8+
DocsParams,
79
OnboardingConfig,
810
} from 'sentry/components/onboarding/gettingStartedDoc/types';
911
import {appleFeedbackOnboarding} from 'sentry/gettingStartedDocs/apple/apple-macos';
1012
import {t, tct} from 'sentry/locale';
1113

12-
const getExperimentalFeaturesSnippet = () => `
14+
type Params = DocsParams;
15+
16+
const getInstallSnippet = () =>
17+
`brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios`;
18+
19+
const getExperimentalFeaturesSnippetSwift = () => `
1320
import Sentry
1421
1522
SentrySDK.start { options in
1623
// ...
1724
1825
// Enable all experimental features
1926
options.attachViewHierarchy = true
20-
options.enablePreWarmedAppStartTracing = true
2127
options.enableMetricKit = true
2228
options.enableTimeToFullDisplayTracing = true
2329
options.swiftAsyncStacktraces = true
30+
options.enableAppLaunchProfiling = true
31+
}`;
32+
33+
const getExperimentalFeaturesSnippetObjC = () => `
34+
@import Sentry;
35+
36+
[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
37+
// ...
38+
39+
// Enable all experimental features
40+
options.attachViewHierarchy = YES;
41+
options.enableMetricKit = YES;
42+
options.enableTimeToFullDisplayTracing = YES;
43+
options.swiftAsyncStacktraces = YES;
44+
options.enableAppLaunchProfiling = YES;
45+
}];`;
46+
47+
const getConfigureMetricsSnippetSwift = (params: Params) => `
48+
import Sentry
49+
50+
SentrySDK.start { options in
51+
options.dsn = "${params.dsn}"
52+
53+
options.enableMetrics = true
2454
}`;
2555

56+
const getConfigureMetricsSnippetObjC = (params: Params) => `
57+
@import Sentry;
58+
59+
[SentrySDK startWithConfigureOptions:^(SentryOptions * options) {
60+
options.Dsn = @"${params.dsn}";
61+
62+
options.enableMetrics = YES;
63+
}];`;
64+
65+
const getVerifyMetricsSnippetSwift = () => `
66+
import Sentry
67+
68+
SentrySDK.metrics
69+
.increment(key: "button_login_click",
70+
value: 1.0,
71+
tags: ["screen": "login"]
72+
)`;
73+
74+
const getVerifyMetricsSnippetObjC = () => `
75+
@import Sentry;
76+
77+
[SentrySDK.metrics
78+
incrementWithKey :@"button_login_click"
79+
value: 1.0
80+
unit: SentryMeasurementUnit.none
81+
tags: @{ @"screen" : @"login" }
82+
];`;
83+
2684
const onboarding: OnboardingConfig = {
2785
install: () => [
2886
{
@@ -42,7 +100,7 @@ const onboarding: OnboardingConfig = {
42100
configurations: [
43101
{
44102
language: 'bash',
45-
code: `brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios`,
103+
code: getInstallSnippet(),
46104
},
47105
],
48106
},
@@ -137,8 +195,20 @@ const onboarding: OnboardingConfig = {
137195
),
138196
configurations: [
139197
{
140-
language: 'swift',
141-
code: getExperimentalFeaturesSnippet(),
198+
code: [
199+
{
200+
label: 'Swift',
201+
value: 'swift',
202+
language: 'swift',
203+
code: getExperimentalFeaturesSnippetSwift(),
204+
},
205+
{
206+
label: 'Objective-C',
207+
value: 'c',
208+
language: 'c',
209+
code: getExperimentalFeaturesSnippetObjC(),
210+
},
211+
],
142212
},
143213
],
144214
},
@@ -175,10 +245,111 @@ const onboarding: OnboardingConfig = {
175245
],
176246
};
177247

248+
const metricsOnboarding: OnboardingConfig = {
249+
install: (params: DocsParams) => [
250+
{
251+
type: StepType.INSTALL,
252+
description: tct(
253+
'You need Sentry Cocoa SDK version [codeVersion:8.23.0] or higher. Learn more about installation methods in our [docsLink:full documentation].',
254+
{
255+
codeVersion: <code />,
256+
docsLink: <Link to={`/projects/${params.projectSlug}/getting-started/`} />,
257+
}
258+
),
259+
configurations: [
260+
{
261+
language: 'yml',
262+
partialLoading: params.sourcePackageRegistries?.isLoading,
263+
code: getInstallSnippet(),
264+
},
265+
],
266+
},
267+
],
268+
configure: (params: DocsParams) => [
269+
{
270+
type: StepType.CONFIGURE,
271+
description: t(
272+
'To enable capturing metrics, you need to enable the metrics feature.'
273+
),
274+
configurations: [
275+
{
276+
code: [
277+
{
278+
label: 'Swift',
279+
value: 'swift',
280+
language: 'swift',
281+
code: getConfigureMetricsSnippetSwift(params),
282+
},
283+
{
284+
label: 'Objective-C',
285+
value: 'c',
286+
language: 'c',
287+
code: getConfigureMetricsSnippetObjC(params),
288+
},
289+
],
290+
},
291+
],
292+
},
293+
],
294+
verify: () => [
295+
{
296+
type: StepType.VERIFY,
297+
description: tct(
298+
"Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:SentrySDK.metrics()] namespace. Try out this example:",
299+
{
300+
codeCounters: <code />,
301+
codeSets: <code />,
302+
codeDistribution: <code />,
303+
codeGauge: <code />,
304+
codeNamespace: <code />,
305+
}
306+
),
307+
configurations: [
308+
{
309+
configurations: [
310+
{
311+
code: [
312+
{
313+
label: 'Swift',
314+
value: 'swift',
315+
language: 'swift',
316+
code: getVerifyMetricsSnippetSwift(),
317+
},
318+
{
319+
label: 'Objective-C',
320+
value: 'c',
321+
language: 'c',
322+
code: getVerifyMetricsSnippetObjC(),
323+
},
324+
],
325+
},
326+
],
327+
},
328+
{
329+
description: t(
330+
'With a bit of delay you can see the data appear in the Sentry UI.'
331+
),
332+
},
333+
{
334+
description: tct(
335+
'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
336+
{
337+
docsLink: (
338+
<ExternalLink href="https://docs.sentry.io/platforms/apple/metrics/" />
339+
),
340+
}
341+
),
342+
},
343+
],
344+
},
345+
],
346+
};
347+
178348
const docs: Docs = {
179349
onboarding,
180350
feedbackOnboardingCrashApi: appleFeedbackOnboarding,
181351
crashReportOnboarding: appleFeedbackOnboarding,
352+
customMetricsOnboarding: metricsOnboarding,
182353
};
183354

184355
export default docs;

0 commit comments

Comments
 (0)