Repository navigation
feat(sentry): N+1 hint in the trace, trace facet for mails and HTTP dumps - #492
Merged
Merged
Conversation
…umps
- GET /api/sentry/traces/{traceId} gets n_plus_one: database spans of one
transaction whose normalized query (literals, $N, IN/VALUES lists -> ?)
runs 5+ times; count, total ms from precise span times, origin, span ids.
- trace facet for SMTP (X-Trace-Id, sentry-trace, traceparent headers) and
HTTP dumps (sentry-trace/traceparent that SDKs add to outgoing calls), so
GET /api/events?trace=<id> returns them for the request timeline.
- Review notes from #491: ?bucket= above 366 days is a 400, NUL bytes are
dropped from ?q=, OpenAPI notes ASCII-only case folding for short words.
- Fixture: real sentry-laravel 4.31.0 transaction of an N+1 page.
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server part of the request timeline (concept 3 of the logs / queues / request-timeline set, option B: Sentry data plus logs, mails and HTTP calls linked by trace id). The Monolog
tracefacet came with #491.Change
GET /api/sentry/traces/{traceId}getsn_plus_one: database spans (peer_type = db) of one transaction whose query, normalized, runs 5 or more times. Most repeated first. Each group hastransaction_id,query,count,total_ms,origin,span_ids.$Nplaceholders →?;IN (…)andVALUES (…), (…)of any length → one?; whitespace collapsed.total_msis summed from span start/end times (two decimals): repeated queries usually take under 1 ms, andduration_msis whole milliseconds (it showed0 mslive).originiscode.filepath:code.linenoof the first span in the group that has one.tracefacet for mails and HTTP dumps, soGET /api/events?trace=<id>returns them for the timeline. Shared parserevent.TraceIDFromHeaders:sentry-trace, thentraceparent, thenX-Trace-Id; 32 hex, not all zero, lower-cased.sentry-trace/traceparentto outgoing calls themselves, so LaravelHttp::calls land on the timeline with no app setup.?bucket=above 366 days → 400 (was a 500 on overflow); NUL bytes dropped from?q=(was a 500); OpenAPI says case folding for words under 3 characters is ASCII only.n_plus_one,SentryNPlusOne,bucketmaximum.Facts for docs and UI
SENTRY_TRACE_SQL_ORIGIN_THRESHOLD_MS(100 ms by default). Live with0: direct queries gotroutes/web.php:256, but lazy-loaded relations ($post->comments()->count(),$post->user) got none: the SDK looks only 20 stack frames deep. So the typical N+1 usually comes without file and line; the hint still shows the query, count and time. Don't promise file:line.X-Trace-Id(orsentry-trace) with the current trace id, e.g. in Laravel$message->getHeaders()->addTextHeader('X-Trace-Id', (string) \Sentry\SentrySdk::getCurrentHub()->getSpan()?->getTraceId()).trace_idintoextraorcontext(from feat(logs): full-text search, per-minute histogram and trace facet #491).Tests
TestNormalizeSQL(MySQL backticks, Postgres$N, quoted strings with'', IN/VALUES lists, identifiers with digits),TestDetectNPlusOne(threshold, per transaction, origin with numeric and string line).TestTraceDetail_NPlusOne_Laravel: a real request from sentry-laravel 4.31.0 (fixturetestdata/sdk/laravel-n1, recorded from thebuggregator/examplesapp): two groups of 30,total_ms > 0, no origin.TestTraceIDFromHeaders, SMTP and HTTP-dump facet tests, histogram/qedge cases ininternal/server/http.go vet ./...clean;go test -count=1 ./...: 29 packages ok.Live check
Built binary,
buggregator/examples(Laravel 12 + sentry-laravel 4.31.0) in Docker,SENTRY_TRACE_SQL_ORIGIN_THRESHOLD_MS=0. Page/n1loops over 28 posts (author + comment count), logs through Monolog withtrace_id, sends a mail withX-Trace-Id, calls an http-dump URL withHttp::post.Not done here: an MCP tool for the trace (none exists yet); the timeline UI is the frontend item.
Made with harnsy