-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node/v8): Add compatibility layer for Prisma v5 (#15210)
- Loading branch information
Showing
23 changed files
with
342 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v5/scenario.js
This file contains 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,52 @@ | ||
const Sentry = require('@sentry/node'); | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
integrations: [Sentry.prismaIntegration()], | ||
}); | ||
|
||
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(); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/docker-compose.yml
This file contains 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-v6 | ||
ports: | ||
- '5434:5432' | ||
environment: | ||
POSTGRES_USER: prisma | ||
POSTGRES_PASSWORD: prisma | ||
POSTGRES_DB: tests |
19 changes: 19 additions & 0 deletions
19
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/package.json
This file contains 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,19 @@ | ||
{ | ||
"name": "sentry-prisma-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"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": "5.22.0" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...node-integration-tests/suites/tracing/prisma-orm-v6/prisma/migrations/migration_lock.toml
This file contains 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-v6/prisma/migrations/sentry_test/migration.sql
This file contains 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-v6/prisma/schema.prisma
This file contains 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 { | ||
url = "postgresql://prisma:prisma@localhost:5434/tests" | ||
provider = "postgresql" | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
email String @unique | ||
name String? | ||
} |
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/setup.ts
This file contains 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,18 @@ | ||
import { execSync } from 'child_process'; | ||
import { parseSemver } from '@sentry/core'; | ||
|
||
const NODE_VERSION = parseSemver(process.versions.node); | ||
|
||
// Prisma v5 requires Node.js v16+ | ||
// https://www.prisma.io/docs/orm/more/upgrade-guides/upgrading-versions/upgrading-to-prisma-5#nodejs-minimum-version-change | ||
if (NODE_VERSION.major && NODE_VERSION.major < 16) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Skipping Prisma tests on Node: ${NODE_VERSION.major}`); | ||
process.exit(0); | ||
} | ||
|
||
try { | ||
execSync('yarn && yarn setup'); | ||
} catch (_) { | ||
process.exit(1); | ||
} |
17 changes: 17 additions & 0 deletions
17
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/test.ts
This file contains 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,17 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { createRunner } from '../../../utils/runner'; | ||
|
||
conditionalTest({ min: 16 })('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).toHaveLength(0); | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
dev-packages/node-integration-tests/suites/tracing/prisma-orm-v6/yarn.lock
This file contains 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,58 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@prisma/client@5.22.0": | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.22.0.tgz#da1ca9c133fbefe89e0da781c75e1c59da5f8802" | ||
integrity sha512-M0SVXfyHnQREBKxCgyo7sffrKttwE6R8PMq330MIUF0pTwjUhLbW84pFDlf06B27XyCR++VtjugEnIHdr07SVA== | ||
|
||
"@prisma/debug@5.22.0": | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.22.0.tgz#58af56ed7f6f313df9fb1042b6224d3174bbf412" | ||
integrity sha512-AUt44v3YJeggO2ZU5BkXI7M4hu9BF2zzH2iF2V5pyXT/lRTyWiElZ7It+bRH1EshoMRxHgpYg4VB6rCM+mG5jQ== | ||
|
||
"@prisma/engines-version@5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2": | ||
version "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" | ||
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2.tgz#d534dd7235c1ba5a23bacd5b92cc0ca3894c28f4" | ||
integrity sha512-2PTmxFR2yHW/eB3uqWtcgRcgAbG1rwG9ZriSvQw+nnb7c4uCr3RAcGMb6/zfE88SKlC1Nj2ziUvc96Z379mHgQ== | ||
|
||
"@prisma/engines@5.22.0": | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.22.0.tgz#28f3f52a2812c990a8b66eb93a0987816a5b6d84" | ||
integrity sha512-UNjfslWhAt06kVL3CjkuYpHAWSO6L4kDCVPegV6itt7nD1kSJavd3vhgAEhjglLJJKEdJ7oIqDJ+yHk6qO8gPA== | ||
dependencies: | ||
"@prisma/debug" "5.22.0" | ||
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" | ||
"@prisma/fetch-engine" "5.22.0" | ||
"@prisma/get-platform" "5.22.0" | ||
|
||
"@prisma/fetch-engine@5.22.0": | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.22.0.tgz#4fb691b483a450c5548aac2f837b267dd50ef52e" | ||
integrity sha512-bkrD/Mc2fSvkQBV5EpoFcZ87AvOgDxbG99488a5cexp5Ccny+UM6MAe/UFkUC0wLYD9+9befNOqGiIJhhq+HbA== | ||
dependencies: | ||
"@prisma/debug" "5.22.0" | ||
"@prisma/engines-version" "5.22.0-44.605197351a3c8bdd595af2d2a9bc3025bca48ea2" | ||
"@prisma/get-platform" "5.22.0" | ||
|
||
"@prisma/get-platform@5.22.0": | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.22.0.tgz#fc675bc9d12614ca2dade0506c9c4a77e7dddacd" | ||
integrity sha512-pHhpQdr1UPFpt+zFfnPazhulaZYCUqeIcPpJViYoq9R+D/yw4fjE+CtnsnKzPYm0ddUbeXUzjGVGIRVgPDCk4Q== | ||
dependencies: | ||
"@prisma/debug" "5.22.0" | ||
|
||
fsevents@2.3.3: | ||
version "2.3.3" | ||
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" | ||
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== | ||
|
||
prisma@5.22.0: | ||
version "5.22.0" | ||
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.22.0.tgz#1f6717ff487cdef5f5799cc1010459920e2e6197" | ||
integrity sha512-vtpjW3XuYCSnMsNVBjLMNkTj6OZbudcPPTPYHqX0CJfpcdWciI1dM8uHETwmDxxiqEwCIE6WvXucWUetJgfu/A== | ||
dependencies: | ||
"@prisma/engines" "5.22.0" | ||
optionalDependencies: | ||
fsevents "2.3.3" |
This file contains 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
41 changes: 41 additions & 0 deletions
41
packages/node/src/integrations/tracing/prisma/vendor/v5-tracing-helper.ts
This file contains 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,41 @@ | ||
// Vendored from https://github.com/prisma/prisma/blob/718358aa37975c18e5ea62f5b659fb47630b7609/packages/internals/src/tracing/types.ts#L1 | ||
|
||
import type { Context, Span, SpanOptions } from '@opentelemetry/api'; | ||
|
||
type V5SpanCallback<R> = (span?: Span, context?: Context) => R; | ||
|
||
type V5ExtendedSpanOptions = SpanOptions & { | ||
name: string; | ||
internal?: boolean; | ||
middleware?: boolean; | ||
active?: boolean; | ||
context?: Context; | ||
}; | ||
|
||
type EngineSpanEvent = { | ||
span: boolean; | ||
spans: V5EngineSpan[]; | ||
}; | ||
|
||
type V5EngineSpanKind = 'client' | 'internal'; | ||
|
||
type V5EngineSpan = { | ||
span: boolean; | ||
name: string; | ||
trace_id: string; | ||
span_id: string; | ||
parent_span_id: string; | ||
start_time: [number, number]; | ||
end_time: [number, number]; | ||
attributes?: Record<string, string>; | ||
links?: { trace_id: string; span_id: string }[]; | ||
kind: V5EngineSpanKind; | ||
}; | ||
|
||
export interface PrismaV5TracingHelper { | ||
isEnabled(): boolean; | ||
getTraceParent(context?: Context): string; | ||
createEngineSpan(engineSpanEvent: EngineSpanEvent): void; | ||
getActiveContext(): Context | undefined; | ||
runInChildSpan<R>(nameOrOptions: string | V5ExtendedSpanOptions, callback: V5SpanCallback<R>): R; | ||
} |
Oops, something went wrong.