Skip to content

Commit 23bab8e

Browse files
committed
Added Metrics to Unity
1 parent 1cca280 commit 23bab8e

7 files changed

Lines changed: 180 additions & 1 deletion

File tree

static/app/components/onboarding/productSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ export const platformProductAvailability = {
489489
ProductSolution.PROFILING,
490490
ProductSolution.LOGS,
491491
],
492-
unity: [ProductSolution.LOGS],
492+
unity: [ProductSolution.LOGS, ProductSolution.METRICS],
493493
unreal: [ProductSolution.LOGS],
494494
} as Record<PlatformKey, ProductSolution[]>;
495495

static/app/data/platformCategories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ export const withMetricsOnboarding: Set<PlatformKey> = new Set([
485485
'ruby',
486486
'ruby-rack',
487487
'ruby-rails',
488+
'unity',
488489
]);
489490

490491
// List of platforms that do not have metrics support. We make use of this list in the product to not provide any Metrics
@@ -506,6 +507,7 @@ export const limitedMetricsSupportPrefixes: Set<string> = new Set([
506507
'react-native',
507508
'ruby',
508509
'flutter',
510+
'unity',
509511
]);
510512

511513
export const profiling: PlatformKey[] = [

static/app/gettingStartedDocs/unity/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type {Docs} from 'sentry/components/onboarding/gettingStartedDoc/types';
22

33
import {crashReport} from './crashReport';
44
import {logs} from './logs';
5+
import {metrics} from './metrics';
56
import {onboarding} from './onboarding';
67

78
const docs: Docs = {
89
onboarding,
910
feedbackOnboardingCrashApi: crashReport,
1011
crashReportOnboarding: crashReport,
1112
logsOnboarding: logs,
13+
metricsOnboarding: metrics,
1214
};
1315

1416
export default docs;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
2+
import {screen} from 'sentry-test/reactTestingLibrary';
3+
import {textWithMarkupMatcher} from 'sentry-test/utils';
4+
5+
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
6+
7+
import docs from '.';
8+
9+
describe('metrics', () => {
10+
it('unity metrics onboarding docs', () => {
11+
renderWithOnboardingLayout(docs, {
12+
selectedProducts: [ProductSolution.METRICS],
13+
});
14+
15+
expect(
16+
screen.getByText(
17+
textWithMarkupMatcher(/SentrySdk\.Metrics\.Increment/)
18+
)
19+
).toBeInTheDocument();
20+
});
21+
22+
it('does not render metrics configuration when metrics is not enabled', () => {
23+
renderWithOnboardingLayout(docs, {
24+
selectedProducts: [],
25+
});
26+
27+
expect(
28+
screen.queryByText(
29+
textWithMarkupMatcher(/SentrySdk\.Metrics\.Increment/)
30+
)
31+
).not.toBeInTheDocument();
32+
});
33+
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {ExternalLink} from '@sentry/scraps/link';
2+
3+
import type {
4+
ContentBlock,
5+
DocsParams,
6+
OnboardingConfig,
7+
} from 'sentry/components/onboarding/gettingStartedDoc/types';
8+
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/types';
9+
import {t, tct} from 'sentry/locale';
10+
11+
export const metricsVerify = (params: DocsParams): ContentBlock => ({
12+
type: 'conditional',
13+
condition: params.isMetricsSelected,
14+
content: [
15+
{
16+
type: 'text',
17+
text: t(
18+
'Send test metrics from your app to verify metrics are arriving in Sentry.'
19+
),
20+
},
21+
{
22+
type: 'code',
23+
language: 'csharp',
24+
code: `using Sentry;
25+
26+
SentrySdk.Metrics.Increment("player_interaction",
27+
tags: new Dictionary<string, string> {{"action", "jump"}, {"scene", "main_menu"}});
28+
SentrySdk.Metrics.Distribution("scene_load", 230,
29+
unit: MeasurementUnit.Duration.Millisecond,
30+
tags: new Dictionary<string, string> {{"scene", "world_1"}});
31+
SentrySdk.Metrics.Gauge("active_players", 42,
32+
tags: new Dictionary<string, string> {{"server", "us-east-1"}});`,
33+
},
34+
{
35+
type: 'text',
36+
text: tct('For more detailed information, see the [link:metrics documentation].', {
37+
link: <ExternalLink href="https://docs.sentry.io/platforms/unity/metrics/" />,
38+
}),
39+
},
40+
],
41+
});
42+
43+
export const metrics: OnboardingConfig = {
44+
install: () => [
45+
{
46+
type: StepType.INSTALL,
47+
content: [
48+
{
49+
type: 'text',
50+
text: tct(
51+
'Metrics for Unity are supported in Sentry SDK version [code:4.1.0] and above.',
52+
{
53+
code: <code />,
54+
}
55+
),
56+
},
57+
],
58+
},
59+
],
60+
configure: (params: DocsParams) => [
61+
{
62+
type: StepType.CONFIGURE,
63+
content: [
64+
{
65+
type: 'text',
66+
text: t(
67+
'To enable metrics in your Unity game, you need to configure the Sentry SDK with metrics enabled.'
68+
),
69+
},
70+
{
71+
type: 'text',
72+
text: tct(
73+
'Open your project settings: [strong:Tools > Sentry > Advanced > Metrics] and check the [strong:Enable Metrics] option.',
74+
{
75+
strong: <strong />,
76+
}
77+
),
78+
},
79+
{
80+
type: 'text',
81+
text: t('Alternatively, you can enable metrics programmatically:'),
82+
},
83+
{
84+
type: 'code',
85+
language: 'csharp',
86+
code: `SentrySdk.Init(options =>
87+
{
88+
options.Dsn = "${params.dsn.public}";
89+
90+
// Enable metrics to be sent to Sentry
91+
options.ExperimentalMetrics = new ExperimentalMetricsOptions
92+
{
93+
EnableCodeLocations = true
94+
};
95+
});`,
96+
},
97+
],
98+
},
99+
],
100+
verify: (params: DocsParams) => [
101+
{
102+
type: StepType.VERIFY,
103+
content: [metricsVerify(params)],
104+
},
105+
],
106+
};

static/app/gettingStartedDocs/unity/onboarding.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboa
44
import {screen} from 'sentry-test/reactTestingLibrary';
55
import {textWithMarkupMatcher} from 'sentry-test/utils';
66

7+
import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';
8+
79
import docs from '.';
810

911
function renderMockRequests() {
@@ -32,4 +34,16 @@ describe('unity onboarding docs', () => {
3234
)
3335
).toBeInTheDocument();
3436
});
37+
38+
it('renders metrics snippet when metrics product is selected', () => {
39+
renderMockRequests();
40+
41+
renderWithOnboardingLayout(docs, {
42+
selectedProducts: [ProductSolution.METRICS],
43+
});
44+
45+
expect(
46+
screen.getByText(textWithMarkupMatcher(/SentrySdk\.Metrics\.Increment/))
47+
).toBeInTheDocument();
48+
});
3549
});

