Skip to content

Commit 648c30f

Browse files
Lms24shanamatthews
andauthored
feat(js): Add Documentation for Sentry Astro SDK (#8267)
This change includes adjustments for Astro in the following pages: * Getting Started shows the semi-automatic setup via the `astro` CLI * Added "Manual Setup" page similarly, to SvelteKit, Remix and NextJS with all possible configuration options * Adjusted source map docs to not display the full range of source maps upload material. The Astro SDK ships with the Vite plugin, so there shouldn't be too much need for other resources than troubleshooting. * Added Astro specific setup for Replay (This is the first SDK that actually enables Replay by default. However, there are two ways how users can manually customize or add Replay). * Added various platform includes for performance monitoring snippets --------- Co-authored-by: Shana Matthews <[email protected]>
1 parent c96877c commit 648c30f

File tree

22 files changed

+502
-3
lines changed

22 files changed

+502
-3
lines changed

src/components/orgAuthTokenNote.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function OrgAuthTokenNote() {
3838
<ExternalLink href={`https://sentry.io/auth/login/?next=${url}`}>
3939
sign in
4040
</ExternalLink>{' '}
41-
to create a token directly from the docs.
41+
to create a token directly from this page.
4242
</Note>
4343
</SignedInCheck>
4444

@@ -48,7 +48,7 @@ export function OrgAuthTokenNote() {
4848
<ExternalLink href={orgAuthTokenUrl} target="_blank">
4949
manually create an Auth Token
5050
</ExternalLink>{' '}
51-
or create a token directly from the docs. A created token will only be visible
51+
or create a token directly from this page. A created token will only be visible
5252
once right after creation - make sure to copy it!
5353
</Alert>
5454
</SignedInCheck>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
You can pass an `Error` object to `captureException()` to have it captured as an event. It's also possible to pass non-`Error` objects and strings, but be aware that the resulting events in Sentry may be missing a stack trace.
2+
3+
```javascript
4+
import * as Sentry from "@sentry/astro";
5+
6+
try {
7+
aFunctionThatMightFail();
8+
} catch (err) {
9+
Sentry.captureException(err);
10+
}
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
If you're using our Astro SDK, distributed tracing will work out of the box for the client and server runtimes.
2+
To get around possible [Browser CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issues, you should define `tracePropagationTargets` on the client-side.
3+
4+
```js
5+
// sentry.client.config.js
6+
Sentry.init({
7+
dsn: "___PUBLIC_DSN___",
8+
integrations: [new BrowserTracing()],
9+
tracePropagationTargets: ["https://myproject.org", /^\/api\//],
10+
});
11+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```javascript
2+
import * as Sentry from "@sentry/astro";
3+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Get started by adding your DSN to your Astro config file:
2+
3+
<SignInNote />
4+
5+
```javascript {filename:astro.config.mjs}
6+
import { defineConfig } from "astro/config";
7+
import sentry from "@sentry/astro";
8+
9+
export default defineConfig({
10+
integrations: [
11+
sentry({
12+
dsn: "___PUBLIC_DSN___",
13+
sourceMapsUploadOptions: {
14+
project: "___PROJECT_SLUG___",
15+
authToken: process.env.SENTRY_AUTH_TOKEN,
16+
},
17+
}),
18+
],
19+
});
20+
```
21+
22+
Once you've added your `dsn`, the SDK will automatically capture and send errors and performance events to Sentry.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
We recommend installing the SDK by using the `astro` CLI:
2+
3+
```bash
4+
npx astro add @sentry/astro
5+
```
6+
7+
The `astro` CLI installs the SDK package and adds the Sentry integration to your `astro.config.mjs` file.
8+
9+
To finish the setup, configure the Sentry integration.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Sentry's Astro SDK enables automatic reporting of errors and performance data.
2+
3+
<Alert level="warning">
4+
5+
The Astro SDK is in **Alpha** and may undergo **breaking changes**.
6+
Please report any issues you encounter in our [Github Repository](https://github.com/getsentry/sentry-javascript/issues/new/choose).
7+
8+
</Alert>
9+
10+
## Compatibility
11+
12+
The minimum supported Astro version is `3.0.0`.
13+
This SDK currently only works on Node runtimes.
14+
Non-Node runtimes, like Vercel's Edge runtime or Cloudflare Pages, are currently not supported.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Add Readable Stack Traces to Errors
2+
3+
To get readable stack traces in your production builds, add the `SENTRY_AUTH_TOKEN` environment variable to your environment, like in a `.env` file or in your CI setup.
4+
5+
<OrgAuthTokenNote />
6+
7+
```bash {filename:.env}
8+
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
9+
```
10+
11+
This, in combination with your `sourceMapsUploadOptions` configuration, will <PlatformLink to="/sourcemaps">upload source maps</PlatformLink> to Sentry every time you make a production build.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Trigger a test error somewhere in your Astro app, for example in one of your pages:
2+
3+
```html {filename: home.astro}
4+
<button onclick="throw new Error('This is a test error')">
5+
Throw test error
6+
</button>
7+
```
8+
9+
<Note>
10+
11+
Errors triggered from within Browser DevTools are sandboxed and won't trigger an error handler. Place the snippet directly in your code instead.
12+
13+
</Note>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The Sentry Astro SDK provides a `BrowserTracing` integration to add automatic instrumentation for monitoring the performance of browser applications, which is enabled by default.
2+
The SDK also automatically enables performance monitoring in your server-side code.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Either set `tracesSampleRate` in your `astro.config.mjs` file or in `sentry.(client|server).init.js`:
2+
3+
<SignInNote />
4+
5+
```javascript {tabTitle:Integration Config}{filename:astro.config.mjs}
6+
import { defineConfig } from "astro/config";
7+
import sentryAstro from "@sentry/astro";
8+
9+
export default defineConfig({
10+
integrations: [
11+
sentryAstro({
12+
dsn: "___PUBLIC_DSN___",
13+
tracesSampleRate: 1.0,
14+
}),
15+
],
16+
});
17+
```
18+
19+
```javascript {tabTitle:Custom Config (client)} {filename:sentry.client.config.js}
20+
import * as Sentry from "@sentry/astro";
21+
22+
Sentry.init({
23+
dsn: "___PUBLIC_DSN___",
24+
tracesSampleRate: 1.0,
25+
});
26+
```
27+
28+
```javascript {tabTitle:Custom Config (server)} {filename:sentry.server.config.js}
29+
import * as Sentry from "@sentry/astro";
30+
31+
Sentry.init({
32+
dsn: "___PUBLIC_DSN___",
33+
tracesSampleRate: 1.0,
34+
});
35+
```
36+
37+
<Alert level="warning">
38+
39+
The `tracesSampler` callback can only be specified in <PlatformLink to="/manual-setup/#manual-sdk-initialization">custom SDK init files</PlatformLink>.
40+
It is **not supported** in the `astro.config.mjs` file.
41+
42+
</Alert>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
To enable tracing, set either a `tracesSampleRate` or a `tracesSampler` in your SDK configuration options, as described in <PlatformLink to="/performance/">Set Up Performance</PlatformLink>.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The Sentry Astro SDK comes with performance monitoring included. To enable it, configure the sample rate as described below.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The Replay integration is already included with the Sentry Astro SDK.
2+
3+
```bash {tabTitle:npx}
4+
npx astro add @sentry/astro
5+
```
6+
7+
<Note>
8+
9+
If the Astro CLI setup doesn't work for you, you can also <PlatformLink to="/manual-setup/">set up the SDK manually</PlatformLink>.
10+
11+
</Note>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Session replay is enabled by default if you use the SDK configuration in your `astro.config.mjs` file.
2+
3+
You can customize Replay sample rates like so:
4+
5+
```javascript {filename:astro.config.mjs}
6+
import { defineConfig } from "astro/config";
7+
import sentry from "@sentry/astro";
8+
9+
export default defineConfig({
10+
integrations: [
11+
sentry({
12+
dsn: "___PUBLIC_DSN___",
13+
replaysSessionSampleRate: 0.2, // defaults to 0.1
14+
replaysOnErrorSampleRate: 1.0, // defaults to 1.0
15+
}),
16+
],
17+
});
18+
```
19+
20+
If you have a <PlatformLink to="/manual-setup/#manual-sdk-initialization">custom SDK configuration file</PlatformLink> for the client side (`sentry.client.config.js`), add the Sentry `Replay` integration:
21+
22+
```javascript {filename:sentry.client.config.js}
23+
import * as sentry from "@sentry/astro";
24+
25+
Sentry.init({
26+
dsn: "___PUBLIC_DSN___",
27+
replaysSessionSampleRate: 0.1,
28+
replaysOnErrorSampleRate: 1.0,
29+
integrations: [new Sentry.Replay()],
30+
});
31+
```
32+
33+
<Alert level="warning">
34+
35+
Do not add the `Replay` integration to your server-side Sentry config file (`sentry.server.config.js`).
36+
Session Replay can only be included on the client side.
37+
38+
</Alert>
39+
40+
### Lazy-loading Replay
41+
42+
Once you've added the integration, Replay will start automatically. If you don't want to start it immediately (lazy-load it), you can use `addIntegration`:
43+
44+
```javascript
45+
Sentry.init({
46+
// Note, Replay is NOT instantiated below:
47+
integrations: [],
48+
});
49+
50+
// Sometime later
51+
const { Replay } = await import("@sentry/astro");
52+
Sentry.addIntegration(new Replay());
53+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Configure Source Maps Upload
2+
3+
Source maps upload should work if you followed the [Astro CLI installation guide](/platforms/javascript/guides/astro/#add-readable-stack-traces-to-errors). However, there are some options to configure source maps upload for your production builds for other configurations.
4+
5+
### Enable Source Maps Upload
6+
7+
To automatically upload source maps during production builds, add the `SENTRY_AUTH_TOKEN` environment variable to your environment, for example in a `.env` file or in your CI setup.
8+
9+
<OrgAuthTokenNote />
10+
11+
```bash {filename:.env}
12+
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
13+
```
14+
15+
Next, add your project slug to the `sourceMapsUploadOptions` in your Astro config:
16+
17+
```javascript {filename:astro.config.mjs}
18+
export default defineConfig({
19+
integrations: [
20+
sentryAstro({
21+
// Other Sentry options
22+
sourceMapsUploadOptions: {
23+
project: "___PROJECT_SLUG___",
24+
authToken: process.env.SENTRY_AUTH_TOKEN,
25+
},
26+
}),
27+
],
28+
});
29+
```
30+
31+
### Working With Old Authentication Tokens
32+
33+
Source maps work best with [organization-scoped auth tokens](/product/accounts/auth-tokens/#organization-auth-tokens). If you are using an old self-hosted Sentry version that doesn't yet support org-based tokens or you're using a different type of Sentry auth token, you'll need to additionally specify your `org` slug in your `sourceMapsUploadOptions`:
34+
35+
```javascript {filename:astro.config.mjs}
36+
export default defineConfig({
37+
integrations: [
38+
sentryAstro({
39+
// Other Sentry options
40+
sourceMapsUploadOptions: {
41+
project: "___PROJECT_SLUG___",
42+
org: "___ORG_SLUG___",
43+
authToken: process.env.SENTRY_AUTH_TOKEN,
44+
},
45+
}),
46+
],
47+
});
48+
```
49+
50+
### Disable Source Maps Upload
51+
52+
You can disable automatic source maps upload in your Astro config:
53+
54+
```javascript {filename:astro.config.mjs}
55+
export default defineConfig({
56+
integrations: [
57+
sentryAstro({
58+
// Other Sentry options
59+
sourceMapsUploadOptions: {
60+
enabled: false,
61+
},
62+
}),
63+
],
64+
});
65+
```
66+
67+
### Disabeling Telemetry Data Collection
68+
69+
The Astro SDK uses the Sentry Vite plugin to upload source maps.
70+
This plugin collects telemetry data to help us improve the source map uploading experience.
71+
Read more about this in our [Vite plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin#telemetry).
72+
You can disable telemetry collection by setting `telemetry` to `false`:
73+
74+
```javascript {filename:astro.config.mjs}
75+
export default defineConfig({
76+
integrations: [
77+
sentryAstro({
78+
// Other Sentry options
79+
sourceMapsUploadOptions: {
80+
telemetry: false,
81+
},
82+
}),
83+
],
84+
});
85+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The Sentry Astro SDK will generate and upload source maps automatically during a production build, so that errors in Sentry contain readable stack traces.
2+
3+
![Readable Stack Traces](/readable-stacktraces.png)
4+
5+
The Astro SDK uses the [Sentry Vite Plugin](https://www.npmjs.com/package/@sentry/vite-plugin/) to upload source maps. See the <PlatformLink to="/manual-setup/#configure-source-maps-upload">Manual Configuration</PlatformLink> page and the Sentry [Vite plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin/#configuration) for more details.

src/platforms/common/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Sentry captures data by using an SDK within your application’s runtime.
2222

2323
## Configure
2424

25-
<PlatformSection notSupported={["android", "unity", "unreal", "javascript.nextjs", "apple.ios"]}>
25+
<PlatformSection notSupported={["android", "unity", "unreal", "javascript.nextjs", "javascript.astro", "apple.ios"]}>
2626

2727
Configuration should happen as early as possible in your application's lifecycle.
2828

src/platforms/javascript/common/install/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sidebar_order: 1
44
description: "Review our alternate installation methods."
55
notSupported:
66
- javascript.angular
7+
- javascript.astro
78
- javascript.bun
89
- javascript.capacitor
910
- javascript.cordova

src/platforms/javascript/common/sourcemaps/uploading/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ notSupported:
66
- javascript.nextjs
77
- javascript.remix
88
- javascript.sveltekit
9+
- javascript.astro
910
---
1011

1112
<PlatformContent includePath="sourcemaps/upload/primer" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: Astro
2+
sdk: sentry.javascript.astro
3+
fallbackPlatform: javascript
4+
caseStyle: camelCase
5+
supportLevel: production
6+
categories:
7+
- browser
8+
- server

0 commit comments

Comments
 (0)