-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): pass prisma instrumentation options through #18900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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); | ||
sebws marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+172
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Re-initializing Suggested FixRefactor Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| }); | ||
|
|
||
| /** | ||
|
|
@@ -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 | ||
|
|
||
| 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); | ||
| }); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing integration or E2E tests for featureLow Severity · Bugbot Rules The PR adds a new |
||
Uh oh!
There was an error while loading. Please reload this page.