Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/server-runtime-injection/src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,15 @@ export function registerDiagnosticsChannelInjection(): void {
} catch (error) {
marker.runtimeUnavailable = true;
const reason = error instanceof Error ? error.message : String(error);
// Build tracers decide which of this package's files a deployment ships, and they miss the ones
// only reached through `Module.register()`. Say so, because the bare message reads like an SDK bug.
const missingFile = (error as { code?: unknown } | null)?.code === 'ERR_MODULE_NOT_FOUND';
warnRuntimeUnavailable(
`Failed to register diagnostics-channel injection hooks (${reason}), so channel-based integrations will not record spans.`,
missingFile
? 'Channel-based integrations will not record spans: your deployment is missing a file from ' +
`\`@sentry/server-runtime-injection\` (${reason}). Your build's file tracing left it out. Deploy the ` +
'whole `@sentry/server-runtime-injection` package directory with your server.'
: `Failed to register diagnostics-channel injection hooks (${reason}), so channel-based integrations will not record spans.`,
);
debug.warn('Diagnostics-channel injection registration error:', error);
return;
Expand Down
20 changes: 20 additions & 0 deletions packages/server-runtime-injection/test/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ describe('registerDiagnosticsChannelInjection - bundled/tree-shaken detection',
expect(GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.runtimeUnavailable).toBe(true);
});

it('says the deployment is missing a file when registering fails with ERR_MODULE_NOT_FOUND', () => {
(globalThis as { Deno?: unknown }).Deno = { version: { deno: '2.8.3' } };
registerHooksMock.mockImplementationOnce(() => {
throw Object.assign(new Error("Cannot find module '/var/task/hook.js'"), { code: 'ERR_MODULE_NOT_FOUND' });
});

try {
registerDiagnosticsChannelInjection();
} finally {
delete (globalThis as { Deno?: unknown }).Deno;
}

expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining(
"your deployment is missing a file from `@sentry/server-runtime-injection` (Cannot find module '/var/task/hook.js')",
),
);
expect(GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.runtimeUnavailable).toBe(true);
});

it('warns once when a module fails to transform because the transformer was tree-shaken', () => {
registerDiagnosticsChannelInjection();
const onDiagnostics = diagnosticsCallback();
Expand Down
Loading