Skip to content

Commit d6e3e41

Browse files
logaretmjulien1619claude
authored
fix: update prisma v7 spans descriptions (#20456)
Applies the same fix as in #19924 closes #18797 Co-authored-by: Julien Blatecky <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
1 parent a2a1bef commit d6e3e41

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

  • dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7
  • packages/node/src/integrations/tracing

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ conditionalTest({ min: 20 })('Prisma ORM v7 Tests', () => {
3737
expect(spanDescriptions).toContain('prisma:client:operation');
3838
expect(spanDescriptions).toContain('prisma:client:serialize');
3939
expect(spanDescriptions).toContain('prisma:client:connect');
40-
expect(spanDescriptions).toContain('prisma:client:db_query');
4140

4241
// Verify the create operation has correct metadata
4342
const createSpan = prismaSpans.find(
@@ -48,11 +47,17 @@ conditionalTest({ min: 20 })('Prisma ORM v7 Tests', () => {
4847
);
4948
expect(createSpan).toBeDefined();
5049

51-
// Verify db_query span has system info and correct op (v7 uses db.system.name)
52-
const dbQuerySpan = prismaSpans.find(span => span.description === 'prisma:client:db_query');
50+
// Verify db_query span has system info and correct op (v7 uses db.system.name).
51+
// The SDK should rewrite the span name to the actual SQL text (same as v5/v6
52+
// `prisma:engine:db_query`), so we find it via op/origin rather than description.
53+
const dbQuerySpan = prismaSpans.find(
54+
span => span.data?.['sentry.op'] === 'db' && span.data?.['db.query.text'],
55+
);
56+
expect(dbQuerySpan).toBeDefined();
5357
expect(dbQuerySpan?.data?.['db.system.name']).toBe('postgresql');
54-
expect(dbQuerySpan?.data?.['sentry.op']).toBe('db');
5558
expect(dbQuerySpan?.op).toBe('db');
59+
expect(dbQuerySpan?.description).toBe(dbQuerySpan?.data?.['db.query.text']);
60+
expect(dbQuerySpan?.description).not.toBe('prisma:client:db_query');
5661
},
5762
})
5863
.start()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,12 @@ export const prismaIntegration = defineIntegration((options?: PrismaOptions) =>
224224
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.prisma');
225225
}
226226

227-
// Make sure we use the query text as the span name, for ex. SELECT * FROM "User" WHERE "id" = $1
228-
if (spanJSON.description === 'prisma:engine:db_query' && spanJSON.data['db.query.text']) {
227+
// Make sure we use the query text as the span name, for ex. SELECT * FROM "User" WHERE "id" = $1.
228+
// v5/v6 emit `prisma:engine:db_query`; v7 inlined the engine and emits `prisma:client:db_query`.
229+
if (
230+
(spanJSON.description === 'prisma:engine:db_query' || spanJSON.description === 'prisma:client:db_query') &&
231+
spanJSON.data['db.query.text']
232+
) {
229233
span.updateName(spanJSON.data['db.query.text'] as string);
230234
}
231235

0 commit comments

Comments
 (0)