Sentry

Last updated Apr 21, 2026 Note

Sentry now provides official support for Cloudflare Workers and Pages. Refer to the Sentry documentation ↗︎ for more details.

The Sentry Pages Plugin captures and logs all exceptions which occur below it in the execution chain of your Pages Functions. It is therefore recommended that you install this Plugin at the root of your application in functions/_middleware.ts as the very first Plugin.

Installation

npmyarnpnpmbun

npm i @cloudflare/pages-plugin-sentry
yarn add @cloudflare/pages-plugin-sentry
pnpm add @cloudflare/pages-plugin-sentry
bun add @cloudflare/pages-plugin-sentry

Usage

import sentryPlugin from "@cloudflare/pages-plugin-sentry";

export const onRequest: PagesFunction = sentryPlugin({
    dsn: "https://sentry.io/welcome/xyz",
});

The Plugin uses Toucan ↗︎. Refer to the Toucan README to review the options it can take ↗︎. context, request, and event are automatically populated and should not be manually configured.

If your DSN ↗︎ is held as an environment variable or in KV, you can access it like so:

import sentryPlugin from "@cloudflare/pages-plugin-sentry";

export const onRequest: PagesFunction<{
    SENTRY_DSN: string;
}> = (context) => {
    return sentryPlugin({ dsn: context.env.SENTRY_DSN })(context);
};
import sentryPlugin from "@cloudflare/pages-plugin-sentry";

export const onRequest: PagesFunction<{
    KV: KVNamespace;
}> = async (context) => {
    return sentryPlugin({ dsn: await context.env.KV.get("SENTRY_DSN") })(context);
};

Additional context

If you need to set additional context for Sentry (for example, user information or additional logs), use the data.sentry instance in any Function below the Plugin in the execution chain.

For example, you can access data.sentry and set user information like so:

import type { PluginData } from "@cloudflare/pages-plugin-sentry";

export const onRequest: PagesFunction<unknown, any, PluginData> = async ({
    data,
    next,
}) => {
    // Authenticate the user from the request and extract user's email address
    const email = await getEmailFromRequest(request);

    data.sentry.setUser({ email });

    return next();
};

Again, the full list of features can be found in Toucan's documentation ↗︎.

Was this helpful?

YesNo

On this page

Sentry - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/pages/functions/plugins/sentry/#page","headline":"Sentry","description":"Capture and log exceptions in Pages Functions using the Sentry Pages Plugin.","url":"https://developers.cloudflare.com/pages/functions/plugins/sentry/","inLanguage":"en","image":"https://developers.cloudflare.com/pages/functions/plugins/sentry/og.png?v=7bc37c1c53e4871e","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Intercept and process HTML form submissions in Pages Functions with the Static Forms Plugin. title: Static Forms image: https://developers.cloudflare.com/pages/functions/plugins/static-forms/og.png?v=4109c1422e16c79d


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/pages/llms.txt
Use this file to discover all available pages before exploring further.