Repository navigation
Trace control-plane requests and their database queries on Cloudflare - #289
Merged
Merged
Conversation
Automatic Workers tracing records fetch calls and bindings, but not PostgreSQL over Hyperdrive, because those queries use a TCP socket. The control plane now traces every pg connection and statement. The hook sits on the pooled pg client, so Drizzle, Better Auth and raw SQL all report through it without changes at their call sites. Spans carry the statement with its placeholders, never its values. Node installations keep the untraced client.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 3579f3a | Nov 22 2026, 12:42 PM |
A PostgreSQL error message can quote a parameter value, such as the text that failed an integer cast. Spans now record the SQLSTATE code, or the error's name when there is none. Tests cover a failed parameterized statement and a rejected connection.
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.
On Cloudflare, Workers Logs show a request's wall time and CPU time, but not where the rest goes. Automatic Workers tracing covers fetch calls and bindings. PostgreSQL over Hyperdrive uses a TCP socket, so its queries do not appear as spans.
Changes
wrangler.jsoncturns on Workers traces for the control plane. All requests are traced; Cloudflare documents no request overhead.createDatabaseaccepts a span function. The Cloudflare runtime passes one built ontracing.startSpan, and every pooled pg client then reports apostgres connectspan for its connection and apostgres queryspan for each statement. The hook sits on the pg client, so Drizzle, Better Auth and raw SQL all report through it without changes where they run queries. Spans carry the statement text with its placeholders (up to 500 characters), never parameter values. A failed connection or statement marks its span as an error and records its SQLSTATE code aserror.type, not the message, because PostgreSQL error messages can quote parameter values.Validation
pnpm checkdatabase-tracing.integration.test.ts, against Postgres: connection and query spans, includingbeginandcommit; SQLSTATE codes on a failed statement and on a rejected connection; no parameter values, even when PostgreSQL quotes one in its error message; every span ended.tracing.startSpan,setAttributes,setStatusandendrun in local workerd with the control plane's compatibility date.pnpm build:cloudflareandwrangler deploy --dry-runwith the traces setting.

Confidence Score: 5/5
The PR appears safe to merge; both previous findings are addressed.Summary
Adds Cloudflare traces for database connections and statements while leaving Node's database client unchanged.
Diagram
Reviews (2) · Last reviewed commit: "Record only the error type of a failed d..." · Reviewed by Greptile