feat(tracing): add PostgreSQL tracing spans - #3678
Conversation
Trace logical database operations across the DB facade, search, audit, replica fencing, and command persistence without recording arguments or raw errors. Signed-off-by: David Grochowski <dgrochowski@squareup.com> Co-authored-by: Amp <amp@ampcode.com>
|
Some additional research on more detailed alternatives: Buzz PostgreSQL trace correlation optionsDecision being consideredBuzz currently has logical datastore spans around operations such as Two possible ways to add query-level visibility are:
These approaches solve related but different problems. Query spans describe Option 1: manually add a span around every queryResulting trace shapeEach query span would normally be a Bind values, community IDs, event IDs, user data, and other high-cardinality or Advantages
Disadvantages
Prior art
The strongest implementation would therefore not be literally manual. It would Option 2: add SQLCommenter propagation to SQLxResulting SQLFor a sampled query, SQLx would append the active W3C context: SELECT * FROM events WHERE community_id = $1 AND id = $2
/*traceparent='00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'*/PostgreSQL treats the suffix as a comment, but database logs, activity samples, Advantages
Disadvantages
Sampling behaviorSQL comments should only be injected when the active span context is valid and
This makes application-side sampling the relevant cost control. Collector-only Prior artPrisma Engines is the strongest Rust implementation. Its Rust query engine
That is substantially better than simply disabling persistence, but Prisma Direct comparison
Recommendation for BuzzDo not add either mechanism to the current PostgreSQL datastore-spans PR. The current logical spans provide useful operation-level latency with a small, If production traces show that logical operation timing is insufficient:
Consider SQLCommenter later only if all of the following are true:
In short: logical datastore spans now; SQLx slow-query events for diagnosis; References
|
Why
Expose PostgreSQL datastore latency within existing request traces so slow logical database operations can be identified without recording tenant data or query arguments.
What
buzz_datastoretarget anddb.system.name = "postgresql"for filtering and backend classificationRisk Assessment
Medium — this instruments frequently used datastore paths and increases trace volume when enabled, but does not change SQL execution or datastore behavior. Existing OpenTelemetry filtering controls export.
References
Generated with Amp