-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): Add pg
auto instrumentation test for @sentry/node-experimental
#10347
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
AbhiPrasad
merged 2 commits into
getsentry:develop
from
timfish:test/postgres-tracing-experimental
Jan 25, 2024
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
13 changes: 13 additions & 0 deletions
13
dev-packages/node-integration-tests/suites/tracing-experimental/postgres/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-postgres | ||
ports: | ||
- '5444:5432' | ||
environment: | ||
POSTGRES_USER: test | ||
POSTGRES_PASSWORD: test | ||
POSTGRES_DB: tests |
46 changes: 46 additions & 0 deletions
46
dev-packages/node-integration-tests/suites/tracing-experimental/postgres/scenario.js
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 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node-experimental'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const { Client } = require('pg'); | ||
|
||
const client = new Client({ port: 5444, user: 'test', password: 'test', database: 'tests' }); | ||
|
||
async function run() { | ||
await Sentry.startSpan( | ||
{ | ||
name: 'Test Transaction', | ||
op: 'transaction', | ||
}, | ||
async () => { | ||
try { | ||
await client.connect(); | ||
|
||
await client | ||
.query( | ||
'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"));', | ||
) | ||
.catch(() => { | ||
// if this is not a fresh database, the table might already exist | ||
}); | ||
|
||
await client.query('INSERT INTO "User" ("email", "name") VALUES ($1, $2)', ['tim', '[email protected]']); | ||
await client.query('SELECT * FROM "User"'); | ||
} finally { | ||
await client.end(); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(); |
54 changes: 54 additions & 0 deletions
54
dev-packages/node-integration-tests/suites/tracing-experimental/postgres/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,54 @@ | ||
import { conditionalTest } from '../../../utils'; | ||
import { createRunner } from '../../../utils/runner'; | ||
|
||
conditionalTest({ min: 14 })('postgres auto instrumentation', () => { | ||
test('should auto-instrument `pg` package', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Transaction', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'db.system': 'postgresql', | ||
'db.name': 'tests', | ||
'sentry.origin': 'manual', | ||
'sentry.op': 'db', | ||
}), | ||
description: 'pg.connect', | ||
op: 'db', | ||
status: 'ok', | ||
}), | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'db.system': 'postgresql', | ||
'db.name': 'tests', | ||
'db.statement': 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)', | ||
'sentry.origin': 'auto.db.otel.postgres', | ||
'sentry.op': 'db', | ||
}), | ||
description: 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)', | ||
op: 'db', | ||
status: 'ok', | ||
origin: 'auto.db.otel.postgres', | ||
}), | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
'db.system': 'postgresql', | ||
'db.name': 'tests', | ||
'db.statement': 'SELECT * FROM "User"', | ||
'sentry.origin': 'auto.db.otel.postgres', | ||
'sentry.op': 'db', | ||
}), | ||
description: 'SELECT * FROM "User"', | ||
op: 'db', | ||
status: 'ok', | ||
origin: 'auto.db.otel.postgres', | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario.js') | ||
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port 5432'] }) | ||
.expect({ transaction: EXPECTED_TRANSACTION }) | ||
.start(done); | ||
}); | ||
}); |
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.
Check failure
Code scanning / CodeQL
Hard-coded credentials