Repository navigation
Trace SQL connection wait and sql-pg connects - #8676
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
🦋 Changeset detectedLatest commit: e234abb The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # packages/effect/src/sql/Statement.ts
Main now names statement spans after the database target, so `sql.execute` is only the fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GjpNuHbLUDNrwZAtpmvbMS
# Conflicts: # packages/effect/test/sql/Statement.test.ts # packages/sql/pg/src/PgPool.ts # packages/sql/pg/test/PgPool.in-process.test.ts
Track pending connects in a WeakMap keyed by session instead of a counter, so sessions closed before their first checkout no longer keep every later checkout on the reporting path. Apply hand-off reporting once around main's checkout, drop the pool.name attribute, and skip the wait-time wrapper when span timing is disabled.
Without timing the statement span starts at 0, so a connect span would mix real timestamps with an untimed parent and report sessions that were ready before the statement.
This branch had an error being deployed
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.
A slow
sql.executespan gives no reason for its duration when the statement spent it waiting for a connection, or waiting for a new PostgreSQL session to connect. On serverless Postgres a connect can take hundreds of milliseconds, or seconds when the compute wakes from scale to zero. This change makes both visible, so a trace shows whether the time went to the connection or to the query.SpanPropagationEnabledalready parents driver spans undersql.execute, and it gates everything below.effect/sqlStatement: with propagation on,sql.executerecordsdb.client.connection.wait_time_ms, from the span's start to the connection hand-off. This covers every Statement-based driver, on the acquirer, borrower and stream paths.@effect/sql-pgPgPool: the pool opens sessions on its own fiber, so a span around the connect has no statement parent. The pool records each session's connect start and end instead. On the session's first checkout, with propagation on, it reports adb.connectchild span under that statement, covering the part of the connect the statement waited for. A session that was ready before the statement started reports nothing. Sessions with an unreported connect sit in aWeakMapthat is checked at hand-off, so a session reports at most once and checkouts of reported sessions run the original code.Validated:
Statement.test.ts, onTestClock: acquired, borrowed and streamed statements record a 30 ms wait.PgPool.in-process.test.ts, onTestClockwith a held fake server: a first checkout throughuse,getandreservereports one 40 msdb.connect, and none with propagation or timing off. A session ready before the statement reports none.effectsql suites and every non-integrationsql-pgsuite pass (288 tests), stable over 10 runs.tsc -bforeffectandsql-pg, anddprint check.Follow-up idea:
effect/Poolcould expose acquire timing per item, which would movedb.connectout of the driver and coversql-mssqltoo.Closes EFF-2699