Repository navigation
Trace SQL transaction control statements and connection wait - #10213
Merged
Merged
Conversation
Failing tests for EFF-3183 / #10203: control spans for BEGIN, SAVEPOINT, COMMIT, ROLLBACK, ROLLBACK TO SAVEPOINT and RELEASE SAVEPOINT under SpanPropagationEnabled, acquisition parented to sql.transaction, and db.client.connection.wait_time_ms on the transaction span.
With Statement.SpanPropagationEnabled, makeWithTransaction runs each transaction control in a client span under sql.transaction, parents connection acquisition to the transaction span, and records the transaction's connection wait time.
🦋 Changeset detectedLatest commit: f4a8b26 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.
|
Control spans replace the effect.sql.transaction.* events under normal tracing; only the connection wait time stays behind SpanPropagationEnabled.
…on events Control spans are traced like statements, without SpanPropagationEnabled, and replace the effect.sql.transaction.* events. The flag still governs connection wait time and driver span parenting.
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.
Closes #10203
Closes EFF-3183
Summary
SqlClient.withTransactionran BEGIN, COMMIT, ROLLBACK and the savepoint statements directly on the connection, so their time showed up only as unexplained time insql.transaction. Connection acquisition also ran withoutsql.transactionas its parent span.makeWithTransactionnow does the following. Because the change is inmakeWithTransaction, every driver that uses it gets this.kind: "client"span, explicitly parented to that level'ssql.transaction, just as every statement gets a client span.{operation} {target}, usingStatement.spanTarget. With no target the name is just{operation}; there is nosql.executefallback.BEGIN,SAVEPOINT,COMMIT,ROLLBACK,ROLLBACK TO SAVEPOINTandRELEASE SAVEPOINT.onCommitFailurealso appears asROLLBACK.spanAttributesplusdb.operation.name, and has nodb.query.text.Effect.orDieand the commit-failure recovery. A failed COMMIT therefore ends its own span with the failure, and transaction semantics don't change.effect.sql.transaction.commit,effect.sql.transaction.savepointandeffect.sql.transaction.rollbackevents onsql.transaction. Those events had no duration or status, and their timestamps match the start of the new spans. Anything that filters on them will no longer see them.SqlClientis@stability unstable.acquireConnectionalways runs withTracer.ParentSpan = sql.transaction. Drivers already gate their connect spans onStatement.SpanPropagationEnabled. With that flag on,PgPoolreports a cold transaction'sdb.connectunder the transaction instead of under whatever outer span was current.Statement.SpanPropagationEnabledandTracerTimingEnabledon, a top-levelsql.transactionrecordsdb.client.connection.wait_time_msat connection hand-off, before BEGIN. The wait helper Statement already used moved tointernal/sql.tsso both modules share it.Known driver quirks, now visible under normal tracing and left as-is:
acquireConnection, so its BEGIN span is empty and its BEGIN time counts as connection wait.isTransactioncleanup skip produces an empty ROLLBACK span.onCommitFailureROLLBACK span always succeeds, because that ROLLBACK's error is ignored.Tests
packages/effect/test/sql/SqlClient.test.ts,makeWithTransaction›tracing:packages/sql/pg/test/PgPool.in-process.test.ts: a cold transaction under an outer span reportsdb.connect,BEGIN appandCOMMIT appundersql.transaction.Validation
pnpm test --runonpackages/effect/test/sql/(78 passed) andPgPool.in-process.test.ts(11 passed).pnpm lint,pnpm checkandpnpm jsdocs --checkare clean.