Wrangler
Upload your Cloudflare Workers source maps using Wrangler and Sentry CLI.
This guide assumes the following:
sentry-cli
version >=2.17.0
- Sentry JavaScript SDK version >=
7.47.0
This guide is specifically for Cloudflare Workers using Wrangler. For other build tools like Vite with Cloudflare, use the corresponding Vite guide instead.
We recommend using Vite to build your worker for an easier and more reliable setup. Learn more about Cloudflare's Vite setup.
The easiest way to configure source map uploading with Wrangler is by using the Sentry Wizard:
npx @sentry/wizard@latest -i sourcemaps
The wizard will guide you through the following steps:
- Logging into Sentry and selecting a project
- Installing the necessary Sentry packages
- Configuring your build tool to generate and upload source maps
- Configuring your CI to upload source maps
If you'd rather configure source maps manually, follow the steps below.
First, install Sentry CLI as a dev dependency:
npm install --save-dev @sentry/cli
For more info on sentry-cli
configuration visit the Sentry CLI configuration docs.
Make sure sentry-cli
is configured for your project. For that you can use environment variables:
.env.local
SENTRY_ORG=example-org
SENTRY_PROJECT=example-project
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
Update your Wrangler deploy script in package.json
to include the necessary flags for source map generation and upload:
package.json
{
"scripts": {
"deploy": "wrangler deploy --outdir dist --upload-source-maps --var SENTRY_RELEASE:$(sentry-cli releases propose-version)"
}
}
The key flags are:
--outdir dist
: Specifies the output directory where source maps will be generated--upload-source-maps
: Forces Wrangler to generate source maps--var SENTRY_RELEASE:$(sentry-cli releases propose-version)
: Injects the release version as an environment variable
Add a script to upload source maps to Sentry in your package.json
:
package.json
{
"scripts": {
"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"
}
}
Replace your-org
and your-project
with your actual Sentry organization and project slugs.
Create a post-deploy script that automatically uploads source maps after deployment:
package.json
{
"scripts": {
"deploy": "wrangler deploy --outdir dist --upload-source-maps --var SENTRY_RELEASE:$(sentry-cli releases propose-version)",
"postdeploy": "npm run sentry:sourcemaps"
}
}
This ensures that source maps are uploaded to Sentry immediately after a successful deployment.
Make sure your Sentry SDK configuration includes the release information:
index.ts
import * as Sentry from "@sentry/cloudflare";
export default Sentry.withSentry(
(env: Env) => ({
dsn: "YOUR_DSN_HERE",
// The release name should match what's used during source map upload
release: env.SENTRY_RELEASE,
// other options...
}),
{
async fetch(request, env, ctx) {
// Your worker logic here
return new Response("Hello World!");
},
} satisfies ExportedHandler<Env>,
);
Run your deploy command:
npm run deploy
This will:
- Build your worker with source maps enabled
- Deploy to Cloudflare with the release version injected
- Automatically upload source maps to Sentry via the post-deploy hook
You can verify that your source maps were uploaded successfully by:
- Going to Project Settings > Source Maps in Sentry
- Checking for your release in the "Artifact Bundles" tab
- Confirming that source maps are working by triggering an error and checking that the stack trace shows your original source code
If your source maps aren't working as expected:
- Verify that the
SENTRY_RELEASE
environment variable is being set correctly in your worker - Check that the release name in your Sentry SDK configuration matches the one used during upload
- Ensure that source maps are being generated in the specified
--outdir
If you encounter build errors when adding source map flags:
- Make sure you're using Wrangler
3.x
or above - Verify that your project structure supports the
--outdir
flag - Consider switching to Vite for a more robust build pipeline
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").