diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument-span-streaming.mjs b/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument-span-streaming.mjs deleted file mode 100644 index 53b9511a21f0..000000000000 --- a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument-span-streaming.mjs +++ /dev/null @@ -1,10 +0,0 @@ -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, - traceLifecycle: 'stream', -}); diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument.mjs b/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument.mjs index 170ad6f6a702..46a27dd03b74 100644 --- a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/instrument.mjs @@ -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, diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/test.ts b/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/test.ts index 98cb1127906b..ec3947f54f4a 100644 --- a/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/knex/mysql2/test.ts @@ -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'; @@ -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() diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument-span-streaming.mjs b/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument-span-streaming.mjs deleted file mode 100644 index 53b9511a21f0..000000000000 --- a/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument-span-streaming.mjs +++ /dev/null @@ -1,10 +0,0 @@ -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, - traceLifecycle: 'stream', -}); diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument.mjs b/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument.mjs index 170ad6f6a702..46a27dd03b74 100644 --- a/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/knex/pg/instrument.mjs @@ -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, diff --git a/dev-packages/node-integration-tests/suites/tracing/knex/pg/test.ts b/dev-packages/node-integration-tests/suites/tracing/knex/pg/test.ts index 5d1da5ad89ff..ae9ea260eab4 100644 --- a/dev-packages/node-integration-tests/suites/tracing/knex/pg/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/knex/pg/test.ts @@ -1,3 +1,15 @@ +import { + DB_NAMESPACE, + DB_OPERATION_NAME, + DB_QUERY_SUMMARY, + DB_QUERY_TEXT, + DB_SYSTEM_NAME, + 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'; @@ -9,112 +21,89 @@ describe('knex auto instrumentation', () => { describeWithDockerCompose('with `pg` client', { workingDirectory: [__dirname] }, () => { 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': 'postgresql', - 'db.namespace': 'tests', - 'sentry.origin': ORIGIN, - 'sentry.op': 'db', - 'server.address': 'localhost', - 'server.port': 5445, - }), - status: 'ok', - description: - 'create table "User" ("id" serial primary key, "createdAt" timestamptz(?) 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: 'postgresql' }, + [DB_NAMESPACE]: { type: 'string', value: 'tests' }, + [SENTRY_ORIGIN]: { type: 'string', value: ORIGIN }, + [SENTRY_OP]: { type: 'string', value: DB }, + [SERVER_ADDRESS]: { type: 'string', value: 'localhost' }, + [SERVER_PORT]: { type: 'integer', value: 5445 }, + [DB_QUERY_TEXT]: { + type: 'string', + value: + 'create table "User" ("id" serial primary key, "createdAt" timestamptz(?) 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': 'postgresql', - 'db.namespace': 'tests', - 'sentry.origin': ORIGIN, - 'sentry.op': 'db', - 'server.address': 'localhost', - 'server.port': 5445, - }), - status: 'ok', - // In the knex-otel spans, the placeholders (e.g., `$1`) are replaced by a `?`. - 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: 'postgresql' }, + [DB_NAMESPACE]: { type: 'string', value: 'tests' }, + [SENTRY_ORIGIN]: { type: 'string', value: ORIGIN }, + [SENTRY_OP]: { type: 'string', value: DB }, + [SERVER_ADDRESS]: { type: 'string', value: 'localhost' }, + [SERVER_PORT]: { type: 'integer', value: 5445 }, + [DB_QUERY_TEXT]: { type: 'string', value: 'insert into "User" ("email", "name") values (?, ?)' }, + [DB_QUERY_SUMMARY]: { type: 'string', value: 'insert "User"' }, }), + status: 'ok', + // In the knex-otel spans, the placeholders (e.g., `$1`) are replaced by a `?`. + name: 'insert "User"', + }), - expect.objectContaining({ - data: expect.objectContaining({ - 'knex.version': KNEX_VERSION, - 'db.operation.name': 'select', - 'db.sql.table': 'User', - 'db.system.name': 'postgresql', - 'db.namespace': 'tests', - 'db.query.text': 'select * from "User"', - '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: 'postgresql' }, + [DB_NAMESPACE]: { type: 'string', value: 'tests' }, + [DB_QUERY_TEXT]: { type: 'string', value: 'select * from "User"' }, + [SENTRY_ORIGIN]: { type: 'string', value: ORIGIN }, + [SENTRY_OP]: { type: 'string', value: DB }, + [DB_QUERY_SUMMARY]: { type: 'string', value: 'select "User"' }, }), + status: 'ok', + name: 'select "User"', + }), - expect.objectContaining({ - data: expect.objectContaining({ - 'knex.version': KNEX_VERSION, - 'db.operation.name': 'select', - 'db.sql.table': 'DoesNotExist', - 'db.system.name': 'postgresql', - 'db.namespace': 'tests', - 'db.query.text': 'select * from "DoesNotExist"', - 'sentry.origin': ORIGIN, - 'sentry.op': 'db', - }), - status: 'internal_error', - description: 'select * from "DoesNotExist"', - 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: 'DoesNotExist' }, + [DB_SYSTEM_NAME]: { type: 'string', value: 'postgresql' }, + [DB_NAMESPACE]: { type: 'string', value: 'tests' }, + [DB_QUERY_TEXT]: { type: 'string', value: 'select * from "DoesNotExist"' }, + [SENTRY_ORIGIN]: { type: 'string', value: ORIGIN }, + [SENTRY_OP]: { type: 'string', value: DB }, + [DB_QUERY_SUMMARY]: { type: 'string', value: 'select "DoesNotExist"' }, }), - ]), - }; - - await createRunner().expect({ transaction: EXPECTED_TRANSACTION }).start().completed(); - }); - }); + status: 'error', + name: 'select "DoesNotExist"', + }), + 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 `pg` 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" serial primary key, "createdAt" timestamptz(?) 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: 'select "DoesNotExist"', - summary: 'select "DoesNotExist"', - text: 'select * from "DoesNotExist"', - }, - { 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()