-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Add Prisma v7 support #18908
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d229ad
feat(node): Add Prisma v7 support
andreiborza 671f472
Increase size limit for @sentry/node
andreiborza ea74146
Switch to rust-free prisma client
andreiborza c0c84d8
Migrate away from deprecated v7 options and generate prisma client
andreiborza b7b71a7
Skip tests on node 18, prisma requires node 20+
andreiborza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/docker-compose.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| version: '3.9' | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:13 | ||
| restart: always | ||
| container_name: integration-tests-prisma-v7 | ||
| ports: | ||
| - '5435:5432' | ||
| environment: | ||
| POSTGRES_USER: prisma | ||
| POSTGRES_PASSWORD: prisma | ||
| POSTGRES_DB: tests |
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/instrument.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| }); |
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/prisma.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { defineConfig } from 'prisma/config'; | ||
|
|
||
| export default defineConfig({ | ||
| schema: './prisma/schema.prisma', | ||
| migrations: './prisma/migrations', | ||
| datasource: { | ||
| url: 'postgresql://prisma:prisma@localhost:5435/tests', | ||
| }, | ||
| }); |
3 changes: 3 additions & 0 deletions
3
...node-integration-tests/suites/tracing/prisma-orm-v7/prisma/migrations/migration_lock.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Please do not edit this file manually | ||
| # It should be added in your version-control system (i.e. Git) | ||
| provider = "postgresql" |
12 changes: 12 additions & 0 deletions
12
...ntegration-tests/suites/tracing/prisma-orm-v7/prisma/migrations/sentry_test/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "User" ( | ||
| "id" SERIAL NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "email" TEXT NOT NULL, | ||
| "name" TEXT, | ||
|
|
||
| CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); |
15 changes: 15 additions & 0 deletions
15
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/prisma/schema.prisma
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| datasource db { | ||
| provider = "postgresql" | ||
| } | ||
|
|
||
| generator client { | ||
| provider = "prisma-client" | ||
| output = "./generated/prisma" | ||
| } | ||
|
|
||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| createdAt DateTime @default(now()) | ||
| email String @unique | ||
| name String? | ||
| } |
11 changes: 11 additions & 0 deletions
11
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/prisma/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "target": "ES2023", | ||
| "declaration": false, | ||
| "rewriteRelativeImportExtensions": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["./generated/prisma/**/*.ts"] | ||
| } |
46 changes: 46 additions & 0 deletions
46
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/scenario.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { PrismaPg } from '@prisma/adapter-pg'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import { randomBytes } from 'crypto'; | ||
| import { PrismaClient } from './prisma/generated/prisma/client.js'; | ||
|
|
||
| // Stop the process from exiting before the transaction is sent | ||
| setInterval(() => {}, 1000); | ||
|
|
||
| const connectionString = 'postgresql://prisma:prisma@localhost:5435/tests'; | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan( | ||
| { | ||
| name: 'Test Transaction', | ||
| op: 'transaction', | ||
| }, | ||
| async span => { | ||
| const adapter = new PrismaPg({ connectionString }); | ||
| const client = new PrismaClient({ adapter }); | ||
|
|
||
| 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(); | ||
74 changes: 74 additions & 0 deletions
74
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v7/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { afterAll, expect } from 'vitest'; | ||
| import { conditionalTest } from '../../../utils'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| // Prisma 7 requires Node.js 20.19+ | ||
| conditionalTest({ min: 20 })('Prisma ORM v7 Tests', () => { | ||
| createEsmAndCjsTests( | ||
| __dirname, | ||
| 'scenario.mjs', | ||
| 'instrument.mjs', | ||
| (createRunner, test, _mode, cwd) => { | ||
| test('should instrument PostgreSQL queries from Prisma ORM', { timeout: 75_000 }, async () => { | ||
| await createRunner() | ||
| .withDockerCompose({ | ||
| workingDirectory: [cwd], | ||
| readyMatches: ['port 5432'], | ||
| setupCommand: `prisma generate --schema ${cwd}/prisma/schema.prisma && tsc -p ${cwd}/prisma/tsconfig.json && prisma migrate dev -n sentry-test --schema ${cwd}/prisma/schema.prisma`, | ||
|
Member
Author
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. This previously used the workspace prisma, which was v6. I changed the runner to modify |
||
| }) | ||
| .expect({ | ||
| transaction: transaction => { | ||
| expect(transaction.transaction).toBe('Test Transaction'); | ||
|
|
||
| const spans = transaction.spans || []; | ||
| expect(spans.length).toBeGreaterThanOrEqual(5); | ||
|
|
||
| // Verify Prisma spans have the correct origin | ||
| const prismaSpans = spans.filter( | ||
| span => span.data && span.data['sentry.origin'] === 'auto.db.otel.prisma', | ||
| ); | ||
| expect(prismaSpans.length).toBeGreaterThanOrEqual(5); | ||
|
|
||
| // Check for key Prisma span descriptions | ||
| const spanDescriptions = prismaSpans.map(span => span.description); | ||
| expect(spanDescriptions).toContain('prisma:client:operation'); | ||
| expect(spanDescriptions).toContain('prisma:client:serialize'); | ||
| expect(spanDescriptions).toContain('prisma:client:connect'); | ||
| expect(spanDescriptions).toContain('prisma:client:db_query'); | ||
|
|
||
| // Verify the create operation has correct metadata | ||
| const createSpan = prismaSpans.find( | ||
| span => | ||
| span.description === 'prisma:client:operation' && | ||
| span.data?.['method'] === 'create' && | ||
| span.data?.['model'] === 'User', | ||
| ); | ||
| expect(createSpan).toBeDefined(); | ||
|
|
||
| // Verify db_query span has system info and correct op (v7 uses db.system.name) | ||
| const dbQuerySpan = prismaSpans.find(span => span.description === 'prisma:client:db_query'); | ||
| expect(dbQuerySpan?.data?.['db.system.name']).toBe('postgresql'); | ||
| expect(dbQuerySpan?.data?.['sentry.op']).toBe('db'); | ||
| expect(dbQuerySpan?.op).toBe('db'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }, | ||
| { | ||
| additionalDependencies: { | ||
| '@prisma/adapter-pg': '7.2.0', | ||
| '@prisma/client': '7.2.0', | ||
| pg: '^8.11.0', | ||
| prisma: '7.2.0', | ||
| typescript: '^5.9.0', | ||
| }, | ||
| copyPaths: ['prisma', 'prisma.config.ts', 'docker-compose.yml'], | ||
| }, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong API used: span auto-ends before setTimeout fires
Low Severity
The v7 scenario uses
Sentry.startSpan()with an async callback that includes asetTimeoutcallingspan.end(). However,startSpanautomatically ends the span when the async callback returns (after the database operations complete), which happens before the setTimeout fires. This meansspan.end()is called on an already-ended span. The v5 test correctly usesSentry.startSpanManual()for this same pattern, which does not auto-end the span. While the test likely still passes because all database operations complete before the callback returns, this is inconsistent with the existing v5 test pattern and could cause confusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with our v6 tests.