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
16 changes: 10 additions & 6 deletions packages/node/src/integrations/tracing/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof PrismaInstrumentation>[0];
}

class SentryPrismaInteropInstrumentation extends PrismaInstrumentation {
public constructor() {
super();
public constructor(options?: PrismaOptions) {
super(options?.instrumentationConfig);
}

public enable(): void {
Expand Down Expand Up @@ -165,8 +169,8 @@ function engineSpanKindToOTELSpanKind(engineSpanKind: V5EngineSpanKind): SpanKin
}
}

export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, _options => {
return new SentryPrismaInteropInstrumentation();
export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, options => {
return new SentryPrismaInteropInstrumentation(options);
Comment on lines +172 to +173
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Re-initializing prismaIntegration with new options passes the wrong object shape to setConfig, causing the new configuration to be ignored or fail.
Severity: MEDIUM

Suggested Fix

Refactor instrumentPrisma to use the three-parameter form of generateInstrumentOnce, providing an optionsCallback function. This callback should extract the instrumentationConfig from the full PrismaOptions object, ensuring that both the constructor and setConfig receive an object with the same, correct shape. This pattern is used by the GraphQL integration.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/node/src/integrations/tracing/prisma.ts#L172-L173

Potential issue: The `prismaIntegration` uses a version of `generateInstrumentOnce` that
causes a type mismatch during re-initialization. On the first call, the
`SentryPrismaInteropInstrumentation` constructor correctly receives the
`instrumentationConfig` object. However, on subsequent calls with new options, the
`instrumented.setConfig()` method is called with the entire `PrismaOptions` object, not
just the nested `instrumentationConfig`. This mismatch means any updated configuration
will be ignored or could lead to runtime errors if the application hot-reloads or
re-initializes Sentry with different Prisma settings.

Did we get this right? 👍 / 👎 to inform future reviews.

});

/**
Expand Down Expand Up @@ -201,11 +205,11 @@ export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(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
Expand Down
38 changes: 38 additions & 0 deletions packages/node/test/integrations/tracing/prisma.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing integration or E2E tests for feature

Low Severity · Bugbot Rules

The PR adds a new instrumentationConfig option (a feat PR) but only includes unit tests with mocked dependencies. Per the review rules: "When reviewing a feat PR, check if the PR includes at least one integration or E2E test." The existing unit tests verify mock interactions but don't test that configuration actually passes through to a real PrismaInstrumentation instance and affects behavior correctly. Flagging because the rules file explicitly requires this.

Fix in Cursor Fix in Web

Loading