Cloudflare Astro Framework Guide
Learn how to add Cloudflare instrumentation to your Astro app.
If you're running your Astro app on Cloudflare Pages, you can use the Sentry Astro SDK in combination with the Sentry Cloudflare SDK to add Sentry instrumentation.
First, install the Sentry Astro SDK in your application. We recommend setting up the Astro SDK manually and manually initializing the SDK. Make sure you have a sentry.client.config.js
file created, but do not add a sentry.server.config.js
file.
After installing the Sentry Astro SDK, you can now install the Sentry Cloudflare SDK. First, install the SDK with your package manager:
In order to get started using the Sentry JavaScript SDK, add the following code to the top of your application, before all other scripts:
<script
src="https://js.sentry-cdn.com/examplePublicKey.min.js"
crossorigin="anonymous"
></script>
The Loader Script allows you to configure some SDK features from the Sentry UI, without having to redeploy your application. The Loader Script documentation shows more information about how to use it.
Alternatively, you can also install the SDK via a package manager:
npm install @sentry/browser --save
We also support installation via CDN bundles.
If you're updating your Sentry SDK to the latest version, check out our migration guide to learn more about breaking changes.
If you are using our previous Browser JavaScript SDK, you can access the legacy SDK documentation, until further notice.
To use the SDK, you'll need to set either the nodejs_compat
or nodejs_als
compatibility flags in your wrangler.toml
. This is because the SDK needs access to the AsyncLocalStorage
API to work correctly.
wrangler.toml
compatibility_flags = ["nodejs_compat"]
# compatibility_flags = ["nodejs_als"]
Then create a functions
directory and add a _middleware.js
file to it with the following code:
functions/_middleware.js
import * as Sentry from "@sentry/cloudflare";
export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => ({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
})),
// Add more middlewares here
];
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").