Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 434adfe

Browse files
committed
fix preloading
fix test
1 parent e3b58cf commit 434adfe

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

‎packages/node/src/integrations/tracing/fastify/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ interface FastifyHandlerOptions {
9090
}
9191

9292
const INTEGRATION_NAME = 'Fastify';
93-
const INTEGRATION_NAME_V5 = 'Fastify-V5';
94-
const INTEGRATION_NAME_V3 = 'Fastify-V3';
9593

96-
export const instrumentFastifyV3 = generateInstrumentOnce(INTEGRATION_NAME_V3, () => new FastifyInstrumentationV3());
94+
export const instrumentFastifyV3 = generateInstrumentOnce(
95+
`${INTEGRATION_NAME}.v3`,
96+
() => new FastifyInstrumentationV3(),
97+
);
9798

9899
function getFastifyIntegration(): ReturnType<typeof _fastifyIntegration> | undefined {
99100
const client = getClient();
@@ -135,7 +136,7 @@ function handleFastifyError(
135136
}
136137
}
137138

138-
export const instrumentFastify = generateInstrumentOnce(INTEGRATION_NAME_V5, () => {
139+
export const instrumentFastify = generateInstrumentOnce(`${INTEGRATION_NAME}.v5`, () => {
139140
const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation();
140141
const plugin = fastifyOtelInstrumentationInstance.plugin();
141142

‎packages/node/src/sdk/initOtel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ function getPreloadMethods(integrationNames?: string[]): ((() => void) & { id: s
101101
return instruments;
102102
}
103103

104-
return instruments.filter(instrumentation => integrationNames.includes(instrumentation.id));
104+
// We match exact matches of instrumentation, but also match prefixes, e.g. "Fastify.v5" will match "Fastify"
105+
return instruments.filter(instrumentation => {
106+
const id = instrumentation.id;
107+
return integrationNames.some(integrationName => id === integrationName || id.startsWith(`${integrationName}.`));
108+
});
105109
}
106110

107111
/** Just exported for tests. */

‎packages/node/test/sdk/preload.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
import { debug } from '@sentry/core';
2-
import { afterEach, describe, expect, it, vi } from 'vitest';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { resetGlobals } from '../helpers/mockSdkInit';
34

45
describe('preload', () => {
6+
beforeEach(() => {
7+
// Mock this to prevent conflicts with other tests
8+
vi.mock('../../src/integrations/tracing', async (importOriginal: () => Promise<Record<string, unknown>>) => {
9+
const actual = await importOriginal();
10+
return {
11+
...actual,
12+
getOpenTelemetryInstrumentationToPreload: () => [
13+
Object.assign(vi.fn(), { id: 'Http.sentry' }),
14+
Object.assign(vi.fn(), { id: 'Http' }),
15+
Object.assign(vi.fn(), { id: 'Express' }),
16+
Object.assign(vi.fn(), { id: 'Graphql' }),
17+
],
18+
};
19+
});
20+
});
21+
522
afterEach(() => {
6-
vi.resetAllMocks();
723
debug.disable();
24+
resetGlobals();
825

926
delete process.env.SENTRY_DEBUG;
1027
delete process.env.SENTRY_PRELOAD_INTEGRATIONS;
@@ -29,6 +46,7 @@ describe('preload', () => {
2946

3047
await import('../../src/preload');
3148

49+
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Http.sentry instrumentation');
3250
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Http instrumentation');
3351
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Express instrumentation');
3452
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Graphql instrumentation');
@@ -44,6 +62,7 @@ describe('preload', () => {
4462

4563
await import('../../src/preload');
4664

65+
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Http.sentry instrumentation');
4766
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Http instrumentation');
4867
expect(logSpy).toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Express instrumentation');
4968
expect(logSpy).not.toHaveBeenCalledWith('Sentry Logger [log]:', '[Sentry] Preloaded Graphql instrumentation');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /