diff --git a/packages/node/src/integrations/tracing/prisma.ts b/packages/node/src/integrations/tracing/prisma.ts index 503e8c1908a4..b81adc9552a8 100644 --- a/packages/node/src/integrations/tracing/prisma.ts +++ b/packages/node/src/integrations/tracing/prisma.ts @@ -58,11 +58,15 @@ interface PrismaOptions { * @deprecated This is no longer used, v5 works out of the box. */ prismaInstrumentation?: Instrumentation; + /** + * Configuration passed through to the {@link PrismaInstrumentation} constructor. + */ + instrumentationConfig?: ConstructorParameters[0]; } class SentryPrismaInteropInstrumentation extends PrismaInstrumentation { - public constructor() { - super(); + public constructor(options?: PrismaOptions) { + super(options?.instrumentationConfig); } public enable(): void { @@ -165,8 +169,8 @@ function engineSpanKindToOTELSpanKind(engineSpanKind: V5EngineSpanKind): SpanKin } } -export const instrumentPrisma = generateInstrumentOnce(INTEGRATION_NAME, _options => { - return new SentryPrismaInteropInstrumentation(); +export const instrumentPrisma = generateInstrumentOnce(INTEGRATION_NAME, options => { + return new SentryPrismaInteropInstrumentation(options); }); /** @@ -201,11 +205,11 @@ export const instrumentPrisma = generateInstrumentOnce(INTEGRATIO * } * ``` */ -export const prismaIntegration = defineIntegration((_options?: PrismaOptions) => { +export const prismaIntegration = defineIntegration((options?: PrismaOptions) => { return { name: INTEGRATION_NAME, setupOnce() { - instrumentPrisma(); + instrumentPrisma(options); }, setup(client) { // If no tracing helper exists, we skip any work here diff --git a/packages/node/test/integrations/tracing/prisma.test.ts b/packages/node/test/integrations/tracing/prisma.test.ts new file mode 100644 index 000000000000..7fb734d7193d --- /dev/null +++ b/packages/node/test/integrations/tracing/prisma.test.ts @@ -0,0 +1,38 @@ +import { PrismaInstrumentation } from '@prisma/instrumentation'; +import { INSTRUMENTED } from '@sentry/node-core'; +import { beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest'; +import { instrumentPrisma } from '../../../src/integrations/tracing/prisma'; + +vi.mock('@prisma/instrumentation'); + +describe('Prisma', () => { + beforeEach(() => { + vi.clearAllMocks(); + delete INSTRUMENTED.Prisma; + + (PrismaInstrumentation as unknown as MockInstance).mockImplementation(() => { + return { + setTracerProvider: () => undefined, + setMeterProvider: () => undefined, + getConfig: () => ({}), + setConfig: () => ({}), + enable: () => undefined, + }; + }); + }); + + it('defaults are correct for instrumentPrisma', () => { + instrumentPrisma(); + + expect(PrismaInstrumentation).toHaveBeenCalledTimes(1); + expect(PrismaInstrumentation).toHaveBeenCalledWith(undefined); + }); + + it('passes instrumentationConfig option to PrismaInstrumentation', () => { + const config = { ignoreSpanTypes: [] }; + instrumentPrisma({ instrumentationConfig: config }); + + expect(PrismaInstrumentation).toHaveBeenCalledTimes(1); + expect(PrismaInstrumentation).toHaveBeenCalledWith(config); + }); +});