Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import {
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
DB_USER,
SENTRY_OP,
SENTRY_ORIGIN,
SERVER_ADDRESS,
SERVER_PORT,
} from '@sentry/conventions/attributes';
import { DB } from '@sentry/conventions/op';
import { describe, expect } from 'vitest';
import { createEsmAndCjsTests, describeWithDockerCompose } from '../../../../utils/runner';

Expand All @@ -9,93 +22,75 @@ describeWithDockerCompose('knex auto instrumentation', { workingDirectory: [__di
describe('with `mysql2` client', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('should auto-instrument `knex` package', { timeout: 60_000 }, async () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Transaction',
spans: expect.arrayContaining([
expect.objectContaining({
data: expect.objectContaining({
'knex.version': KNEX_VERSION,
'db.system.name': 'mysql2',
'db.namespace': 'tests',
'db.user': 'root',
'sentry.origin': ORIGIN,
'sentry.op': 'db',
'server.address': 'localhost',
'server.port': 3307,
}),
status: 'ok',
description:
'create table `User` (`id` int unsigned not null auto_increment primary key, `createdAt` timestamp(?) not null default CURRENT_TIMESTAMP(?), `email` text not null, `name` text not null)',
origin: ORIGIN,
const EXPECTED_SPANS = [
expect.objectContaining({
attributes: expect.objectContaining({
'knex.version': { type: 'string', value: KNEX_VERSION },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mysql2' },
[DB_NAMESPACE]: { type: 'string', value: 'tests' },
[DB_USER]: { type: 'string', value: 'root' },
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[SERVER_ADDRESS]: { type: 'string', value: 'localhost' },
[SERVER_PORT]: { type: 'integer', value: 3307 },
[DB_QUERY_TEXT]: {
type: 'string',
value:
'create table `User` (`id` int unsigned not null auto_increment primary key, `createdAt` timestamp(?) not null default CURRENT_TIMESTAMP(?), `email` text not null, `name` text not null)',
},
[DB_QUERY_SUMMARY]: { type: 'string', value: 'create table `User`' },
}),
expect.objectContaining({
data: expect.objectContaining({
'knex.version': KNEX_VERSION,
'db.system.name': 'mysql2',
'db.namespace': 'tests',
'db.user': 'root',
'sentry.origin': ORIGIN,
'sentry.op': 'db',
'server.address': 'localhost',
'server.port': 3307,
}),
status: 'ok',
description: 'insert into `User` (`email`, `name`) values (?, ?)',
origin: ORIGIN,
status: 'ok',
name: 'create table `User`',
}),
expect.objectContaining({
attributes: expect.objectContaining({
'knex.version': { type: 'string', value: KNEX_VERSION },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mysql2' },
[DB_NAMESPACE]: { type: 'string', value: 'tests' },
[DB_USER]: { type: 'string', value: 'root' },
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[SERVER_ADDRESS]: { type: 'string', value: 'localhost' },
[SERVER_PORT]: { type: 'integer', value: 3307 },
[DB_QUERY_TEXT]: { type: 'string', value: 'insert into `User` (`email`, `name`) values (?, ?)' },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'insert `User`' },
}),
status: 'ok',
name: 'insert `User`',
}),

expect.objectContaining({
data: expect.objectContaining({
'knex.version': KNEX_VERSION,
'db.operation.name': 'select',
'db.sql.table': 'User',
'db.system.name': 'mysql2',
'db.namespace': 'tests',
'db.query.text': 'select * from `User`',
'db.user': 'root',
'sentry.origin': ORIGIN,
'sentry.op': 'db',
}),
status: 'ok',
description: 'select * from `User`',
origin: ORIGIN,
expect.objectContaining({
attributes: expect.objectContaining({
'knex.version': { type: 'string', value: KNEX_VERSION },
[DB_OPERATION_NAME]: { type: 'string', value: 'select' },
'db.sql.table': { type: 'string', value: 'User' },
[DB_SYSTEM_NAME]: { type: 'string', value: 'mysql2' },
[DB_NAMESPACE]: { type: 'string', value: 'tests' },
[DB_QUERY_TEXT]: { type: 'string', value: 'select * from `User`' },
[DB_USER]: { type: 'string', value: 'root' },
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'select `User`' },
}),
]),
};

await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed();
});
});
status: 'ok',
name: 'select `User`',
}),
expect.objectContaining({
attributes: expect.objectContaining({
[DB_QUERY_TEXT]: { type: 'string', value: 'drop table `User`' },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'drop table `User`' },
}),
name: 'drop table `User`',
}),
];

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-span-streaming.mjs', (createRunner, test) => {
test('should name spans after the query summary with span streaming', { timeout: 60_000 }, async () => {
await createRunner()
.expect({
span: container => {
// The `mysql2` driver spans underneath the knex spans come from a different integration and
// are named after the full statement, so they are filtered out here.
const knexSpans = container.items.filter(item => item.attributes['sentry.origin']?.value === ORIGIN);

expect(
knexSpans.map(span => ({
name: span.name,
summary: span.attributes['db.query.summary']?.value,
text: span.attributes['db.query.text']?.value,
})),
).toEqual([
{
name: 'create table `User`',
summary: 'create table `User`',
text: 'create table `User` (`id` int unsigned not null auto_increment primary key, `createdAt` timestamp(?) not null default CURRENT_TIMESTAMP(?), `email` text not null, `name` text not null)',
},
{
name: 'insert `User`',
summary: 'insert `User`',
text: 'insert into `User` (`email`, `name`) values (?, ?)',
},
{ name: 'select `User`', summary: 'select `User`', text: 'select * from `User`' },
{ name: 'drop table `User`', summary: 'drop table `User`', text: 'drop table `User`' },
]);
expect(container.items.find(span => span.is_segment)?.name).toBe('Test Transaction');
const knexSpans = container.items.filter(span => span.attributes[SENTRY_ORIGIN]?.value === ORIGIN);
expect(knexSpans).toEqual(EXPECTED_SPANS);
},
})
.start()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Loading
Loading