Skip to content

feat(core): Add db.query.summary functionality#21670

Merged
JPeer264 merged 4 commits into
developfrom
jp/query-summary
Jun 24, 2026
Merged

feat(core): Add db.query.summary functionality#21670
JPeer264 merged 4 commits into
developfrom
jp/query-summary

Conversation

@JPeer264

@JPeer264 JPeer264 commented Jun 20, 2026

Copy link
Copy Markdown
Member

By implementing #21656 I saw that db.query.summary is not implemented. I wanted to use the name in a low cardinality format, but there was no function for it. I therefore added the functionality for our postgres integration in order to have db.query.summary with a low cardinality format and also having the Span name in low cardinality.

We are adding almost 800bytes in source code, but on the good side is that we send less bytes over the wire, which is IMO already a big win and a great justification for the bytes (also they are living "only" on the server so it is less tragic).

The OpenTelemetry docs only had few examples on how it should be done. Therefore the tests from the Java OpenTelemetry instrumentation were taken and put into sql.ported.test.ts in order to verify our function works as well. Unfortunately there are some edge cases which do not work just yet, because we use a regex implementation and wouldn't work with regex.

I also checked if the regex has some performance issues, but they should all be good.

Related meme joke: https://programmerhumor.io/debugging-memes/the-plural-of-regex-is-regrets-jfzt

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.96 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.75 kB - -
@sentry/browser (incl. Tracing, Replay) 85.21 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.81 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.91 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.57 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.62 kB - -
@sentry/vue (incl. Tracing) 47.83 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.88 kB - -
CDN Bundle (incl. Tracing) 47.9 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB - -
CDN Bundle (incl. Tracing, Replay) 85.41 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.69 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.45 kB - -
CDN Bundle - uncompressed 88.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.02 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.62 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 267.99 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.68 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 76.32 kB - -
@sentry/core/browser 63.48 kB - -
@sentry/node-core 61.63 kB -0.01% -1 B 🔽
@sentry/node 123.61 kB -0.01% -1 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.55 kB - -
@sentry/node - without tracing 73.69 kB - -
@sentry/aws-serverless 84.89 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 175.71 kB - -
@sentry/cloudflare (withSentry) 437.11 kB - -

View base workflow run

@JPeer264 JPeer264 self-assigned this Jun 22, 2026
@JPeer264 JPeer264 marked this pull request as ready for review June 22, 2026 09:14
@JPeer264 JPeer264 requested a review from a team as a code owner June 22, 2026 09:14
@JPeer264 JPeer264 requested review from Lms24, andreiborza and mydea and removed request for a team June 22, 2026 09:14
Comment thread packages/core/src/integrations/postgresjs.ts Outdated
Comment thread packages/core/src/utils/sql.ts
Comment thread packages/core/test/lib/utils/sql.ported.test.ts Outdated
return startSpanManual(
{
name: sanitizedSqlQuery || 'postgresjs.query',
name: querySummary || sanitizedSqlQuery || 'postgresjs.query',

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.

cc @Lms24 this is what we want for span streaming, but I guess kind of breaking...? do we care...?

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.

Yeah, let's only add the attribute (this is a good thing IMO and can happen ASAP).

Let's hold off from making span name changes just yet. Talked about this with @cleptric when I worked on #21599. We'll very likely need to dynamcially decide what span name to set depending on span streaming enabled/disabled.

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.

Removed it from postgres. I still like to add this for #21656, though.

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

See https://github.com/getsentry/sentry-javascript/pull/21670/changes#r3465674147

(Sorry in case my comment on Monday about this attribute being useful for span names prompted you to make the span name adjustments, I should have worded this more carefully. It will be very useful once we make the name change :D)

Comment thread dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts Outdated
@JPeer264 JPeer264 changed the title feat(core): Add db.query.summary to postgres integration feat(core): Add db.query.summary functionality Jun 24, 2026
@JPeer264 JPeer264 requested a review from Lms24 June 24, 2026 08:48
if (subSelect?.[1]) {
parts.push(subSelect[1]);
const selectTables = extractTableNames(rest.slice(subSelect.index));
parts.push(...selectTables);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

INSERT misreads SELECT in strings

Medium Severity

For INSERT statements, the follow-up scan uses a word-boundary SELECT match on the remainder of the query after the target table. That can match SELECT inside quoted string literals in VALUES clauses, so plain INSERT ... VALUES (...) queries may be summarized like INSERT ... SELECT ... with extra tokens from extractTableNames, skewing db.query.summary cardinality.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e94685f. Configure here.

@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 34b5ca7. Configure here.

return selectMatch.groups['operation'];
}

return truncate(query.trim().split(/\s+/)[0] ?? query);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Whitespace-only query mishandled

Low Severity

getSqlQuerySummary returns undefined for '' but not for strings that contain only whitespace. Those inputs fall through to the fallback, which can yield a non-empty whitespace string instead of undefined, unlike the empty-string case.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 34b5ca7. Configure here.

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

Thanks!
Also RE byte size: that's fine from my PoV. 0.8kb in server environments is much less of an issue than in browser. Should we ever support browser-based DBs, we'd need to consider it but that's a thing to worry about later 😅

@JPeer264 JPeer264 enabled auto-merge (squash) June 24, 2026 10:47
@JPeer264 JPeer264 merged commit 583fdbd into develop Jun 24, 2026
824 of 828 checks passed
@JPeer264 JPeer264 deleted the jp/query-summary branch June 24, 2026 10:59
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.

3 participants