static/app/gettingStartedDocs/unity/onboarding.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {getConsoleExtensions} from 'sentry/components/onboarding/gettingStartedD
1111
import {t, tct} from 'sentry/locale';
1212

1313
import {logsVerify} from './logs';
14+
import {metricsVerify} from './metrics';
1415

1516
const getVerifySnippet = () => `
1617
using Sentry; // On the top of the script
@@ -74,6 +75,19 @@ export const onboarding: OnboardingConfig = {
7475
},
7576
],
7677
},
78+
{
79+
type: 'conditional',
80+
condition: params.isMetricsSelected,
81+
content: [
82+
{
83+
type: 'text',
84+
text: tct(
85+
'To enable metrics, navigate to [strong:Tools > Sentry > Advanced > Metrics] and check the [strong:Enable Metrics] option.',
86+
{strong: <strong />}
87+
),
88+
},
89+
],
90+
},
7791
{
7892
type: 'text',
7993
text: tct(
@@ -113,6 +127,14 @@ export const onboarding: OnboardingConfig = {
113127
},
114128
] satisfies OnboardingStep[])
115129
: []),
130+
...(params.isMetricsSelected
131+
? ([
132+
{
133+
title: t('Metrics'),
134+
content: [metricsVerify(params)],
135+
},
136+
] satisfies OnboardingStep[])
137+
: []),
116138
{
117139
title: t('Troubleshooting'),
118140
content: [

0 commit comments

Comments
 (0)