-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nuxt): Add _experimental.useDiagnosticsChannelInjection
#22323
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.
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
Changes from all commits
1963320
626d374
35b0785
b9749a1
6112c70
854a06e
92c57d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { readFileSync, readdirSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| function readServerBundle(): string { | ||
| const serverDir = path.join(process.cwd(), '.output/server'); | ||
| return readdirSync(serverDir, { recursive: true }) | ||
| .filter(file => typeof file === 'string' && file.endsWith('.mjs')) | ||
| .map(file => readFileSync(path.join(serverDir, file), 'utf8')) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| function readClientBundle(): string { | ||
| const serverDir = path.join(process.cwd(), '.output/public'); | ||
| return readdirSync(serverDir, { recursive: true }) | ||
| .filter(file => typeof file === 'string' && file.endsWith('.js')) | ||
| .map(file => readFileSync(path.join(serverDir, file), 'utf8')) | ||
| .join('\n'); | ||
| } | ||
|
|
||
| test.describe('Orchestrion build-time injection', () => { | ||
| const serverBundle = readServerBundle(); | ||
| const clientBundle = readClientBundle(); | ||
|
|
||
| test('force-bundles instrumented dependencies', () => { | ||
| expect(serverBundle).not.toMatch(/(from\s*["']mysql["']|require\(["']mysql["']\))/); | ||
| expect(serverBundle).not.toMatch(/(from\s*["']ioredis["']|require\(["']ioredis["']\))/); | ||
| expect(serverBundle).not.toMatch(/(from\s*["']standard-as-callback["']|require\(["']standard-as-callback["']\))/); | ||
| }); | ||
|
|
||
| test('injects diagnostics-channel publishers into the server build', () => { | ||
| expect(serverBundle).toContain('__SENTRY_ORCHESTRION__'); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:mysql:query["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:ioredis:command["']\)/); | ||
| expect(serverBundle).toMatch(/tracingChannel\(["']orchestrion:ioredis:connect["']\)/); | ||
| }); | ||
|
|
||
| test('does not inject diagnostics-channel publishers into the client build', () => { | ||
| expect(clientBundle).not.toContain('__SENTRY_ORCHESTRION__'); | ||
| expect(clientBundle).not.toMatch(/orchestrion:/); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,6 +183,24 @@ export type SentryNuxtModuleOptions = BuildTimeOptionsBase & { | |
| */ | ||
| enabled?: boolean; | ||
|
|
||
| // todo(v11): Update this JSDoc (and remove from experimental) | ||
| /** | ||
| * Experimental build-time options that may change or be removed without notice. | ||
| */ | ||
| _experimental?: { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: this will go away again in v11?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| /** | ||
| * Enables build-time diagnostics-channel instrumentation for supported dependencies bundled into the Nitro server. | ||
| * | ||
| * 1. Call `Sentry.experimentalUseDiagnosticsChannelInjection()` just before `Sentry.init()` | ||
| * 2. Remove `--import ./.output/server/sentry.server.config.mjs` from your `start`script | ||
| * 3. Add `sentry.autoInjectServerSentry: 'top-level-import'` in `nuxt.config.ts` so Sentry's server configuration is automatically imported | ||
| * | ||
| * @default false | ||
| * @experimental May change or be removed in any release. | ||
| */ | ||
| useDiagnosticsChannelInjection?: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Options for the Sentry Vite plugin to customize the source maps upload process. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { Nuxt } from '@nuxt/schema'; | ||
| import { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config'; | ||
| import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup'; | ||
| import type { NitroConfig } from 'nitropack'; | ||
|
|
||
| // ioredis requires this CommonJS helper to be bundled with it. Leaving it | ||
| // external makes Nitro resolve the default export as a namespace object. | ||
| const IORedisDependencies = ['standard-as-callback']; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: This will likely fail for all nitro based frameworks I guess? Maybe we can move this to server utils at some point so we can make this reusable if we run into more of these things. |
||
|
|
||
| /** | ||
| * Configures Nitro to bundle and transform dependencies that publish tracing | ||
| * events through diagnostics channels. | ||
| */ | ||
| export function setupOrchestrion(nuxt: Nuxt): void { | ||
| nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => { | ||
| if (nuxt.options?._prepare) { | ||
| return; | ||
| } | ||
|
|
||
| nitroConfig.rollupConfig ??= {}; | ||
|
|
||
| if (nitroConfig.rollupConfig.plugins === null || nitroConfig.rollupConfig.plugins === undefined) { | ||
| nitroConfig.rollupConfig.plugins = []; | ||
| } else if (!Array.isArray(nitroConfig.rollupConfig.plugins)) { | ||
| nitroConfig.rollupConfig.plugins = [nitroConfig.rollupConfig.plugins]; | ||
| } | ||
|
|
||
| nitroConfig.rollupConfig.plugins.push(sentryOrchestrionPlugin()); | ||
|
|
||
| const externals = (nitroConfig.externals ||= {}); | ||
| const inline = externals.inline; | ||
| const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : []; | ||
| externals.inline = [...new Set([...existingInline, ...INSTRUMENTED_MODULE_NAMES, ...IORedisDependencies])]; | ||
| }); | ||
| } | ||
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.
q: Is the plan to make this the default then?
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.
Yes 👍