Skip to content

feat(server-utils)!: Emit low cardinality postgres db span names - #23600

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

feat(server-utils)!: Emit low cardinality postgres db span names#23600
Lms24 wants to merge 7 commits into
developfrom
lms/feat-server-utils-low-card-db-span-names1

Conversation

@Lms24

@Lms24 Lms24 commented Aug 25, 2026

Copy link
Copy Markdown
Member

This PR sets a low cardinality span name on postgres (pg and postgres.js) spans when span streaming is enabled.

Concrete changes:

  • Set the query summary as span name if a query is available. If not fall back to the db namespace or db system ("postgres")
    • Example: SELECT * FROM "User" WHERE id = $1 becomes SELECT "User"
  • added db.query.summary attribute
  • ensured that db and connection attributes are set as span start options
    • for this, I refactored _setOperationName to _getOperationName and _setConnectionAttributes to _getConnectionAttributes. Both are exported from Core so these are breaking changes but they're prefixed with _INTERNAL and we're only doing this for v11. So I think this should be fine. Marked the PR with a ! for correctness.
  • added node integration tests for streamed postgres.js spans (pg already has streaming tests)

Refs #23523

With span streaming, `pg` and `postgres.js` query spans are named after their
`db.query.summary` (`SELECT "User"`) instead of the full SQL statement, and
report that summary as a new `db.query.summary` attribute. 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>

@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 3 potential issues.

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 5f7d0d4. Configure here.

Comment thread packages/server-utils/src/integrations/postgres-js.ts Outdated
Comment thread packages/server-utils/src/integrations/postgres.ts
Comment thread packages/core/src/integrations/postgresjs.ts Outdated
@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.04 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.44 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.75 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.44 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) 72.98 kB - -
CDN Bundle (incl. Tracing, Replay) 86.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.25 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.36 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.12 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.79 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.48 kB - -
@sentry/nextjs (client) 53.33 kB - -
@sentry/sveltekit (client) 49.03 kB - -
@sentry/core/server 65.1 kB +0.04% +22 B 🔺
@sentry/core/browser 52.35 kB -0.06% -27 B 🔽
@sentry/node 122.29 kB +0.72% +870 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.19 kB - -
@sentry/node - without tracing 87.62 kB +0.03% +20 B 🔺
@sentry/aws-serverless 95.77 kB +0.03% +27 B 🔺
@sentry/cloudflare (withSentry) - minified 199.5 kB - -
@sentry/cloudflare (withSentry) 495.46 kB - -

View base workflow run

@Lms24
Lms24 marked this pull request as ready for review August 26, 2026 10:28
@Lms24
Lms24 requested review from a team as code owners August 26, 2026 10:28
@Lms24
Lms24 requested review from JPeer264 and isaacs and removed request for a team August 26, 2026 10:28
@Lms24 Lms24 self-assigned this Aug 26, 2026
Comment thread packages/core/src/integrations/postgresjs.ts Outdated

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice. LGTM

...getConnectionAttributes(params),
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[DB_QUERY_TEXT]: queryConfig?.text || undefined,
[DB_QUERY_SUMMARY]: querySummary,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice catch

@Lms24
Lms24 enabled auto-merge (squash) August 26, 2026 11:40
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.

2 participants