GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(nuxt): Set up Cloudflare from `sentry.cloudflare.config.ts` by JPeer264 · Pull Request #26754 · getsentry/sentry-javascript

feat(nuxt): Set up Cloudflare from sentry.cloudflare.config.ts #26754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
JPeer264 merged 10 commits into develop from jp/nuxt-cloudflare-instrument-server
Nov 25, 2026
+1,191 −67
Merged

feat(nuxt): Set up Cloudflare from sentry.cloudflare.config.ts #26754

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
10 commits
Select commit Hold shift + click to select a range
90e71de
feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 17, 2026
35a94ff
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 23, 2026
7388fe7
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 23, 2026
0c8be18
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 23, 2026
40735ad
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 23, 2026
f759eba
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 24, 2026
f51b356
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 24, 2026
f505a78
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 24, 2026
e72d045
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 24, 2026
74d0341
fixup! feat(nuxt): Set up Cloudflare from `instrument.server.ts`
JPeer264 Nov 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

15 changes: 10 additions & 5 deletions 15 packages/nuxt/src/common/buildAssets.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ type GlobalWithNuxtPaths = {
* Returns `app.buildAssetsDir` with a leading and a trailing slash.
* Returns `undefined` for `/`, because there build output and routes share one path.
*/
export function getNuxtBuildAssetsDir(): string | undefined {
const dir = joinPath((GLOBAL_OBJ as GlobalWithNuxtPaths)[NUXT_BUILD_ASSETS_DIR_GLOBAL] ?? DEFAULT_BUILD_ASSETS_DIR);
export function getNuxtBuildAssetsDir(
buildAssetsDir = (GLOBAL_OBJ as GlobalWithNuxtPaths)[NUXT_BUILD_ASSETS_DIR_GLOBAL] ?? DEFAULT_BUILD_ASSETS_DIR,
): string | undefined {
const dir = joinPath(buildAssetsDir);
return dir === '/' ? undefined : dir;
}

/** Returns `app.baseURL` + `app.buildAssetsDir`, the path prefix of build output requests to the server. */
export function getNuxtBuildAssetsPath(): string | undefined {
const dir = getNuxtBuildAssetsDir();
return dir && joinPath((GLOBAL_OBJ as GlobalWithNuxtPaths)[NUXT_BASE_PATH_GLOBAL] ?? '', dir);
export function getNuxtBuildAssetsPath(
baseURL = (GLOBAL_OBJ as GlobalWithNuxtPaths)[NUXT_BASE_PATH_GLOBAL] ?? '',
buildAssetsDir?: string,
): string | undefined {
const dir = getNuxtBuildAssetsDir(buildAssetsDir);
return dir && joinPath(baseURL, dir);
}

/** Returns `app.cdnURL` (or `app.baseURL`) + `app.buildAssetsDir`, the URL prefix the browser loads build output from. */
Expand Down
30 changes: 20 additions & 10 deletions 30 packages/nuxt/src/module.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import * as path from 'path';
import { NUXT_BUILD_ASSETS_DIR_GLOBAL, NUXT_CDN_URL_GLOBAL } from './common/buildAssets';
import { NUXT_BASE_PATH_GLOBAL } from './common/tunnel';
import type { SentryNuxtModuleOptions } from './common/types';
import { setupCloudflareEntry } from './vite/cloudflare';
import { addTunnelPlugin, setupNitroServer } from './vite/nitroServer';
import { setupOrchestrion } from './vite/orchestrion';
import { NUXT_RELEASE_RUNTIME_CONFIG_KEY, setupSourceMaps } from './vite/sourceMaps';
import { findDefaultSdkInitFile, resolveServerApi } from './vite/utils';
import { findCloudflareOptionsFile, findDefaultSdkInitFile, resolveServerApi } from './vite/utils';
import { setupViteServer } from './vite/viteServer';
import { stringifyForCodeInjection, warnOnConflictingSourceMapOptions } from '@sentry/core';

Expand Down Expand Up @@ -87,34 +88,39 @@ export default defineNuxtModule<ModuleOptions>({
}

const serverConfigFile = await findDefaultSdkInitFile('server', nuxt, moduleOptions);
const cloudflareOptionsFile = await findCloudflareOptionsFile(nuxt, moduleOptions);
const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);
const isMinNuxtV4 = nuxtMajor >= 4;

// Orchestrion runs on both the Node path (gated on a server config file) and the Cloudflare path
// (which has no server config file — the SDK is set up via `sentryCloudflareNitroPlugin`). The
// (which has no server config file, the SDK is set up via `withSentry` or `sentryCloudflareNitroPlugin`). The
// Cloudflare detection happens inside, keyed off the resolved Nitro preset.
setupOrchestrion(nuxt, !!serverConfigFile, moduleOptions.buildTimeInstrumentation);

if (serverConfigFile) {
if (serverApi === 'nuxt') {
if (cloudflareOptionsFile) {
setupCloudflareEntry(nuxt, cloudflareOptionsFile);
}

if (serverApi === 'nuxt') {
if (serverConfigFile) {
setupViteServer(nuxt, serverConfigFile, moduleOptions);
} else {
setupNitroServer(nuxt, serverApi, serverConfigFile, moduleOptions);
}
} else if (serverConfigFile || cloudflareOptionsFile) {
setupNitroServer(nuxt, serverApi, serverConfigFile, moduleOptions, !!cloudflareOptionsFile);
} else {
// The Cloudflare setup initializes the SDK from `sentryCloudflareNitroPlugin`, so it needs the tunnel too.
// `sentryCloudflareNitroPlugin` initializes the SDK without a config file, so it needs the tunnel too.
addTunnelPlugin(serverApi);
}

// Names the server spans of pages after their route, with the SDK set up from the server config or from
// `sentryCloudflareNitroPlugin`.
// Names the server spans of pages after their route, with the SDK set up from the server config, from
// `sentry.cloudflare.config.ts` or from `sentryCloudflareNitroPlugin`.
if (isMinNuxtV4) {
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });
} else {
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
}

if (clientConfigFile || serverConfigFile) {
if (clientConfigFile || serverConfigFile || cloudflareOptionsFile) {
// The bundler plugins do not get `sourcemaps.delete`.
warnOnConflictingSourceMapOptions(moduleOptions.sourcemaps);
setupSourceMaps(moduleOptions, nuxt, addVitePlugin, !!clientConfigFile, serverApi === 'nuxt');
Expand Down Expand Up @@ -169,6 +175,10 @@ export default defineNuxtModule<ModuleOptions>({
const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);
tsConfig.include.push(relativePath);
}
if (cloudflareOptionsFile) {
const relativePath = path.relative(nuxt.options.buildDir, cloudflareOptionsFile);
tsConfig.include.push(relativePath);
}
});
},
});
21 changes: 21 additions & 0 deletions 21 packages/nuxt/src/runtime/plugins/cloudflare-entry.server.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getIsolationScope, stripUrlQueryAndFragment } from '@sentry/core';
import type { H3Event } from 'h3';
import type { NitroAppPlugin } from 'nitropack';
import { markCloudflareEntryWrapped } from '../utils/cloudflare-entry';

