Skip to content

feat(server-utils): Record returned rows on pg and Neon query spans - #26666

Open
sentry-junior[bot] wants to merge 1 commit into
developfrom
feat/pg-returned-rows
Open

sentry-junior[bot] wants to merge 1 commit into
developfrom
feat/pg-returned-rows

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

What

pg query spans now set db.response.returned_rows (OTel semconv, development status). The value is the result's rowCount, or rows.length when rowCount isn't a number. It covers single results, multi-statement results (one per statement, summed), callback and promise queries, and streamed Query submittables, which report the result they end with. Nothing is set on errors or when no count is known.

Neon's WebSocket driver already goes through the pg query channel. The HTTP driver (neon()) uses its own http-query channel, so it gets the same attribute from the bare rows array, from a fullResults result, or from a transaction() batch (summed).

Why

Without a row count on DB spans you can't tell whether a slow statement read many rows or read a few badly.

Cursors and streams (pg-cursor, pg-query-stream) are skipped on purpose: they are read in batches and end with only the last batch's rowCount and rows. Against Postgres, a 25-row cursor read in batches of 10 ends with rowCount: 5.

Semantic note: pg exposes one count. For INSERT/UPDATE/DELETE without RETURNING, rowCount is the number of affected rows, so this reports that rather than 0. The Neon HTTP driver without fullResults only gets the rows array, so the same INSERT reports 0 there. DDL reports 0.

via @BYK.

--

View Session [Sentry]

Set db.response.returned_rows on pg query spans from the result's rowCount,
falling back to rows.length. Multi-statement results are summed, streamed
Query submittables report the result they end with, and cursors set nothing
because they end with only the last batch. The Neon HTTP driver gets the
same attribute from its rows array or fullResults result.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 31786a6 (PR test merge using develop at 1884708)

Against: 1884708 (develop) · base run #67147

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.23 kB - -
@sentry/browser - with treeshaking flags 28.43 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.33 kB - -
@sentry/browser (incl. Tracing) 52.79 kB - -
@sentry/browser (incl. Tracing Core) 40.32 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.8 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.68 kB - -
@sentry/browser (incl. Tracing, Replay) 92.84 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.66 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.22 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.76 kB - -
@sentry/browser (incl. Feedback) 48.17 kB - -
@sentry/browser (incl. sendFeedback) 30.81 kB - -
@sentry/browser (incl. FeedbackAsync) 35.84 kB - -
@sentry/browser (incl. Metrics) 31.55 kB - -
@sentry/browser (incl. Logs) 31.83 kB - -
@sentry/browser (incl. Metrics & Logs) 32.49 kB - -
@sentry/react 32.24 kB - -
@sentry/react (incl. Tracing) 55.44 kB - -
@sentry/vue 38.44 kB - -
@sentry/vue (incl. Tracing) 55.74 kB - -
@sentry/svelte 30.24 kB - -
@sentry/remix (Remix 3 client bundle) 58.45 kB - -
CDN Bundle 32.16 kB - -
CDN Bundle (incl. Tracing) 53.18 kB - -
CDN Bundle (incl. Logs, Metrics) 34.95 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.74 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.98 kB - -
CDN Bundle (incl. Tracing, Replay) 91.06 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.47 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.03 kB - -
CDN Bundle - uncompressed 93.91 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.23 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 102.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 164.86 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.36 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 277.39 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.02 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.94 kB - -
@sentry/nextjs (client) 59.13 kB - -
@sentry/sveltekit (client) 54.06 kB - -
@sentry/core/server 45.26 kB - -
@sentry/core/browser 14.4 kB - -
@sentry/node 153.96 kB +0.16% +231 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.34 kB - -
@sentry/node - without tracing 88.8 kB +0.01% +1 B 🔺
@sentry/node - without channel injection 142.94 kB +0.17% +242 B 🔺
@sentry/aws-serverless 99.39 kB -0.01% -4 B 🔽
@sentry/cloudflare (withSentry) - minified 208.33 kB - -
@sentry/cloudflare (withSentry) 483.46 kB - -
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 1.01 MB - -
@sentry/nextjs/cloudflare (withSentry) - minified 233.7 kB - -

View base workflow run

@github-actions

Copy link
Copy Markdown
Contributor

Optional E2E tests

All optional checks were successful. 58 successful. See the run.

Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (bun) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E node-eve (0.x) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (deno) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7 (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14-supabase Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (cloudflare) Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry (static trace lifecycle) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel (cloudflare) Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 30s Details

BYK added a commit to getsentry/junior that referenced this pull request Nov 19, 2026
Pinned pnpm patch for `@sentry/server-utils@11.14.0` that backports
getsentry/sentry-javascript#26666. pg and Neon query spans now carry
`db.response.returned_rows`, so a slow statement shows whether it read
many rows.

The patch changes the built pg and Neon integrations (ESM and CJS):
- The count comes from the result's `rowCount`, falling back to
`rows.length`.
- Multi-statement results are summed.
- A streamed `Query` reports the result it ends with.
- Cursors and streams set nothing, because they end with only the last
batch's count.
- The Neon HTTP channel reads the rows array, the `fullResults` result,
or a `transaction()` batch.

Drop the patch and its `patchedDependencies` entry when Junior bumps to
an SDK release that includes getsentry/sentry-javascript#26666.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A825beff139610fd6deb1d4e59cf4fb79 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A825beff139610fd6deb1d4e59cf4fb79)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A825beff139610fd6deb1d4e59cf4fb79/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <126780+BYK@users.noreply.github.com>

@Lms24 Lms24 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.

Let's add the attribute to sentry conventions first please. Change looks good to me otherwise.

@sentry-junior

sentry-junior Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@Lms24 Added it to conventions in getsentry/sentry-conventions#826.

@sentry-junior
sentry-junior Bot requested a review from Lms24 November 20, 2026 09:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants