Skip to content

Commit 56f5098

Browse files
sebwsJPeer264
andauthored
feat(node): pass prisma instrumentation options through (#18900)
Before submitting a pull request, please take a look at our [Contributing](https://github.com/getsentry/sentry-javascript/blob/master/CONTRIBUTING.md) guidelines and verify: - [ ] ~If you've added code that should be tested, please add tests.~ - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). - [x] Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked. Closes #17181 --------- Co-authored-by: JPeer264 <jan.peer@sentry.io>
1 parent 9bf03cf commit 56f5098

2 files changed

Lines changed: 48 additions & 6 deletions

File tree

packages/node/src/integrations/tracing/prisma.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ interface PrismaOptions {
5858
* @deprecated This is no longer used, v5 works out of the box.
5959
*/
6060
prismaInstrumentation?: Instrumentation;
61+
/**
62+
* Configuration passed through to the {@link PrismaInstrumentation} constructor.
63+
*/
64+
instrumentationConfig?: ConstructorParameters<typeof PrismaInstrumentation>[0];
6165
}
6266

6367
class SentryPrismaInteropInstrumentation extends PrismaInstrumentation {
64-
public constructor() {
65-
super();
68+
public constructor(options?: PrismaOptions) {
69+
super(options?.instrumentationConfig);
6670
}
6771

6872
public enable(): void {
@@ -165,8 +169,8 @@ function engineSpanKindToOTELSpanKind(engineSpanKind: V5EngineSpanKind): SpanKin
165169
}
166170
}
167171

168-
export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, _options => {
169-
return new SentryPrismaInteropInstrumentation();
172+
export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATION_NAME, options => {
173+
return new SentryPrismaInteropInstrumentation(options);
170174
});
171175

172176
/**
@@ -201,11 +205,11 @@ export const instrumentPrisma = generateInstrumentOnce<PrismaOptions>(INTEGRATIO
201205
* }
202206
* ```
203207
*/
204-
export const prismaIntegration = defineIntegration((_options?: PrismaOptions) => {
208+
export const prismaIntegration = defineIntegration((options?: PrismaOptions) => {
205209
return {
206210
name: INTEGRATION_NAME,
207211
setupOnce() {
208-
instrumentPrisma();
212+
instrumentPrisma(options);
209213
},
210214
setup(client) {
211215
// If no tracing helper exists, we skip any work here
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { PrismaInstrumentation } from '@prisma/instrumentation';
2+
import { INSTRUMENTED } from '@sentry/node-core';
3+
import { beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest';
4+
import { instrumentPrisma } from '../../../src/integrations/tracing/prisma';
5+
6+
vi.mock('@prisma/instrumentation');
7+
8+
describe('Prisma', () => {
9+
beforeEach(() => {
10+
vi.clearAllMocks();
11+
delete INSTRUMENTED.Prisma;
12+
13+
(PrismaInstrumentation as unknown as MockInstance).mockImplementation(() => {
14+
return {
15+
setTracerProvider: () => undefined,
16+
setMeterProvider: () => undefined,
17+
getConfig: () => ({}),
18+
setConfig: () => ({}),
19+
enable: () => undefined,
20+
};
21+
});
22+
});
23+
24+
it('defaults are correct for instrumentPrisma', () => {
25+
instrumentPrisma();
26+
27+
expect(PrismaInstrumentation).toHaveBeenCalledTimes(1);
28+
expect(PrismaInstrumentation).toHaveBeenCalledWith(undefined);
29+
});
30+
31+
it('passes instrumentationConfig option to PrismaInstrumentation', () => {
32+
const config = { ignoreSpanTypes: [] };
33+
instrumentPrisma({ instrumentationConfig: config });
34+
35+
expect(PrismaInstrumentation).toHaveBeenCalledTimes(1);
36+
expect(PrismaInstrumentation).toHaveBeenCalledWith(config);
37+
});
38+
});

0 commit comments

Comments
 (0)