type H3V2Event = { req: { method: string }; url: { pathname: string } };

export default (nitroApp => {
// This plugin runs before the plugins of the app, so a `sentryCloudflareNitroPlugin` there sees the flag.
markCloudflareEntryWrapped();
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


// `withSentry` sets no transaction name, so errors captured during the request would have none.
// This is the same best-effort name the Node SDK sets when a request starts.
nitroApp.hooks.hook('request', (event: H3Event) => {
Comment thread

@s1gr1d s1gr1d Nov 24, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this request hook for a v1 and v2 H3Event?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JPeer264 JPeer264 Nov 24, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yap, added

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
// h3 v1 (Nitro 2) has the method and the path on the event, h3 v2 (Nitro 3) on `event.req` and `event.url`.
const { req, url } = event as unknown as Partial<H3V2Event>;
const method = event.method ?? req?.method;
const path = event.path ?? url?.pathname;
getIsolationScope().setTransactionName(`${method} ${stripUrlQueryAndFragment(path)}`);
});
}) satisfies NitroAppPlugin;
1 change: 1 addition & 0 deletions 1 packages/nuxt/src/runtime/plugins/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// oxlint-disable-next-line typescript/no-deprecated -- supported until removal
export { sentryCloudflareNitroPlugin } from './sentry-cloudflare.server';
24 changes: 24 additions & 0 deletions 24 packages/nuxt/src/runtime/plugins/sentry-cloudflare.server.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { wrapRequestHandler } from '@sentry/cloudflare/request';
import {
_INTERNAL_captureOptionsSetByUser,
applySdkMetadata,
consoleSandbox,
debug,
getDefaultIsolationScope,
getIsolationScope,
Expand All @@ -17,6 +18,7 @@ import type { NitroApp, NitroAppPlugin } from 'nitropack';
import type { NuxtRenderHTMLContext } from 'nuxt/app';
import { sentryCaptureErrorHook } from '../hooks/captureErrorHook';
import { updateRouteBeforeResponse } from '../hooks/updateRouteBeforeResponse';
import { isCloudflareEntryWrapped } from '../utils/cloudflare-entry';
import { getCfProperties, getCloudflareProperties, hasCfProperty, isEventType } from '../utils/event-type-check';
import { addSentryPageMetaTags, recordRequestStart } from '../utils/pageMetaTags';

Expand Down Expand Up @@ -63,10 +65,32 @@ function getRequestHandlerOptions(cloudflareOptions: CloudflareOptions): Cloudfl
* debug: nitroApp.h3App.options.debug
* })));
* ```
*
* @deprecated Add a `sentry.cloudflare.config.ts` file with the Sentry setup to the root of the Nuxt app instead.
*
* ```ts
* // sentry.cloudflare.config.ts
* import { defineCloudflareOptions } from '@sentry/cloudflare';
*
* export default defineCloudflareOptions(env => ({
* dsn: env.SENTRY_DSN,
* }));
* ```
*/
// TODO(v12): Remove `sentryCloudflareNitroPlugin`.
export const sentryCloudflareNitroPlugin =
(optionsOrFn: CloudflareOptions | ((nitroApp: NitroApp) => CloudflareOptions)): NitroAppPlugin =>
(nitroApp: NitroApp): void => {
if (isCloudflareEntryWrapped()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
'[Sentry] `sentryCloudflareNitroPlugin` does nothing, because Sentry sets up the SDK from `sentry.cloudflare.config.ts`. Remove the plugin.',
);
});
return;
}

const traceDataMap = new WeakMap<object, ReturnType<typeof getTraceData>>();

// Nitro v3 (Nuxt 5) has no `localFetch`. It hands the Worker's own request to `fetch`, with `ctx` on it.
Expand Down
16 changes: 16 additions & 0 deletions 16 packages/nuxt/src/runtime/utils/buildAssetRequestFilters.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { URL_PATH } from '@sentry/conventions/attributes';
import { HTTP_SERVER } from '@sentry/conventions/op';
import type { Options } from '@sentry/core';
import { escapeStringForRegex } from '@sentry/core';

/**
* Returns the `ignoreSpans` entries for requests to `buildAssetsPath` (`app.baseURL` + `app.buildAssetsDir`), the
* build output that the static asset filters miss, such as `.map` and `.json` files. Matches `url.path`, because a
* span name has no path yet when `ignoreSpans` runs. A runtime `NUXT_APP_BASE_URL` disables this filter, because the
* path comes from build-time config.
*/
export function getBuildAssetRequestFilters(buildAssetsPath: string | undefined): NonNullable<Options['ignoreSpans']> {
return buildAssetsPath
? [{ op: HTTP_SERVER, attributes: { [URL_PATH]: new RegExp(`^${escapeStringForRegex(buildAssetsPath)}`) } }]
: [];
}
15 changes: 15 additions & 0 deletions 15 packages/nuxt/src/runtime/utils/cloudflare-entry.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GLOBAL_OBJ } from '@sentry/core';

const CLOUDFLARE_ENTRY_WRAPPED_FLAG = '__SENTRY_NUXT_CLOUDFLARE_ENTRY_WRAPPED__';

type GlobalWithCloudflareEntryFlag = typeof GLOBAL_OBJ & { [CLOUDFLARE_ENTRY_WRAPPED_FLAG]?: boolean };

/** Records that the Sentry Nuxt module wrapped the Worker entry with `withSentry`. */
export function markCloudflareEntryWrapped(): void {
(GLOBAL_OBJ as GlobalWithCloudflareEntryFlag)[CLOUDFLARE_ENTRY_WRAPPED_FLAG] = true;
}

/** Whether the Sentry Nuxt module wrapped the Worker entry with `withSentry`. */
export function isCloudflareEntryWrapped(): boolean {
return (GLOBAL_OBJ as GlobalWithCloudflareEntryFlag)[CLOUDFLARE_ENTRY_WRAPPED_FLAG] === true;
}
7 changes: 7 additions & 0 deletions 7 packages/nuxt/src/runtime/utils/cloudflareWorkers.d.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// `@cloudflare/workers-types` declares this module, but pulling it in would also add Workers globals
// that clash with the DOM lib the client half of this package is checked against. Only the export
// the SDK reads is declared here; the declaration is build-time only and never emitted.
declare module 'cloudflare:workers' {
// workerd versions from before March 2025 have no `withEnv`.
export const withEnv: (<T>(env: unknown, callback: () => T) => T) | undefined;
}
87 changes: 87 additions & 0 deletions 87 packages/nuxt/src/runtime/utils/wrapCloudflareEntry.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import type { DurableObjectState, ExecutionContext, ExportedHandler } from '@cloudflare/workers-types';
import type { CloudflareOptions } from '@sentry/cloudflare';
import { instrumentDurableObjectWithSentry, withSentry } from '@sentry/cloudflare';
import { _INTERNAL_captureOptionsSetByUser, applySdkMetadata } from '@sentry/core';
// A namespace import keeps a missing `withEnv` export a missing property instead of a module linking error.
import * as cloudflareWorkers from 'cloudflare:workers';
import { getBuildAssetRequestFilters } from './buildAssetRequestFilters';

type OptionsCallback = (env: unknown) => CloudflareOptions;
type NitroDurableObjectClass = new (state: DurableObjectState, env: unknown) => object;
type Method = (this: unknown, ...args: unknown[]) => unknown;

/**
* Wraps the default export of the Nitro Worker entry with `withSentry`. Each handler runs with the `env` that
* `withSentry` instruments as the `env` of `cloudflare:workers`, so db0 of Nitro 3 reads instrumented D1 bindings.
* `buildAssetsPath` is `app.baseURL` + `app.buildAssetsDir`, the path of the build output that the SDK ignores.
*/
export function wrapNitroCloudflareEntryWithSentry<Handler extends ExportedHandler>(
optionsCallback: OptionsCallback,
handler: Handler,
buildAssetsPath?: string,
): Handler {
const handlerWithEnv = Object.fromEntries(
Object.entries(handler).map(([name, value]) => [
name,
typeof value === 'function'
? (event: unknown, env: unknown, context: ExecutionContext): unknown =>
runWithEnv(env, () => (value as Method).call(handler, event, env, context))
: value,
]),
) as Handler;

const optionsCallbackWithMetadata = withNuxtSdkMetadata(optionsCallback);
// Nitro sends a request for a build file that the Cloudflare assets do not have to `env.ASSETS` before the Nitro app
// runs, but `withSentry` sees the request.
return withSentry(env => {
const options = optionsCallbackWithMetadata(env);
return {
...options,
ignoreSpans: [...(options.ignoreSpans || []), ...getBuildAssetRequestFilters(buildAssetsPath)],
};
Comment thread
Comment on lines +37 to +41

@s1gr1d s1gr1d Nov 24, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sdk setup uses _INTERNAL_captureOptionsSetByUser, should we maybe also check that here? so it captures the user options first

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JPeer264 JPeer264 Nov 25, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smart move, added.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}, handlerWithEnv);
}

/**
* Wraps the Durable Object class of the Nitro Worker entry with `instrumentDurableObjectWithSentry`. Each method runs
* with the instrumented `this.env` as the `env` of `cloudflare:workers`.
*/
export function wrapNitroDurableObjectWithSentry(
optionsCallback: OptionsCallback,
NitroDurableObject: NitroDurableObjectClass,
): NitroDurableObjectClass {
class NitroDurableObjectWithEnv extends NitroDurableObject {}

for (const name of Object.getOwnPropertyNames(NitroDurableObject.prototype)) {
const method: unknown = Object.getOwnPropertyDescriptor(NitroDurableObject.prototype, name)?.value;
if (name === 'constructor' || typeof method !== 'function') {
continue;
}

// Frameworks can read the name of a method, so the wrapper keeps it.
const { [name]: methodWithEnv } = {
[name](this: { env?: unknown }, ...args: unknown[]): unknown {
return runWithEnv(this.env, () => (method as Method).apply(this, args));
},
};
Object.defineProperty(NitroDurableObjectWithEnv.prototype, name, {
value: methodWithEnv,
writable: true,
configurable: true,
});
}

return instrumentDurableObjectWithSentry(withNuxtSdkMetadata(optionsCallback), NitroDurableObjectWithEnv);
}

function runWithEnv(env: unknown, callback: () => unknown): unknown {
return cloudflareWorkers.withEnv && env !== undefined ? cloudflareWorkers.withEnv(env, callback) : callback();
}

function withNuxtSdkMetadata(optionsCallback: OptionsCallback): OptionsCallback {
return env => {
const options = _INTERNAL_captureOptionsSetByUser({ ...optionsCallback(env) });
applySdkMetadata(options, 'nuxt', ['nuxt', 'cloudflare']);
return options;
};
}
19 changes: 6 additions & 13 deletions 19 packages/nuxt/src/server/sdk.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
markNuxtServerInitialized,
} from '../common/devMode';
import type { SentryNuxtServerOptions } from '../common/types';
import { getBuildAssetRequestFilters } from '../runtime/utils/buildAssetRequestFilters';

/**
* Initializes the server-side of the Nuxt SDK
Expand Down Expand Up @@ -62,7 +63,11 @@ export function init(options: SentryNuxtServerOptions): Client | undefined {
const sentryOptions = {
environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,
..._INTERNAL_captureOptionsSetByUser(options),
ignoreSpans: [...(options.ignoreSpans || []), ...getBuildAssetRequestFilters(), ...getPublicFileRequestFilters()],
ignoreSpans: [
...(options.ignoreSpans || []),
...getBuildAssetRequestFilters(getNuxtBuildAssetsPath()),
...getPublicFileRequestFilters(),
],
};

applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);
Expand All @@ -80,18 +85,6 @@ export function init(options: SentryNuxtServerOptions): Client | undefined {
return client;
}

/**
* Ignores build output that the HTTP integration's static asset filter misses, such as `.map` and `.json` files.
* Matches `url.path`, because a span name has no path yet when `ignoreSpans` runs. A runtime `NUXT_APP_BASE_URL`
* disables this filter, because the path comes from build-time config.
*/
function getBuildAssetRequestFilters(): NonNullable<SentryNuxtServerOptions['ignoreSpans']> {
const buildAssetsPath = getNuxtBuildAssetsPath();
return buildAssetsPath
? [{ op: HTTP_SERVER, attributes: { [URL_PATH]: new RegExp(`^${escapeStringForRegex(buildAssetsPath)}`) } }]
: [];
}

/**
* Ignores files from `public/` that the HTTP integration's static asset filter misses, such as `.pdf` and `.txt` files.
* Matches exact paths, because a route can share a prefix with a public dir.
Expand Down
18 changes: 15 additions & 3 deletions 18 packages/nuxt/src/vite/addServerConfig.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,17 @@ export function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro
/**
* Registers a Nitro plugin that statically imports the Sentry server config, so the SDK initializes
* at server startup without a `node --import` preload.
*
* On a Cloudflare preset, it removes the plugin again. It warns then only when the app has no
* `sentry.cloudflare.config` file (`hasCloudflareOptionsFile`), because an app with both files can build for Node and
* for Cloudflare.
*/
export function addServerConfigPlugin(nuxt: Nuxt, serverConfigFile: string, isLegacyNitro: boolean): void {
export function addServerConfigPlugin(
nuxt: Nuxt,
serverConfigFile: string,
isLegacyNitro: boolean,
hasCloudflareOptionsFile: boolean,
): void {
const configPath = createResolver(nuxt.options.rootDir).resolve(serverConfigFile);
let publicFilePaths: string[] = [];
// Nitro starts before Nuxt generates the templates.
Expand Down Expand Up @@ -162,18 +171,21 @@ export function addServerConfigPlugin(nuxt: Nuxt, serverConfigFile: string, isLe
}
});

// On Cloudflare the SDK is set up through `sentryCloudflareNitroPlugin`; the Node SDK config
// On Cloudflare `withSentry` sets up the SDK with the options of `sentry.cloudflare.config.ts`; the Node SDK config
// must not end up in the worker bundle. `nitro.options.preset` is resolved here.
nuxt.hook('nitro:init', nitro => {
if (nuxt.options._prepare || !isCloudflarePreset(nitro.options.preset)) {
return;
}

nitro.options.plugins = (nitro.options.plugins ?? []).filter(plugin => plugin !== configPluginTemplate.dst);
if (hasCloudflareOptionsFile) {
return;
}
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
`[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK with \`sentryCloudflareNitroPlugin\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`,
`[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK in \`sentry.cloudflare.config.ts\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`,
);
});
});
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.