fix(db): propagate transaction context into RunInTx callback#1368
Closed
valerijhegaj wants to merge 1 commit into
Closed
fix(db): propagate transaction context into RunInTx callback#1368valerijhegaj wants to merge 1 commit into
valerijhegaj wants to merge 1 commit into
Conversation
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this pr will be closed. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions! |
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.
fix: #1367
Summary
RunInTxwas passing the originalctxinto the callback instead of the transaction context (tx.ctx). This breaks context propagation for anything initialized duringBeginTx.Details
In Bun, OpenTelemetry instrumentation is typically added via query hooks. Those hooks rely on the context to carry the active span.
During
BeginTx, Bun creates a wrapped context (tx.ctx) that includes the transaction span (BEGIN). However, the callback was invoked with the outerctx, so all queries inside the transaction were executed outside of that span.As a result:
queries inside the transaction are not children of the
BEGINspantrace structure is inconsistent (
COMMIT/ROLLBACKare correct, queries are not)Fix
Pass
tx.ctxinto the callback:fn(tx.ctx, tx)Applied to:
Conn.RunInTxDB.RunInTxTx.RunInTxResult
All queries inside a transaction now inherit the transaction span created at
BEGIN, producing a correct and consistent trace tree.