Skip to content

Commit 5cc62e8

Browse files
AbhiPrasadcursoragentcoolguyzone
authored
Create wrangler sourcemaps guide for Cloudflare (#14089)
Documents the changes from getsentry/sentry-wizard#999 ref getsentry/sentry-javascript#14841 A new sourcemaps guide for Wrangler was added to the Cloudflare documentation. * A new guide, `docs/platforms/javascript/common/sourcemaps/uploading/wrangler.mdx`, was created. * It details both automatic setup via the Sentry Wizard and manual configuration. * Manual steps include installing `@sentry/cli`, configuring `sentry-cli`, and modifying the `package.json` scripts. * The `deploy` script is updated to include `--outdir`, `--upload-source-maps`, and `--var SENTRY_RELEASE:$(sentry-cli releases propose-version)`. * A `sentry:sourcemaps` script is added to create releases and upload sourcemaps. * A `postdeploy` script is introduced to automatically run the `sentry:sourcemaps` command after deployment. * Instructions for configuring the Sentry SDK with `release: env.SENTRY_RELEASE` are provided. * The guide is marked as `supported: [javascript.cloudflare]` to ensure platform-specific visibility. * `platform-includes/sourcemaps/overview/javascript.cloudflare.mdx` was updated to include a "Cloudflare-Specific Tools" section, linking to the new Wrangler guide. * `platform-includes/sourcemaps/upload/primer/javascript.cloudflare.mdx` was modified to include the updated Cloudflare overview. These changes ensure that Wrangler users have a dedicated guide for sourcemap uploads, integrated seamlessly into the Cloudflare platform documentation. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Alex Krawiec <alex.krawiec@sentry.io>
1 parent e639797 commit 5cc62e8

File tree

3 files changed

+221
-0
lines changed

3 files changed

+221
-0
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Wrangler
3+
description: "Upload your Cloudflare Workers source maps using Wrangler and Sentry CLI."
4+
sidebar_order: 10
5+
supported:
6+
- javascript.cloudflare
7+
---
8+
9+
10+
<Include name="debug-id-requirement.mdx" />
11+
12+
<Alert level="info">
13+
14+
This guide is specifically for Cloudflare Workers using Wrangler. For other build tools like Vite with Cloudflare, use the corresponding Vite guide instead.
15+
16+
We recommend using Vite to build your worker for an easier and more reliable setup. Learn more about [Cloudflare's Vite setup](https://developers.cloudflare.com/workers/vite-plugin/get-started/).
17+
18+
</Alert>
19+
20+
## Automatic Setup
21+
22+
The easiest way to configure source map uploading with Wrangler is by using the Sentry Wizard:
23+
24+
<Include name="sourcemaps-wizard-instructions.mdx" />
25+
26+
If you'd rather configure source maps manually, follow the steps below.
27+
28+
## Manual Setup
29+
30+
### 1. Install Sentry CLI
31+
32+
First, install Sentry CLI as a dev dependency:
33+
34+
```bash {tabTitle:npm}
35+
npm install --save-dev @sentry/cli
36+
```
37+
38+
```bash {tabTitle:yarn}
39+
yarn add --dev @sentry/cli
40+
```
41+
42+
```bash {tabTitle:pnpm}
43+
pnpm add --save-dev @sentry/cli
44+
```
45+
46+
### 2. Configure Sentry CLI
47+
48+
For more info on `sentry-cli` configuration visit the [Sentry CLI configuration docs](/cli/configuration/).
49+
50+
Make sure `sentry-cli` is configured for your project. For that you can use environment variables:
51+
52+
```bash {filename:.env.local}
53+
SENTRY_ORG=example-org
54+
SENTRY_PROJECT=example-project
55+
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
56+
```
57+
58+
### 3. Modify Your Deploy Script
59+
60+
Update your Wrangler deploy script in `package.json` to include the necessary flags for source map generation and upload:
61+
62+
```json {filename:package.json}
63+
{
64+
"scripts": {
65+
"deploy": "wrangler deploy --outdir dist --upload-source-maps --var SENTRY_RELEASE:$(sentry-cli releases propose-version)"
66+
}
67+
}
68+
```
69+
70+
The key flags are:
71+
72+
- `--outdir dist`: Specifies the output directory where source maps will be generated
73+
- `--upload-source-maps`: Forces Wrangler to generate source maps
74+
- `--var SENTRY_RELEASE:$(sentry-cli releases propose-version)`: Injects the release version as an environment variable
75+
76+
### 4. Create a Source Map Upload Script
77+
78+
Add a script to upload source maps to Sentry in your `package.json`:
79+
80+
```json {filename:package.json}
81+
{
82+
"scripts": {
83+
"sentry:sourcemaps": "_SENTRY_RELEASE=$(sentry-cli releases propose-version) && sentry-cli releases new $_SENTRY_RELEASE --org=your-org --project=your-project && sentry-cli sourcemaps upload --org=your-org --project=your-project --release=$_SENTRY_RELEASE --strip-prefix 'dist/..' dist"
84+
}
85+
}
86+
```
87+
88+
Replace `your-org` and `your-project` with your actual Sentry organization and project slugs.
89+
90+
### 5. Add a Post-Deploy Hook
91+
92+
Create a post-deploy script that automatically uploads source maps after deployment:
93+
94+
```json {filename:package.json}
95+
{
96+
"scripts": {
97+
"deploy": "wrangler deploy --outdir dist --upload-source-maps --var SENTRY_RELEASE:$(sentry-cli releases propose-version)",
98+
"postdeploy": "npm run sentry:sourcemaps"
99+
}
100+
}
101+
```
102+
103+
This ensures that source maps are uploaded to Sentry immediately after a successful deployment.
104+
105+
### 6. Configure Your Sentry SDK
106+
107+
Make sure your Sentry SDK configuration includes the release information:
108+
109+
```typescript {filename:index.ts}
110+
import * as Sentry from "@sentry/cloudflare";
111+
112+
export default Sentry.withSentry(
113+
(env: Env) => ({
114+
dsn: "YOUR_DSN_HERE",
115+
// The release name should match what's used during source map upload
116+
release: env.SENTRY_RELEASE,
117+
// other options...
118+
}),
119+
{
120+
async fetch(request, env, ctx) {
121+
// Your worker logic here
122+
return new Response("Hello World!");
123+
},
124+
} satisfies ExportedHandler<Env>
125+
);
126+
```
127+
128+
### 7. Deploy Your Application
129+
130+
Run your deploy command:
131+
132+
```bash
133+
npm run deploy
134+
```
135+
136+
This will:
137+
138+
1. Build your worker with source maps enabled
139+
2. Deploy to Cloudflare with the release version injected
140+
3. Automatically upload source maps to Sentry via the post-deploy hook
141+
142+
### 8. Verify Source Maps Upload
143+
144+
You can verify that your source maps were uploaded successfully by:
145+
146+
1. Going to **Project Settings > Source Maps** in Sentry
147+
2. Checking for your release in the "Artifact Bundles" tab
148+
3. Confirming that source maps are working by triggering an error and checking that the stack trace shows your original source code
149+
150+
## Troubleshooting
151+
152+
### Source Maps Not Working
153+
154+
If your source maps aren't working as expected:
155+
156+
1. Verify that the `SENTRY_RELEASE` environment variable is being set correctly in your worker
157+
2. Check that the release name in your Sentry SDK configuration matches the one used during upload
158+
3. Ensure that source maps are being generated in the specified `--outdir`
159+
160+
### Build Errors
161+
162+
If you encounter build errors when adding source map flags:
163+
164+
1. Make sure you're using Wrangler `3.x` or above
165+
2. Verify that your project structure supports the `--outdir` flag
166+
3. Consider switching to Vite for a more robust build pipeline
167+
168+
## Additional Resources
169+
170+
- [Cloudflare Wrangler Documentation](https://developers.cloudflare.com/workers/wrangler/)
171+
- [Cloudflare Vite Plugin](https://developers.cloudflare.com/workers/vite-plugin/get-started/)
172+
- [Using sentry-cli to Upload Source Maps](/cli/releases/#sentry-cli-sourcemaps)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Uploading Source Maps
2+
3+
The easiest way to configure uploading source maps is by using the Sentry Wizard:
4+
5+
<Include name="sourcemaps-wizard-instructions.mdx" />
6+
7+
If you want to configure source maps to upload manually, follow the guide for your bundler or build tool below.
8+
9+
## Sentry Bundler Support
10+
11+
- <PlatformLink to="/sourcemaps/uploading/webpack/">webpack</PlatformLink>
12+
- <PlatformLink to="/sourcemaps/uploading/rollup/">Rollup</PlatformLink>
13+
- <PlatformLink to="/sourcemaps/uploading/vite/">Vite</PlatformLink>
14+
- <PlatformLink to="/sourcemaps/uploading/esbuild/">esbuild</PlatformLink>
15+
16+
### Cloudflare-Specific Tools
17+
18+
- <PlatformLink to="/sourcemaps/uploading/wrangler/">Wrangler</PlatformLink>
19+
20+
### Guides for Source Maps
21+
22+
- <PlatformLink to="/sourcemaps/uploading/typescript/">
23+
TypeScript (tsc)
24+
</PlatformLink>
25+
26+
<Alert>
27+
If you're using a bundler like Webpack, Vite, Rollup, or Esbuild, use the
28+
corresponding Sentry plugin instead. For details, see the "Sentry Bundler Support" section.
29+
</Alert>
30+
31+
- <PlatformLink to="/sourcemaps/uploading/uglifyjs/">UglifyJS</PlatformLink>
32+
- <PlatformLink to="/sourcemaps/uploading/systemjs/">SystemJS</PlatformLink>
33+
- [GitHub Actions](/product/releases/setup/release-automation/github-actions/)
34+
35+
## Other Tools
36+
37+
If you're not using one of these tools, we assume you already know how to generate source maps with your toolchain and we recommend you upload them using <PlatformLink to="/sourcemaps/uploading/cli/">Sentry CLI</PlatformLink>.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
We provide guides on uploading source maps to Sentry for the most popular JavaScript build tools and Cloudflare-specific tools.
2+
Pick one from the list below to learn more.
3+
4+
<Alert>
5+
6+
If you can't find the tool of your choice in the list below, we recommend you choose the "Sentry CLI" guide.
7+
8+
</Alert>
9+
10+
<Include name="sourcemaps/overview/javascript.cloudflare.mdx" />
11+
12+
<PageGrid />

0 commit comments

Comments
 (0)