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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DB_CONNECTION_STRING,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
Expand Down Expand Up @@ -129,6 +130,7 @@ describe('mysql auto instrumentation', () => {
...COMMON_ATTRIBUTES,
[DB_QUERY_TEXT]: { type: 'string', value: queryText },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
},
...COMMON_SPAN_PROPS,
});
Expand Down
42 changes: 33 additions & 9 deletions dev-packages/node-integration-tests/suites/tracing/neon/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SerializedStreamedSpan } from '@sentry/core';
import {
DB_NAMESPACE,
DB_OPERATION_BATCH_SIZE,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
Expand Down Expand Up @@ -34,11 +35,13 @@ const CONNECTION_ATTRIBUTES = {

function expectedDbSpan({
name,
operation,
statement,
status = 'ok',
batchSize,
}: {
name: string;
operation: string;
statement: string;
status?: 'ok' | 'error';
batchSize?: number;
Expand All @@ -51,6 +54,7 @@ function expectedDbSpan({
[SENTRY_ORIGIN]: attr(ORIGIN),
[DB_QUERY_TEXT]: attr(statement),
[DB_QUERY_SUMMARY]: attr(name),
[DB_OPERATION_NAME]: attr(operation),
...(batchSize ? { [DB_OPERATION_BATCH_SIZE]: attr(batchSize, 'integer') } : {}),
}),
is_segment: false,
Expand Down Expand Up @@ -87,20 +91,30 @@ describeWithDockerCompose('neon auto instrumentation', { workingDirectory: [__di
const neonSpans = getNeonSpans(spans);
expect(neonSpans.every(span => span.parent_span_id === segment!.span_id)).toBe(true);
expect(neonSpans).toEqual([
expectedDbSpan({ name: 'CREATE TABLE "User"', statement: CREATE_USER_TABLE_STATEMENT }),
expectedDbSpan({ name: 'INSERT "User"', statement: 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)' }),
expectedDbSpan({ name: 'SELECT "User"', statement: 'SELECT * FROM "User" WHERE "name" = $1' }),
expectedDbSpan({ name: 'CREATE TABLE "User"', operation: 'CREATE', statement: CREATE_USER_TABLE_STATEMENT }),
expectedDbSpan({
name: 'INSERT "User"',
operation: 'INSERT',
statement: 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)',
}),
expectedDbSpan({
name: 'SELECT "User"',
operation: 'SELECT',
statement: 'SELECT * FROM "User" WHERE "name" = $1',
}),
expectedDbSpan({
name: 'SELECT "User"; SELECT "User"',
operation: 'BATCH SELECT',
statement: 'SELECT "email" FROM "User"; SELECT "name" FROM "User"',
batchSize: 2,
}),
expectedDbSpan({
name: 'SELECT "does_not_exist_table"',
operation: 'SELECT',
statement: 'SELECT * FROM "does_not_exist_table"',
status: 'error',
}),
expectedDbSpan({ name: 'DROP TABLE "User"', statement: 'DROP TABLE "User"' }),
expectedDbSpan({ name: 'DROP TABLE "User"', operation: 'DROP', statement: 'DROP TABLE "User"' }),
]);
});
});
Expand All @@ -121,15 +135,20 @@ describeWithDockerCompose('neon auto instrumentation', { workingDirectory: [__di
const neonSpans = getNeonSpans(spans);
expect(neonSpans.every(span => span.parent_span_id === segment!.span_id)).toBe(true);
expect(neonSpans).toEqual([
expectedDbSpan({ name: 'CREATE TABLE "User"', statement: CREATE_USER_TABLE_STATEMENT }),
expectedDbSpan({ name: 'INSERT "User"', statement: 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)' }),
expectedDbSpan({ name: 'SELECT "User"', statement: 'SELECT * FROM "User"' }),
expectedDbSpan({ name: 'CREATE TABLE "User"', operation: 'CREATE', statement: CREATE_USER_TABLE_STATEMENT }),
expectedDbSpan({
name: 'INSERT "User"',
operation: 'INSERT',
statement: 'INSERT INTO "User" ("email", "name") VALUES ($1, $2)',
}),
expectedDbSpan({ name: 'SELECT "User"', operation: 'SELECT', statement: 'SELECT * FROM "User"' }),
expectedDbSpan({
name: 'SELECT "does_not_exist_table"',
operation: 'SELECT',
statement: 'SELECT * FROM "does_not_exist_table"',
status: 'error',
}),
expectedDbSpan({ name: 'DROP TABLE "User"', statement: 'DROP TABLE "User"' }),
expectedDbSpan({ name: 'DROP TABLE "User"', operation: 'DROP', statement: 'DROP TABLE "User"' }),
]);
});
});
Expand All @@ -154,10 +173,15 @@ describeWithDockerCompose('neon auto instrumentation', { workingDirectory: [__di
expect(neonSpans).toEqual([
expectedDbSpan({
name: 'SELECT pg_catalog.pg_user',
operation: 'SELECT',
statement: 'SELECT "email", "name" FROM pg_catalog.pg_user LIMIT ?',
status: 'error',
}),
expectedDbSpan({ name: 'SELECT pg_catalog.pg_user', statement: 'SELECT "usename" FROM pg_catalog.pg_user' }),
expectedDbSpan({
name: 'SELECT pg_catalog.pg_user',
operation: 'SELECT',
statement: 'SELECT "usename" FROM pg_catalog.pg_user',
}),
]);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DB_CONNECTION_STRING,
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
Expand Down Expand Up @@ -87,6 +88,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'INSERT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'INSERT' },
},
name: 'INSERT "User"',
status: 'ok',
Expand All @@ -101,6 +103,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
},
name: 'SELECT "User"',
status: 'ok',
Expand All @@ -114,6 +117,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT "User"',
status: 'ok',
Expand All @@ -126,6 +130,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "does_not_exist_table"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT "does_not_exist_table"',
status: 'error',
Expand All @@ -144,6 +149,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
},
[DB_QUERY_SUMMARY]: { type: 'string', value: 'CREATE TABLE "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'CREATE' },
},
},
{
Expand All @@ -156,6 +162,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[DB_QUERY_TEXT]: { type: 'string', value: 'DROP TABLE "User"' },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'DROP TABLE "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'DROP' },
},
},
]),
Expand Down Expand Up @@ -218,6 +225,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'INSERT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'INSERT' },
},
name: 'INSERT "User"',
status: 'ok',
Expand All @@ -232,6 +240,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
},
name: 'SELECT "User"',
status: 'ok',
Expand All @@ -250,6 +259,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
'CREATE TABLE "User" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
},
[DB_QUERY_SUMMARY]: { type: 'string', value: 'CREATE TABLE "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'CREATE' },
},
},
{
Expand All @@ -262,6 +272,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[DB_QUERY_TEXT]: { type: 'string', value: 'DROP TABLE "User"' },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'DROP TABLE "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'DROP' },
},
},
]),
Expand Down Expand Up @@ -300,6 +311,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT',
status: 'ok',
Expand Down Expand Up @@ -359,6 +371,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT',
status: 'ok',
Expand Down Expand Up @@ -397,6 +410,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT',
status: 'ok',
Expand Down Expand Up @@ -444,6 +458,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'INSERT "NativeUser"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'INSERT' },
[SERVER_ADDRESS]: { type: 'string', value: '127.0.0.1' },
[DB_CONNECTION_STRING]: {
type: 'string',
Expand All @@ -463,6 +478,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "NativeUser"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
[SERVER_ADDRESS]: { type: 'string', value: '127.0.0.1' },
[DB_CONNECTION_STRING]: {
type: 'string',
Expand Down Expand Up @@ -490,6 +506,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
'CREATE TABLE "NativeUser" ("id" SERIAL NOT NULL,"createdAt" TIMESTAMP(?) NOT NULL DEFAULT CURRENT_TIMESTAMP,"email" TEXT NOT NULL,"name" TEXT,CONSTRAINT "User_pkey" PRIMARY KEY ("id"))',
},
[DB_QUERY_SUMMARY]: { type: 'string', value: 'CREATE TABLE "NativeUser"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'CREATE' },
},
},
{
Expand All @@ -506,6 +523,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: QUERY_ORIGIN },
[DB_QUERY_TEXT]: { type: 'string', value: 'DROP TABLE "NativeUser"' },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'DROP TABLE "NativeUser"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'DROP' },
},
},
]),
Expand Down Expand Up @@ -568,6 +586,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'INSERT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'INSERT' },
}),
name: 'INSERT "User"',
status: 'ok',
Expand All @@ -581,6 +600,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT "User"',
status: 'ok',
Expand All @@ -592,6 +612,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "does_not_exist_table"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT "does_not_exist_table"',
status: 'error',
Expand Down Expand Up @@ -629,6 +650,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT',
status: 'ok',
Expand Down Expand Up @@ -700,6 +722,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT',
status: 'ok',
Expand Down Expand Up @@ -747,6 +770,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'INSERT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'INSERT' },
}),
name: 'INSERT "User"',
status: 'ok',
Expand All @@ -759,6 +783,7 @@ describeWithDockerCompose('postgres auto instrumentation', { workingDirectory: [
[SENTRY_ORIGIN]: { type: 'string', value: ORIGIN },
[SENTRY_OP]: { type: 'string', value: DB },
[DB_QUERY_SUMMARY]: { type: 'string', value: 'SELECT "User"' },
[DB_OPERATION_NAME]: { type: 'string', value: 'SELECT' },
}),
name: 'SELECT "User"',
status: 'ok',
Expand Down
11 changes: 9 additions & 2 deletions packages/nuxt/src/runtime/utils/instrumentDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import { flushIfServerless } from '@sentry/core/server';
import { sanitizeSqlQuery, sanitizeSqlQueryWithSummary, type SqlDialect } from '@sentry/server-utils';
import type { Database, PreparedStatement } from 'db0';
import { type DatabaseConnectionConfig, type DatabaseSpanData, getDatabaseSpanData } from './database-span-data';
import { DB_NAMESPACE, DB_QUERY_SUMMARY, DB_QUERY_TEXT, DB_SYSTEM_NAME } from '@sentry/conventions/attributes';
import {
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
} from '@sentry/conventions/attributes';

type MaybeInstrumentedDatabase = Database & {
__sentry_instrumented__?: boolean;
Expand Down Expand Up @@ -261,7 +267,7 @@ function createStartSpanOptions(
data: DatabaseSpanData,
dialect: SqlDialect | undefined,
): StartSpanOptions {
const { queryText, querySummary } = sanitizeSqlQueryWithSummary(query, dialect);
const { queryText, querySummary, operationName } = sanitizeSqlQueryWithSummary(query, dialect);

const client = getClient();
const name =
Expand All @@ -274,6 +280,7 @@ function createStartSpanOptions(
attributes: {
[DB_QUERY_TEXT]: queryText,
[DB_QUERY_SUMMARY]: querySummary,
[DB_OPERATION_NAME]: operationName,
[SENTRY_ORIGIN]: NUXT_DATABASE_ORIGIN,
[SENTRY_OP]: DB_QUERY,
...data,
Expand Down
4 changes: 3 additions & 1 deletion packages/server-utils/src/integrations/mysql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as diagnosticsChannel from '../utils/diagnosticsChannel';
import {
DB_NAMESPACE,
DB_OPERATION_NAME,
DB_QUERY_SUMMARY,
DB_QUERY_TEXT,
DB_SYSTEM_NAME,
Expand Down Expand Up @@ -81,7 +82,7 @@ function instrumentMysql(): void {
// handler with the caller's context lost. `deferSpanEnd` replays this scope onto the emitter.
data._sentryCallerScope = getCurrentScope();

const { queryText, querySummary } = sanitizeSqlQueryWithSummary(sql, 'mysql');
const { queryText, querySummary, operationName } = sanitizeSqlQueryWithSummary(sql, 'mysql');

const client = getClient();
const name =
Expand All @@ -102,6 +103,7 @@ function instrumentMysql(): void {
[DB_USER]: user,
[DB_QUERY_TEXT]: queryText,
[DB_QUERY_SUMMARY]: querySummary,
[DB_OPERATION_NAME]: operationName,
[SERVER_ADDRESS]: host,
[SERVER_PORT]: portIsNumber ? portNumber : undefined,
},
Expand Down
Loading
Loading