Skip to content

feat(server-utils): Emit low cardinality mysql db span names - #23601

Open
Lms24 wants to merge 2 commits into
developfrom
lms/feat-server-utils-low-card-db-span-names2
Open

feat(server-utils): Emit low cardinality mysql db span names#23601
Lms24 wants to merge 2 commits into
developfrom
lms/feat-server-utils-low-card-db-span-names2

Conversation

@Lms24

@Lms24 Lms24 commented Aug 25, 2026

Copy link
Copy Markdown
Member

With span streaming enabled:

  • mysql and mysql2 query spans are named after db.query.summary
    • e.g. SELECT solution FROM maths becomes SELECT maths
  • falls back to db.namespace, then db.system.name
  • new db.query.summary attribute, set in both trace lifecycles

Refs #23523

[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db',
[DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_MYSQL,
[DB_QUERY_TEXT]: queryText,
[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.

MySQL escapes leak into summaries

Medium Severity

Summaries are built after _INTERNAL_sanitizeSqlQuery, which only treats doubled quotes ('') as escaped string delimiters. mysql2's query channel inlines values with MySQL backslash escapes (\'), so a literal that contains a quote plus FROM/JOIN is only partially stripped and can still land in db.query.summary and the streamed span name.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f7c6bc0. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

might be an issue but a broader one than this change. I wanna look into this separately.

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.58 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.6 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.51 kB - -
@sentry/browser (incl. Tracing, Replay) 88.06 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.46 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.47 kB - -
@sentry/browser (incl. Feedback) 45.81 kB - -
@sentry/browser (incl. sendFeedback) 33.36 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.79 kB - -
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.82 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.07 kB - -
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.95 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73 kB - -
CDN Bundle (incl. Tracing, Replay) 86.58 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.46 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.27 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.69 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.38 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.42 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.18 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.86 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.55 kB - -
@sentry/nextjs (client) 53.33 kB - -
@sentry/sveltekit (client) 49.03 kB - -
@sentry/core/server 65.19 kB - -
@sentry/core/browser 52.35 kB - -
@sentry/node 122.73 kB +0.08% +86 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.22 kB - -
@sentry/node - without tracing 87.95 kB +0.03% +21 B 🔺
@sentry/aws-serverless 96.14 kB +0.03% +27 B 🔺
@sentry/cloudflare (withSentry) - minified 199.5 kB - -
@sentry/cloudflare (withSentry) 495.46 kB - -

View base workflow run

With span streaming, `mysql` and `mysql2` query spans are named after their
`db.query.summary` (`SELECT users`) instead of the full SQL statement, and
report that summary as a new `db.query.summary` attribute. Both mysql2 paths
(the orchestrion channels below 3.20.0 and the native diagnostics channels from
3.20.0 on) are covered, so the name does not depend on the driver version.

The statement is sanitized before it is summarized, so a string literal
containing `from`/`join` cannot leak a value into the name.

`traceLifecycle: 'static'` keeps the existing names.

Refs #23523
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the lms/feat-server-utils-low-card-db-span-names2 branch from f7c6bc0 to 58cd60c Compare August 26, 2026 12:53

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 58cd60c. Configure here.

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 = sql ? _INTERNAL_getSqlQuerySummary(_INTERNAL_sanitizeSqlQuery(sql)) : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MySQL literals can leak into summaries

Medium Severity

_INTERNAL_sanitizeSqlQuery only strips single-quoted literals, but MySQL treats double-quoted values as strings unless ANSI_QUOTES is on, and also allows backslash escapes. A user value containing from or join can therefore survive sanitization and land in db.query.summary and streamed span names, which this change presents as low-cardinality and leak-free.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 58cd60c. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed in #23659

@Lms24
Lms24 marked this pull request as ready for review August 26, 2026 13:20
@Lms24
Lms24 requested review from a team as code owners August 26, 2026 13:20
@Lms24
Lms24 requested review from JPeer264 and isaacs and removed request for a team August 26, 2026 13:20
@Lms24 Lms24 self-assigned this Aug 26, 2026
@Lms24 Lms24 changed the title feat(server-utils)!: Emit low cardinality mysql db span names feat(server-utils): Emit low cardinality mysql db span names Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant