Skip to content

Commit 2a51a0b

Browse files
author
Luca Forstner
committed
.
1 parent b5355da commit 2a51a0b

File tree

2 files changed

+75
-6
lines changed
  • dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5
  • packages/node/src/integrations/tracing

2 files changed

+75
-6
lines changed

dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ conditionalTest({ min: 16 })('Prisma ORM Tests', () => {
77
.expect({
88
transaction: transaction => {
99
expect(transaction.transaction).toBe('Test Transaction');
10+
1011
const spans = transaction.spans || [];
1112
expect(spans.length).toBeGreaterThanOrEqual(5);
1213

@@ -42,6 +43,65 @@ conditionalTest({ min: 16 })('Prisma ORM Tests', () => {
4243
status: 'ok',
4344
}),
4445
);
46+
47+
expect(spans).toContainEqual(
48+
expect.objectContaining({
49+
data: {
50+
'sentry.origin': 'auto.db.otel.prisma',
51+
},
52+
description: 'prisma:engine',
53+
status: 'ok',
54+
}),
55+
);
56+
expect(spans).toContainEqual(
57+
expect.objectContaining({
58+
data: {
59+
'sentry.origin': 'auto.db.otel.prisma',
60+
'sentry.op': 'db',
61+
'db.system': 'postgresql',
62+
},
63+
description: 'prisma:engine:connection',
64+
status: 'ok',
65+
op: 'db',
66+
}),
67+
);
68+
69+
expect(spans).toContainEqual(
70+
expect.objectContaining({
71+
data: {
72+
'db.statement': expect.stringContaining(
73+
'INSERT INTO "public"."User" ("createdAt","email","name") VALUES ($1,$2,$3) RETURNING "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" /* traceparent',
74+
),
75+
'sentry.origin': 'auto.db.otel.prisma',
76+
'sentry.op': 'db',
77+
'db.system': 'postgresql',
78+
'otel.kind': 'CLIENT',
79+
},
80+
description: expect.stringContaining(
81+
'INSERT INTO "public"."User" ("createdAt","email","name") VALUES ($1,$2,$3) RETURNING "public"."User"."id", "public"."User"."createdAt", "public"."User"."email", "public"."User"."name" /* traceparent',
82+
),
83+
status: 'ok',
84+
op: 'db',
85+
}),
86+
);
87+
expect(spans).toContainEqual(
88+
expect.objectContaining({
89+
data: {
90+
'sentry.origin': 'auto.db.otel.prisma',
91+
},
92+
description: 'prisma:engine:serialize',
93+
status: 'ok',
94+
}),
95+
);
96+
expect(spans).toContainEqual(
97+
expect.objectContaining({
98+
data: {
99+
'sentry.origin': 'auto.db.otel.prisma',
100+
},
101+
description: 'prisma:engine:response_json_serialization',
102+
status: 'ok',
103+
}),
104+
);
45105
expect(spans).toContainEqual(
46106
expect.objectContaining({
47107
data: {
@@ -63,6 +123,15 @@ conditionalTest({ min: 16 })('Prisma ORM Tests', () => {
63123
status: 'ok',
64124
}),
65125
);
126+
expect(spans).toContainEqual(
127+
expect.objectContaining({
128+
data: {
129+
'sentry.origin': 'auto.db.otel.prisma',
130+
},
131+
description: 'prisma:engine',
132+
status: 'ok',
133+
}),
134+
);
66135
},
67136
})
68137
.start(done);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const EsmInteropPrismaInstrumentation: typeof prismaInstrumentation.PrismaInstru
1515

1616
type CompatibilityLayerTraceHelper = PrismaV5TracingHelper & PrismaV6TracingHelper;
1717

18-
function isPrismaV6TracingHelper(helper: unknown): helper is PrismaV6TracingHelper {
19-
return !!helper && typeof helper === 'object' && 'dispatchEngineSpans' in helper;
18+
function isPrismaV5TracingHelper(helper: unknown): helper is PrismaV5TracingHelper {
19+
return !!helper && typeof helper === 'object' && 'createEngineSpan' in helper;
2020
}
2121

2222
class SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation {
@@ -27,7 +27,7 @@ class SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation
2727
public enable(): void {
2828
super.enable();
2929

30-
// The PrismaIntegration (super class) defines a global variable `global["PRISMA_INSTRUMENTATION"]` when `enable()` is called. This global variable holds a "TracingHelper" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 5 with the v6 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.
30+
// The PrismaIntegration (super class) defines a global variable `global["PRISMA_INSTRUMENTATION"]` when `enable()` is called. This global variable holds a "TracingHelper" which Prisma uses internally to create tracing data. It's their way of not depending on OTEL with their main package. The sucky thing is, prisma broke the interface of the tracing helper with the v6 major update. This means that if you use Prisma 6 with the v5 instrumentation (or vice versa) Prisma just blows up, because tries to call methods on the helper that no longer exist.
3131
// Because we actually want to use the v6 instrumentation and not blow up in Prisma 5 user's faces, what we're doing here is backfilling the v5 method (`createEngineSpan`) with a noop so that no longer crashes when it attempts to call that function.
3232
// We still won't fully emit all the spans, but this could potentially be implemented in the future.
3333
const prismaInstrumentationObject = (globalThis as Record<string, unknown>).PRISMA_INSTRUMENTATION;
@@ -40,14 +40,14 @@ class SentryPrismaInteropInstrumentation extends EsmInteropPrismaInstrumentation
4040

4141
let emittedWarning = false;
4242

43-
if (isPrismaV6TracingHelper(prismaTracingHelper)) {
44-
(prismaTracingHelper as CompatibilityLayerTraceHelper).createEngineSpan = () => {
43+
if (isPrismaV5TracingHelper(prismaTracingHelper)) {
44+
(prismaTracingHelper as CompatibilityLayerTraceHelper).dispatchEngineSpans = () => {
4545
consoleSandbox(() => {
4646
if (!emittedWarning) {
4747
emittedWarning = true;
4848
// eslint-disable-next-line no-console
4949
console.warn(
50-
'[Sentry] The Sentry SDK supports tracing with Prisma version 5 only with limited capabilities. For full tracing capabilities pass `prismaInstrumentation` for version 5 to the Sentry `prismaIntegration`. Read more: https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/',
50+
'[Sentry] This version of the Sentry SDK supports tracing with Prisma 6 only with very limited capabilities. For full tracing capabilities pass `prismaInstrumentation` for version 6 to the Sentry `prismaIntegration`. Read more: https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/prisma/',
5151
);
5252
}
5353
});

0 commit comments

Comments
 (0)