Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ module.exports = [
import: createImport('init'),
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '145 KB',
limit: '146 KB',
disablePlugins: ['@size-limit/esbuild'],
},
{
Expand Down Expand Up @@ -452,7 +452,7 @@ module.exports = [
path: 'packages/node/build/esm/index.js',
import: createImport('init'),
gzip: true,
limit: '123 KB',
limit: '125 KB',
disablePlugins: ['@size-limit/esbuild'],
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
modifyWebpackConfig: function (config) {
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export {
mongoIntegration,
mongooseIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
mysqlIntegration,
nativeNodeFetchIntegration,
NodeClient,
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export {
mongooseIntegration,
mysqlIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
redisIntegration,
tediousIntegration,
pinoIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export {
mongooseIntegration,
mysqlIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
redisIntegration,
tediousIntegration,
postgresIntegration,
Expand Down
12 changes: 7 additions & 5 deletions packages/cloudflare/src/baseSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import { defaultStackParser } from './vendor/stacktrace';
function getRegisteredChannelIntegrations(): Integration[] {
const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;

return registered ? [...registered.values()].map(factory => factory()) : [];
// A module holds a single factory, or a Set of them (once it registers more than one integration).
return registered
? [...registered.values()].flatMap(entry => (entry instanceof Set ? [...entry] : [entry])).map(factory => factory())
: [];
}

/**
Expand Down Expand Up @@ -148,10 +151,9 @@ export function initWithDefaultIntegrations(
// integration on the live client here. `addIntegration` dedupes by
// integration name, so already-installed integrations are no-ops.
client.on('orchestrion.module-injected', moduleName => {
const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);
if (factory) {
client.addIntegration(factory());
}
const entry = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);
const factories = entry instanceof Set ? entry : entry ? [entry] : [];
factories.forEach(factory => client.addIntegration(factory()));
});

return client;
Expand Down
33 changes: 33 additions & 0 deletions packages/cloudflare/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,37 @@ describe('getDefaultIntegrations', () => {

expect(client?.getIntegrationByName('Mysql')).toBeDefined();
});

test('installs all integrations for a module registered after init via the module-injected event', async () => {
const { mysqlIntegration, lruMemoizerIntegration } = await import('@sentry/server-utils');
// `cacheClient: false` so this gets its own client rather than one a previous `init()` cached.
const client = init({ cacheClient: false });
expect(client?.getIntegrationByName('Mysql')).toBeUndefined();
expect(client?.getIntegrationByName('LruMemoizer')).toBeUndefined();

// A module registering more than one integration (like `h3` → span + Server-Timing) evaluates
// after init: store the Set of factories on the marker, then emit the event.
globalThis.__SENTRY_ORCHESTRION__ = {
bundler: new Set(['some-module']),
integrations: new Map([['some-module', new Set([mysqlIntegration, lruMemoizerIntegration])]]),
};
client?.emit('orchestrion.module-injected', 'some-module');

expect(client?.getIntegrationByName('Mysql')).toBeDefined();
expect(client?.getIntegrationByName('LruMemoizer')).toBeDefined();
});

test('installs all integrations a single module registers', async () => {
const { mysqlIntegration, lruMemoizerIntegration } = await import('@sentry/server-utils');
// One module registering more than one integration (like `h3` → span + Server-Timing).
globalThis.__SENTRY_ORCHESTRION__ = {
bundler: new Set(['some-module']),
integrations: new Map([['some-module', new Set([mysqlIntegration, lruMemoizerIntegration])]]),
};

const names = getDefaultIntegrations({}).map(i => i.name);

expect(names).toContain('Mysql');
expect(names).toContain('LruMemoizer');
});
Comment thread
cursor[bot] marked this conversation as resolved.
});
13 changes: 8 additions & 5 deletions packages/core/src/utils/worldwide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ export type InternalGlobal = {
/**
* Channel-subscriber integration factories stored by the snippet the
* bundler transform splices into each instrumented module, keyed by module
* name. A factory shared by several packages (e.g. pg/pg-pool) appears
* under several keys; integration-name deduplication collapses them at
* setup. A bundler-only SDK (e.g. `@sentry/cloudflare`) reads these at
* `init()` and instantiates them.
* name. A module holds a single factory, or a Set of them once it registers
* more than one integration (e.g. `h3` → span + Server-Timing) — the single
* shape is kept for the common case so an older reader stays compatible. A
* factory shared by several packages (e.g. pg/pg-pool) appears under several
* keys; integration-name deduplication collapses them at setup. A
* bundler-only SDK (e.g. `@sentry/cloudflare`) reads these at `init()` and
* instantiates them.
*/
integrations?: Map<string, () => Integration>;
integrations?: Map<string, (() => Integration) | Set<() => Integration>>;
/**
* Set once `registerDiagnosticsChannelInjection()` has run but could not
* install the runtime module hooks — most commonly because
Expand Down
2 changes: 2 additions & 0 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export {
mongooseIntegration,
mysqlIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
mistralAIIntegration,
openAIIntegration,
groqIntegration,
Expand Down
63 changes: 3 additions & 60 deletions packages/deno/test/__snapshots__/mod.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,7 @@ snapshot[`captureMessage 1`] = `
platform: "javascript",
sdk: {
integrations: [
"EventFilters",
"RequestData",
"FunctionToString",
"LinkedErrors",
"Dedupe",
"ConversationId",
"Breadcrumbs",
"Console",
"DenoContext",
"DenoServe",
"Fetch",
"DenoHttp",
"ContextLines",
"NormalizePaths",
"GlobalHandlers",
"Express",
"Fastify",
"Hapi",
"Hono",
"Koa",
"{{integrations}}",
],
name: "sentry.javascript.deno",
packages: [
Expand Down Expand Up @@ -136,26 +117,7 @@ snapshot[`captureMessage twice 1`] = `
platform: "javascript",
sdk: {
integrations: [
"EventFilters",
"RequestData",
"FunctionToString",
"LinkedErrors",
"Dedupe",
"ConversationId",
"Breadcrumbs",
"Console",
"DenoContext",
"DenoServe",
"Fetch",
"DenoHttp",
"ContextLines",
"NormalizePaths",
"GlobalHandlers",
"Express",
"Fastify",
"Hapi",
"Hono",
"Koa",
"{{integrations}}",
],
name: "sentry.javascript.deno",
packages: [
Expand Down Expand Up @@ -232,26 +194,7 @@ snapshot[`captureMessage twice 2`] = `
platform: "javascript",
sdk: {
integrations: [
"EventFilters",
"RequestData",
"FunctionToString",
"LinkedErrors",
"Dedupe",
"ConversationId",
"Breadcrumbs",
"Console",
"DenoContext",
"DenoServe",
"Fetch",
"DenoHttp",
"ContextLines",
"NormalizePaths",
"GlobalHandlers",
"Express",
"Fastify",
"Hapi",
"Hono",
"Koa",
"{{integrations}}",
],
name: "sentry.javascript.deno",
packages: [
Expand Down
6 changes: 6 additions & 0 deletions packages/deno/test/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ function normalizeEvent(event: Event): Event {
}
}

// The default integration list is incidental to these snapshots, so collapse it to a placeholder.
// This keeps the snapshots stable when integrations are added to or removed from the defaults.
if (event.sdk?.integrations) {
event.sdk.integrations = ['{{integrations}}'];
}

if (event.contexts?.app?.app_start_time) {
event.contexts.app.app_start_time = '{{time}}';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/elysia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export {
mongooseIntegration,
mysqlIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
redisIntegration,
tediousIntegration,
postgresIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export {
mongooseIntegration,
mysqlIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
redisIntegration,
tediousIntegration,
pinoIntegration,
Expand Down
3 changes: 1 addition & 2 deletions packages/nitro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
"@sentry/conventions": "^0.24.0",
"@sentry/core": "11.1.0",
"@sentry/node": "11.1.0",
"@sentry/server-runtime-injection": "11.1.0",
"@sentry/server-utils": "11.1.0"
"@sentry/server-runtime-injection": "11.1.0"
},
"devDependencies": {
"nitro": "^3.0.260415-beta"
Expand Down
27 changes: 0 additions & 27 deletions packages/nitro/src/runtime/hooks/setServerTimingHeaders.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/nitro/src/runtime/plugins/server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { definePlugin } from 'nitro';
import { captureErrorHook } from '../hooks/captureErrorHook';
import { captureStorageEvents } from '../hooks/captureStorageEvents';
import { captureTracingEvents } from '../hooks/captureTracingEvents';

export default definePlugin(nitroApp => {
nitroApp.hooks.hook('error', captureErrorHook);

captureTracingEvents();
captureStorageEvents();
});
6 changes: 4 additions & 2 deletions packages/nitro/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Integration } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import type { NodeClient, NodeOptions } from '@sentry/node';
import { getDefaultIntegrations as getDefaultNodeIntegrations, init as nodeInit } from '@sentry/node';
import { getDefaultIntegrations as getDefaultNodeIntegrations, init as nodeInit, nitroIntegration } from '@sentry/node';

/**
* Initializes the Nitro SDK
Expand All @@ -28,5 +28,7 @@ export function init(options: NodeOptions | undefined = {}): NodeClient | undefi
* @returns The default integrations for the Nitro SDK.
*/
export function getDefaultIntegrations(options: NodeOptions): Integration[] | undefined {
return [...getDefaultNodeIntegrations(options)];
// `nitroIntegration` is also part of the Node tracing integrations, but add it explicitly so it is
// always present for the Nitro SDK regardless of that gating (deduped by name when both are added).
return [...getDefaultNodeIntegrations(options), nitroIntegration()];
}
2 changes: 2 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export {
mysqlIntegration,
mistralAIIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
openAIIntegration,
togetherAIIntegration,
typesafeIntegration,
Expand Down
2 changes: 2 additions & 0 deletions packages/remix/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export {
mongoIntegration,
mongooseIntegration,
mysql2Integration,
nitroIntegration,
nitroServerTimingIntegration,
mysqlIntegration,
nativeNodeFetchIntegration,
NodeClient,
Expand Down
1 change: 1 addition & 0 deletions packages/server-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ export type { ExpressIntegrationOptions } from './integrations/express/types';
export { expressErrorHandler, setupExpressErrorHandler } from './integrations/express/error-handler';
/* oxlint-enable typescript/no-deprecated */
export { firebaseIntegration } from './integrations/firebase';
export { nitroIntegration, nitroServerTimingIntegration } from './integrations/nitro';

export { getTracingIntegrations, getErrorIntegrations } from './integrations';
17 changes: 15 additions & 2 deletions packages/server-utils/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { postgresJsIntegration } from './postgres-js';
import { firebaseIntegration } from './firebase';
import { expressIntegration } from './express';
import { fastifyIntegration } from './fastify';
import { nitroIntegration, nitroServerTimingIntegration } from './nitro';
import { hapiIntegration } from './hapi';
import { honoIntegration } from './hono';
import { koaIntegration } from './koa';
Expand Down Expand Up @@ -70,10 +71,22 @@ export function getTracingIntegrations(): Integration[] {
postgresJsIntegration(),
firebaseIntegration(),
mcpServerIntegration(),
nitroIntegration(),
];
}

/** These are integrations that cover error capture, in addition to tracing. */
/**
* These are default integrations that are registered regardless of whether tracing is enabled -
* either because they cover error capture in addition to tracing, or because they only handle trace
* propagation (which must work in tracing-without-performance mode too).
*/
export function getErrorIntegrations(): Integration[] {
return [expressIntegration(), fastifyIntegration(), hapiIntegration(), honoIntegration(), koaIntegration()];
return [
expressIntegration(),
fastifyIntegration(),
hapiIntegration(),
honoIntegration(),
koaIntegration(),
nitroServerTimingIntegration(),
];
}
Loading