Skip to content

fix(node): Add compatibility layer for Prisma v5 #15169

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

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"build:types": "tsc -p tsconfig.types.json",
"clean": "rimraf -g **/node_modules && run-p clean:script",
"clean:script": "node scripts/clean.js",
"prisma:init": "cd suites/tracing/prisma-orm && yarn && yarn setup",
"prisma-v5:init": "cd suites/tracing/prisma-orm-v5 && yarn && yarn setup",
"prisma-v6:init": "cd suites/tracing/prisma-orm-v6 && yarn && yarn setup",
"lint": "eslint . --format stylish",
"fix": "eslint . --format stylish --fix",
"type-check": "tsc",
"pretest": "run-s --silent prisma:init",
"pretest": "run-s --silent prisma-v5:init prisma-v6:init",
"test": "jest --config ./jest.config.js",
"test:watch": "yarn test --watch"
},
Expand All @@ -30,7 +31,6 @@
"@nestjs/common": "10.4.6",
"@nestjs/core": "10.4.6",
"@nestjs/platform-express": "10.4.6",
"@prisma/client": "6.2.1",
"@sentry/aws-serverless": "9.0.0-alpha.0",
"@sentry/core": "9.0.0-alpha.0",
"@sentry/node": "9.0.0-alpha.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
db:
image: postgres:13
restart: always
container_name: integration-tests-prisma
container_name: integration-tests-prisma-v5
ports:
- '5433:5432'
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "sentry-prisma-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": {
"node": ">=18"
},
"scripts": {
"db-up": "docker compose up -d",
"generate": "prisma generate",
"migrate": "prisma migrate dev -n sentry-test",
"setup": "run-s --silent db-up generate migrate"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "5.22.0",
"@prisma/instrumentation": "5.22.0",
"prisma": "5.22.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ datasource db {

generator client {
provider = "prisma-client-js"
previewFeatures = ["tracing"]
}

model User {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const Sentry = require('@sentry/node');
const { PrismaInstrumentation } = require('@prisma/instrumentation');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [
Sentry.prismaIntegration({
prismaInstrumentation: new PrismaInstrumentation(),
}),
],
});

const { randomBytes } = require('crypto');
const { PrismaClient } = require('@prisma/client');

// Stop the process from exiting before the transaction is sent
setInterval(() => {}, 1000);

async function run() {
const client = new PrismaClient();

await Sentry.startSpanManual(
{
name: 'Test Transaction',
op: 'transaction',
},
async span => {
await client.user.create({
data: {
name: 'Tilda',
email: `tilda_${randomBytes(4).toString('hex')}@sentry.io`,
},
});

await client.user.findMany();

await client.user.deleteMany({
where: {
email: {
contains: 'sentry.io',
},
},
});

setTimeout(async () => {
span.end();
await client.$disconnect();
}, 500);
},
);
}

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { createRunner } from '../../../utils/runner';

describe('Prisma ORM Tests', () => {
test('CJS - should instrument PostgreSQL queries from Prisma ORM', done => {
createRunner(__dirname, 'scenario.js')
.expect({
transaction: transaction => {
expect(transaction.transaction).toBe('Test Transaction');
const spans = transaction.spans || [];
expect(spans.length).toBeGreaterThanOrEqual(5);

expect(spans).toContainEqual(
expect.objectContaining({
data: {
method: 'create',
model: 'User',
name: 'User.create',
'sentry.origin': 'auto.db.otel.prisma',
},
description: 'prisma:client:operation',
status: 'ok',
}),
);

expect(spans).toContainEqual(
expect.objectContaining({
data: {
'sentry.origin': 'auto.db.otel.prisma',
},
description: 'prisma:client:serialize',
status: 'ok',
}),
);

expect(spans).toContainEqual(
expect.objectContaining({
data: {
'sentry.origin': 'auto.db.otel.prisma',
},
description: 'prisma:client:connect',
status: 'ok',
}),
);

expect(spans).toContainEqual(
expect.objectContaining({
data: {
'db.statement': expect.stringContaining(
'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',
),
'sentry.origin': 'auto.db.otel.prisma',
'sentry.op': 'db',
'db.system': 'postgresql',
'otel.kind': 'CLIENT',
},
description: expect.stringContaining(
'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',
),
status: 'ok',
op: 'db',
}),
);
expect(spans).toContainEqual(
expect.objectContaining({
data: {
method: 'findMany',
model: 'User',
name: 'User.findMany',
'sentry.origin': 'auto.db.otel.prisma',
},
description: 'prisma:client:operation',
status: 'ok',
}),
);
expect(spans).toContainEqual(
expect.objectContaining({
data: {
'sentry.origin': 'auto.db.otel.prisma',
},
description: 'prisma:client:serialize',
status: 'ok',
}),
);
},
})
.start(done);
});
});
Loading
Loading