Skip to content

Commit 62bd12c

Browse files
authored
feat(getting-started): Add Astro onboarding (#58435)
This change adds a getting started page for Astro. Furthermore it also re-adds astro to the platform picker. One noteable thing here: We're currently experimenting with enabeling performance and Replay by default and letting users opt out of both by specifying 0-sample rates. Therefore, the init code is simplest when everything is selected and additional options (the rates) are added, if products are un-selected.
1 parent 3d2dd0b commit 62bd12c

File tree

5 files changed

+293
-9
lines changed

5 files changed

+293
-9
lines changed

static/app/components/onboarding/productSelection.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export const platformProductAvailability = {
104104
ProductSolution.PERFORMANCE_MONITORING,
105105
ProductSolution.SESSION_REPLAY,
106106
],
107+
'javascript-astro': [
108+
ProductSolution.PERFORMANCE_MONITORING,
109+
ProductSolution.SESSION_REPLAY,
110+
],
107111
node: [ProductSolution.PERFORMANCE_MONITORING, ProductSolution.PROFILING],
108112
'node-azurefunctions': [
109113
ProductSolution.PERFORMANCE_MONITORING,
@@ -332,7 +336,10 @@ export function ProductSelection({
332336
// The package manager info is only shown for javascript platforms
333337
// until we improve multi snippet suppport
334338
const showPackageManagerInfo =
335-
platform?.indexOf('javascript') === 0 || platform?.indexOf('node') === 0;
339+
(platform?.indexOf('javascript') === 0 || platform?.indexOf('node') === 0) &&
340+
platform !== 'javascript-astro';
341+
342+
const showAstroInfo = platform === 'javascript-astro';
336343

337344
return (
338345
<Fragment>
@@ -348,6 +355,13 @@ export function ProductSelection({
348355
})}
349356
</TextBlock>
350357
)}
358+
{showAstroInfo && (
359+
<TextBlock noMargin>
360+
{tct("In this quick guide you'll use the [astrocli:astro] CLI to set up:", {
361+
astrocli: <strong />,
362+
})}
363+
</TextBlock>
364+
)}
351365
<Products>
352366
<Product
353367
label={t('Error Monitoring')}

static/app/data/platformPickerCategories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const browser: Set<PlatformKey> = new Set([
3333
'dart',
3434
'javascript',
3535
'javascript-angular',
36+
'javascript-astro',
3637
'javascript-ember',
3738
'javascript-gatsby',
3839
'javascript-nextjs',

static/app/data/platforms.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,13 @@ const platforms: PlatformIntegration[] = [
263263
language: 'javascript',
264264
link: 'https://docs.sentry.io/platforms/javascript/guides/angular/',
265265
},
266-
// TODO: comment back in when we have a getting-started page for Astro
267-
// {
268-
// id: 'javascript-astro',
269-
// name: 'Astro',
270-
// type: 'framework',
271-
// language: 'javascript',
272-
// link: 'https://docs.sentry.io/platforms/javascript/guides/astro/',
273-
// },
266+
{
267+
id: 'javascript-astro',
268+
name: 'Astro',
269+
type: 'framework',
270+
language: 'javascript',
271+
link: 'https://docs.sentry.io/platforms/javascript/guides/astro/',
272+
},
274273
{
275274
id: 'javascript-ember',
276275
name: 'Ember',
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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/productSelection';
6+
7+
import docs from './astro';
8+
9+
describe('javascript-astro onboarding docs', function () {
10+
it('renders onboarding docs correctly', () => {
11+
renderWithOnboardingLayout(docs);
12+
13+
// Renders main headings
14+
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
15+
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
16+
expect(screen.getByRole('heading', {name: 'Verify'})).toBeInTheDocument();
17+
18+
// Includes minimum required Astro version
19+
expect(screen.getByText(textWithMarkupMatcher(/Astro 3.0.0/))).toBeInTheDocument();
20+
21+
// Includes import statement
22+
expect(
23+
screen.getByText(textWithMarkupMatcher(/import sentry from "@sentry\/astro"/))
24+
).toBeInTheDocument();
25+
});
26+
27+
it("doesn't display any sample rates by default", () => {
28+
renderWithOnboardingLayout(docs, {
29+
selectedProducts: [
30+
ProductSolution.ERROR_MONITORING,
31+
ProductSolution.PERFORMANCE_MONITORING,
32+
ProductSolution.SESSION_REPLAY,
33+
],
34+
});
35+
36+
expect(
37+
screen.queryByText(textWithMarkupMatcher(/tracesSampleRate/))
38+
).not.toBeInTheDocument();
39+
expect(
40+
screen.queryByText(textWithMarkupMatcher(/replaysSessionSampleRate/))
41+
).not.toBeInTheDocument();
42+
expect(
43+
screen.queryByText(textWithMarkupMatcher(/replaysOnErrorSampleRate/))
44+
).not.toBeInTheDocument();
45+
});
46+
47+
it('disables performance setting the tracesSampleRate to 0', () => {
48+
renderWithOnboardingLayout(docs, {
49+
selectedProducts: [
50+
ProductSolution.ERROR_MONITORING,
51+
ProductSolution.SESSION_REPLAY,
52+
],
53+
});
54+
55+
expect(
56+
screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 0/))
57+
).toBeInTheDocument();
58+
});
59+
60+
it('disables replay by setting replay samplerates set to 0', () => {
61+
renderWithOnboardingLayout(docs, {
62+
selectedProducts: [
63+
ProductSolution.ERROR_MONITORING,
64+
ProductSolution.PERFORMANCE_MONITORING,
65+
],
66+
});
67+
68+
expect(
69+
screen.getByText(textWithMarkupMatcher(/replaysSessionSampleRate: 0/))
70+
).toBeInTheDocument();
71+
expect(
72+
screen.getByText(textWithMarkupMatcher(/replaysOnErrorSampleRate: 0/))
73+
).toBeInTheDocument();
74+
});
75+
});
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import {Fragment} from 'react';
2+
3+
import ExternalLink from 'sentry/components/links/externalLink';
4+
import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
5+
import {
6+
Docs,
7+
DocsParams,
8+
OnboardingConfig,
9+
} from 'sentry/components/onboarding/gettingStartedDoc/types';
10+
import {t, tct} from 'sentry/locale';
11+
12+
type Params = DocsParams;
13+
14+
const getSdkSetupSnippet = (params: Params) => `
15+
import { defineConfig } from "astro/config";
16+
import sentry from "@sentry/astro";
17+
18+
export default defineConfig({
19+
integrations: [
20+
sentry({
21+
dsn: "${params.dsn}",${
22+
params.isPerformanceSelected
23+
? ''
24+
: `
25+
tracesSampleRate: 0,`
26+
}${
27+
params.isReplaySelected
28+
? ''
29+
: `
30+
replaysSessionSampleRate: 0,
31+
replaysOnErrorSampleRate: 0,`
32+
}
33+
sourceMapsUploadOptions: {
34+
project: "${params.projectSlug}",
35+
authToken: process.env.SENTRY_AUTH_TOKEN,
36+
},
37+
}),
38+
],
39+
});
40+
`;
41+
42+
const getVerifyAstroSnippet = () => `
43+
<!-- your-page.astro -->
44+
<button onclick="throw new Error('This is a test error')">
45+
Throw test error
46+
</button>
47+
`;
48+
49+
const onboarding: OnboardingConfig = {
50+
introduction: () =>
51+
tct("Sentry's integration with [astroLink:Astro] supports Astro 3.0.0 and above.", {
52+
astroLink: <ExternalLink href="https://astro.build/" />,
53+
}),
54+
install: (_params: Params) => [
55+
{
56+
type: StepType.INSTALL,
57+
configurations: [
58+
{
59+
description: tct(
60+
'Install the [sentryAstroPkg:@sentry/astro] package with the [astroCli:astro] CLI:',
61+
{
62+
sentryAstroPkg: <code />,
63+
astroCli: <code />,
64+
}
65+
),
66+
language: 'bash',
67+
code: [
68+
{
69+
label: 'bash',
70+
value: 'bash',
71+
language: 'bash',
72+
code: `npx astro add @sentry/astro`,
73+
},
74+
],
75+
},
76+
],
77+
},
78+
],
79+
configure: (params: Params) => [
80+
{
81+
type: StepType.CONFIGURE,
82+
description: tct(
83+
'Open up your [astroConfig:astro.config.mjs] file and configure the DSN, and any other settings you need:',
84+
{
85+
astroConfig: <code />,
86+
}
87+
),
88+
configurations: [
89+
{
90+
code: [
91+
{
92+
label: 'JavaScript',
93+
value: 'javascript',
94+
language: 'javascript',
95+
code: getSdkSetupSnippet(params),
96+
},
97+
],
98+
},
99+
{
100+
description: tct(
101+
'Add your Sentry auth token to the [authTokenEnvVar:SENTRY_AUTH_TOKEN] environment variable:',
102+
{
103+
authTokenEnvVar: <code />,
104+
}
105+
),
106+
language: 'bash',
107+
code: [
108+
{
109+
value: 'bash',
110+
language: 'bash',
111+
label: 'bash',
112+
code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
113+
},
114+
],
115+
},
116+
{
117+
description: tct(
118+
'You can further customize your SDK by [manualSetupLink:manually inializing the SDK].',
119+
{
120+
manualSetupLink: (
121+
<ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/" />
122+
),
123+
}
124+
),
125+
},
126+
],
127+
},
128+
],
129+
verify: () => [
130+
{
131+
type: StepType.VERIFY,
132+
description: t(
133+
'Then throw a test error anywhere in your app, so you can test that everything is working:'
134+
),
135+
configurations: [
136+
{
137+
code: [
138+
{
139+
label: 'Astro',
140+
value: 'html',
141+
language: 'html',
142+
code: getVerifyAstroSnippet(),
143+
},
144+
],
145+
},
146+
],
147+
additionalInfo: (
148+
<Fragment>
149+
<p>
150+
{t(
151+
"If you're new to Sentry, use the email alert to access your account and complete a product tour."
152+
)}
153+
</p>
154+
<p>
155+
{t(
156+
"If you're an existing user and have disabled alerts, you won't receive this email."
157+
)}
158+
</p>
159+
</Fragment>
160+
),
161+
},
162+
],
163+
nextSteps: () => [
164+
{
165+
id: 'astro-manual-setup',
166+
name: t('Customize your SDK Setup'),
167+
description: t(
168+
'Learn how to further configure and customize your Sentry Astro SDK setup.'
169+
),
170+
link: 'https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/',
171+
},
172+
{
173+
id: 'performance-monitoring',
174+
name: t('Performance Monitoring'),
175+
description: t(
176+
'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
177+
),
178+
link: 'https://docs.sentry.io/platforms/javascript/guides/astro/performance/',
179+
},
180+
{
181+
id: 'session-replay',
182+
name: t('Session Replay'),
183+
description: t(
184+
'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
185+
),
186+
link: 'https://docs.sentry.io/platforms/javascript/guides/astro/session-replay/',
187+
},
188+
],
189+
};
190+
191+
const docs: Docs = {
192+
onboarding,
193+
};
194+
195+
export default docs;

0 commit comments

Comments
 (0)