Skip to content
Draft
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
20 changes: 19 additions & 1 deletion packages/nuxt/src/runtime/utils/instrumentDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {
_INTERNAL_getSqlQuerySummary,
_INTERNAL_sanitizeSqlQuery,
addBreadcrumb,
captureException,
DB_SPAN_NAME_FALLBACK,
debug,
flushIfServerless,
getClient,
hasSpanStreamingEnabled,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
type Span,
Expand Down Expand Up @@ -220,10 +225,23 @@ function createBreadcrumb(query: string): void {
* Creates a start span options object.
*/
function createStartSpanOptions(query: string, data: DatabaseSpanData): StartSpanOptions {
const client = getClient();
// The statement is sanitized before it is summarized, so that a string literal containing
// `from`/`join` can't leak a value into the summary.
const querySummary = query ? _INTERNAL_getSqlQuerySummary(_INTERNAL_sanitizeSqlQuery(query)) : undefined;
// With span streaming, span names have to be low cardinality, so `{db.query.summary}` is used
// instead of the full statement, falling back to `{db.namespace}` when there is no statement to
// summarize.
const streamedName =
client && hasSpanStreamingEnabled(client)
? querySummary || (data['db.namespace'] as string | undefined) || DB_SPAN_NAME_FALLBACK
: undefined;

return {
name: query,
name: streamedName ?? query,
attributes: {
'db.query.text': query,
'db.query.summary': querySummary,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests for new behavior

Medium Severity

This feat PR changes streamed db.query span names and always sets db.query.summary, but the diff adds no integration or E2E coverage for that behavior. Existing Nuxt DB E2E suites stay on traceLifecycle: 'static' and never assert db.query.summary, so the new path is untested.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 8524d24. Configure here.

[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: SENTRY_ORIGIN,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.query',
...data,
Expand Down
Loading