feat(server-utils): Emit low cardinality mysql db span names - #23601
feat(server-utils): Emit low cardinality mysql db span names#23601Lms24 wants to merge 2 commits into
Conversation
| [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db', | ||
| [DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_MYSQL, | ||
| [DB_QUERY_TEXT]: queryText, | ||
| [DB_QUERY_SUMMARY]: querySummary, |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit f7c6bc0. Configure here.
There was a problem hiding this comment.
might be an issue but a broader one than this change. I wanna look into this separately.
size-limit report 📦
|
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>
f7c6bc0 to
58cd60c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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; |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 58cd60c. Configure here.


With span streaming enabled:
mysqlandmysql2query spans are named afterdb.query.summarySELECT solution FROM mathsbecomesSELECT mathsdb.namespace, thendb.system.namedb.query.summaryattribute, set in both trace lifecyclesRefs #23523