-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from 1 commit
9d229ad
671f472
ea74146
c0c84d8
b7b71a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { defineConfig } from 'prisma/config'; | ||
|
|
||
| export default defineConfig({ | ||
| earlyAccess: true, | ||
| schema: './prisma/schema.prisma', | ||
| migrate: { | ||
| migrations: './prisma/migrations', | ||
| }, | ||
| datasource: { | ||
| url: 'postgresql://prisma:prisma@localhost:5435/tests', | ||
| }, | ||
| }); |
| 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" |
| 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"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| datasource db { | ||
| provider = "postgresql" | ||
| } | ||
|
|
||
| generator client { | ||
| provider = "prisma-client-js" | ||
| } | ||
|
|
||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| createdAt DateTime @default(now()) | ||
| email String @unique | ||
| name String? | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { PrismaPg } from '@prisma/adapter-pg'; | ||
| import { PrismaClient } from '@prisma/client'; | ||
| import * as Sentry from '@sentry/node'; | ||
| import { randomBytes } from 'crypto'; | ||
|
|
||
| // 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); | ||
| }, | ||
| ); | ||
|
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. Wrong API used: span auto-ends before setTimeout firesLow Severity The v7 scenario uses
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 is consistent with our v6 tests. |
||
| } | ||
|
|
||
| run(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| describe('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: `yarn prisma generate --schema ${cwd}/prisma/schema.prisma && yarn prisma migrate dev -n sentry-test --schema ${cwd}/prisma/schema.prisma`, | ||
| }) | ||
| .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', | ||
| }, | ||
| copyPaths: ['prisma', 'prisma.config.ts', 'docker-compose.yml'], | ||
| }, | ||
| ); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
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.
Should we maybe use
"prisma-client"here? According to their blog post, this is now possible and rust-free: https://www.prisma.io/blog/announcing-prisma-orm-7-0-0And their migration guide: https://www.prisma.io/docs/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-7#prisma-schema-changes
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.
neat, will update.