-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(tracing): Add Prisma ORM integration tests. #4962
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
packages/node-integration-tests/suites/tracing/prisma-orm/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 | ||
ports: | ||
- '5433:5432' | ||
environment: | ||
POSTGRES_USER: prisma | ||
POSTGRES_PASSWORD: prisma | ||
POSTGRES_DB: tests |
22 changes: 22 additions & 0 deletions
22
packages/node-integration-tests/suites/tracing/prisma-orm/package.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,22 @@ | ||
{ | ||
"name": "sentry-prisma-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"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": "3.12.0", | ||
"prisma": "^3.12.0" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/node-integration-tests/suites/tracing/prisma-orm/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
...e-integration-tests/suites/tracing/prisma-orm/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
packages/node-integration-tests/suites/tracing/prisma-orm/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 { | ||
url = "postgresql://prisma:prisma@localhost:5433/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? | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/node-integration-tests/suites/tracing/prisma-orm/scenario.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,48 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import { PrismaClient } from '@prisma/client'; | ||
import * as Sentry from '@sentry/node'; | ||
import * as Tracing from '@sentry/tracing'; | ||
import { randomBytes } from 'crypto'; | ||
|
||
const client = new PrismaClient(); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
integrations: [new Tracing.Integrations.Prisma({ client })], | ||
}); | ||
|
||
async function run(): Promise<void> { | ||
const transaction = Sentry.startTransaction({ | ||
name: 'Test Transaction', | ||
op: 'transaction', | ||
}); | ||
|
||
Sentry.configureScope(scope => { | ||
scope.setSpan(transaction); | ||
}); | ||
|
||
try { | ||
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', | ||
}, | ||
}, | ||
}); | ||
} finally { | ||
if (transaction) transaction.finish(); | ||
} | ||
} | ||
|
||
void run(); |
16 changes: 16 additions & 0 deletions
16
packages/node-integration-tests/suites/tracing/prisma-orm/setup.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,16 @@ | ||
import { parseSemver } from '@sentry/utils'; | ||
import { execSync } from 'child_process'; | ||
|
||
const NODE_VERSION = parseSemver(process.versions.node); | ||
|
||
if (NODE_VERSION.major && NODE_VERSION.major < 12) { | ||
// 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
packages/node-integration-tests/suites/tracing/prisma-orm/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,17 @@ | ||
import { assertSentryTransaction, conditionalTest, getEnvelopeRequest, runServer } from '../../../utils'; | ||
|
||
conditionalTest({ min: 12 })('Prisma ORM Integration', () => { | ||
test('should instrument Prisma client for tracing.', async () => { | ||
const url = await runServer(__dirname); | ||
const envelope = await getEnvelopeRequest(url); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'Test Transaction', | ||
spans: [ | ||
{ description: 'User create', op: 'db.prisma' }, | ||
{ description: 'User findMany', op: 'db.prisma' }, | ||
{ description: 'User deleteMany', op: 'db.prisma' }, | ||
], | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/node-integration-tests/suites/tracing/prisma-orm/yarn.lock
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,27 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@prisma/[email protected]": | ||
version "3.12.0" | ||
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.12.0.tgz#a0eb49ffea5c128dd11dffb896d7139a60073d12" | ||
integrity sha512-4NEQjUcWja/NVBvfuDFscWSk1/rXg3+wj+TSkqXCb1tKlx/bsUE00rxsvOvGg7VZ6lw1JFpGkwjwmsOIc4zvQw== | ||
dependencies: | ||
"@prisma/engines-version" "3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980" | ||
|
||
"@prisma/engines-version@3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980": | ||
version "3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980" | ||
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980.tgz#829ca3d9d0d92555f44644606d4edfd45b2f5886" | ||
integrity sha512-o+jo8d7ZEiVpcpNWUDh3fj2uPQpBxl79XE9ih9nkogJbhw6P33274SHnqheedZ7PyvPIK/mvU8MLNYgetgXPYw== | ||
|
||
"@prisma/[email protected]": | ||
version "3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980" | ||
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980.tgz#e52e364084c4d05278f62768047b788665e64a45" | ||
integrity sha512-zULjkN8yhzS7B3yeEz4aIym4E2w1ChrV12i14pht3ePFufvsAvBSoZ+tuXMvfSoNTgBS5E4bolRzLbMmbwkkMQ== | ||
|
||
prisma@^3.12.0: | ||
version "3.12.0" | ||
resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.12.0.tgz#9675e0e72407122759d3eadcb6d27cdccd3497bd" | ||
integrity sha512-ltCMZAx1i0i9xuPM692Srj8McC665h6E5RqJom999sjtVSccHSD8Z+HSdBN2183h9PJKvC5dapkn78dd0NWMBg== | ||
dependencies: | ||
"@prisma/engines" "3.12.0-37.22b822189f46ef0dc5c5b503368d1bee01213980" |
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
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.
Doesn't this
ts-ignore
mean that this will happen to any user? That kinda feels like bad UX. Could we change the client type to somethingunknown
, validate it as aPrismaClient
and throw an error if it isn't?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.
Yes, that's right, updated 👍