Nuxt on Cloudflare

Learn how to add Cloudflare instrumentation to your Nuxt app.

If you're running your Nuxt app on Cloudflare Pages, you need to configure the SDK a little differently to the default setup. This guide will show you how to set up the Sentry Nuxt SDK with Nitro's cloudflare-pages deployment preset.

First, install the Sentry Nuxt SDK in your application. We recommend using the Sentry wizard to automatically install the SDK:

Copied
npx @sentry/wizard@latest -i nuxt

If the setup through the wizard doesn't work for you, you can also set up the Nuxt SDK manually.

Now you can install the Sentry Cloudflare SDK. First, install the SDK with your package manager:

Copied
npm install @sentry/cloudflare --save

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

To use the SDK, you'll need to set either the nodejs_compat or nodejs_als compatibility flags in your wrangler.jsonc / wrangler.toml config. This is because the SDK needs access to the AsyncLocalStorage API to work correctly.

wrangler.jsonc
Copied
{
  "compatibility_flags": [
    "nodejs_als",
    // "nodejs_compat"
  ],
}

You will also want to add the CF_VERSION_METADATA binding:

wrangler.jsonc
Copied
{
  // ...
  "version_metadata": {
    "binding": "CF_VERSION_METADATA"
  },
}

To enable Sentry for your Nuxt app on Cloudflare, follow these steps:

  1. Remove the previous server config file: Delete sentry.server.config.ts if it exists.

  2. Add a Nitro plugin: Create a new file in server/plugins (for example, server/plugins/sentry-cloudflare-setup.ts).

  3. Add the following code to your plugin file:

server/plugins/[custom-plugin-name].ts
Copied
import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'

export default defineNitroPlugin(sentryCloudflareNitroPlugin({
  dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
  tracesSampleRate: 1.0,
}))

Or, if you need access to nitroApp:

server/plugins/[custom-plugin-name].ts
Copied
import { sentryCloudflareNitroPlugin } from '@sentry/nuxt/module/plugins'

export default defineNitroPlugin(sentryCloudflareNitroPlugin((nitroApp: NitroApp) => {
  // You can access `nitroApp` here if needed
  return {
    dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
    tracesSampleRate: 1.0,
  }
}))
Was this helpful?
Help improve this content
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").