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
12 changes: 9 additions & 3 deletions packages/nuxt/src/runtime/hooks/wrapMiddlewareHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';
import {
SENTRY_SEGMENT_NAME_SOURCE,
SENTRY_OP,
SENTRY_ORIGIN,
HTTP_REQUEST_METHOD,
HTTP_ROUTE,
} from '@sentry/conventions/attributes';
import { MIDDLEWARE } from '@sentry/conventions/op';
import {
captureException,
Expand Down Expand Up @@ -183,11 +189,11 @@ function getSpanAttributes(
const path = event.path ?? eventH3v2?.url?.pathname;

if (method) {
attributes['http.request.method'] = method;
attributes[HTTP_REQUEST_METHOD] = method;
}

if (path) {
attributes['http.route'] = path;
attributes[HTTP_ROUTE] = path;
}

// h3 v1 (Nuxt 4): headers are on event.node.req.headers
Expand Down
11 changes: 6 additions & 5 deletions packages/nuxt/src/runtime/utils/database-span-data.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DB_NAMESPACE, SERVER_ADDRESS, SERVER_PORT } from '@sentry/conventions/attributes';
import type { ConnectorName } from 'db0';

export interface DatabaseSpanData {
Expand Down Expand Up @@ -27,27 +28,27 @@ export function getDatabaseSpanData(config?: DatabaseConnectionConfig): Partial<
if (!config?.connector) {
// Default to SQLite if no connector is configured
return {
'db.namespace': 'db.sqlite',
[DB_NAMESPACE]: 'db.sqlite',
};
}

if (config.connector === 'postgresql' || config.connector === 'mysql2') {
return {
'server.address': config.options?.host,
'server.port': config.options?.port,
[SERVER_ADDRESS]: config.options?.host,
[SERVER_PORT]: config.options?.port,
};
}

if (config.connector === 'pglite') {
return {
'db.namespace': config.options?.dataDir,
[DB_NAMESPACE]: config.options?.dataDir,
};
}

if ((['better-sqlite3', 'bun', 'sqlite', 'sqlite3'] as ConnectorName[]).includes(config.connector)) {
return {
// DB is the default file name in nitro for sqlite-like connectors
'db.namespace': `${config.options?.name ?? 'db'}.sqlite`,
[DB_NAMESPACE]: `${config.options?.name ?? 'db'}.sqlite`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/runtime/utils/instrumentDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function createBreadcrumb(query: string, dialect: SqlDialect | undefined): void
category: 'query',
message: queryText,
data: {
'db.query.text': queryText,
[DB_QUERY_TEXT]: queryText,
},
});
}
Expand Down
17 changes: 13 additions & 4 deletions packages/nuxt/src/runtime/utils/instrumentStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { CACHE_HIT, CACHE_KEY, CACHE_OPERATION, SENTRY_OP, SENTRY_ORIGIN } from '@sentry/conventions/attributes';
import {
CACHE_HIT,
CACHE_KEY,
CACHE_OPERATION,
SENTRY_OP,
SENTRY_ORIGIN,
DB_COLLECTION_NAME,
DB_OPERATION_NAME,
DB_SYSTEM_NAME,
} from '@sentry/conventions/attributes';
import { CACHE_GET, CACHE_PUT, CACHE_REMOVE } from '@sentry/conventions/op';
import {
CACHE_OPERATION_NAMES,
Expand Down Expand Up @@ -240,9 +249,9 @@ function createSpanStartOptions(
[CACHE_OPERATION]: cacheOperationName,
[SENTRY_ORIGIN]: 'auto.cache.nuxt',
[CACHE_KEY]: keys.length > 1 ? keys : keys[0],
'db.operation.name': methodName,
'db.collection.name': mountBase.replace(/:$/, ''),
'db.system.name': driver.name ?? 'unknown',
[DB_OPERATION_NAME]: methodName,
[DB_COLLECTION_NAME]: mountBase.replace(/:$/, ''),
[DB_SYSTEM_NAME]: driver.name ?? 'unknown',
};

const client = getClient();
Expand Down
Loading