fix: don't adopt a foreign global OTel span as a Judgment parent - #769
Open
arthi-arumugam-git wants to merge 2 commits into
Open
fix: don't adopt a foreign global OTel span as a Judgment parent#769arthi-arumugam-git wants to merge 2 commits into
arthi-arumugam-git wants to merge 2 commits into
Conversation
JudgmentLabs#749 made get_current_context() read the global OTel context whenever this provider owns the global provider. That conflated two directions: - write: publish the active Judgment span to the global context so third-party instrumentation reading trace.get_current_span() sees it - read: decide what a new Judgment span should be parented to Only the write direction needs to be global. Reading parenting from the global context means any span a host application or unrelated instrumentation left current becomes the parent of the next Judgment span, which silently reroots it onto a foreign trace. Split them. get_current_context() now always reads Judgment's private runtime context. attach_context() writes to that context and, when we own the global provider, mirrors into the global context as well, returning both tokens so detach unwinds both. Adds a test that fails on main: with a foreign span current in the global context, a Judgment root span comes back with a parent and a trace_id belonging to the foreign trace.
Author
|
Gentle ping: this has been unchanged and ready for review for 8 days. Anything needed from my side to move it forward? |
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.
Picks up the regression from #749 that #751 and #752 were both aimed at. #752 has been open since 6 July, so this is an independent take on it with a failing test.
The problem
#749 made
get_current_context()read the global OTel context whenever this provider owns the global provider. That folded two different jobs into one method:trace.get_current_span()can see itOnly the write direction actually needs to be global. Reading parenting from the global context means whatever span a host application or unrelated instrumentation happens to have left current becomes the parent of the next Judgment span, which silently reroots it onto a foreign trace. Nothing errors, and the trace just shows up in the wrong tree with the wrong
trace_id.The change
Split the two directions.
get_current_context()always reads Judgment's private runtime context. Parenting never consults the global context.get_global_context()added for the cases that genuinely want the global view.attach_context()attaches to the private context and, when we own the global provider, mirrors the same context into the global one. It returns both tokens in a_ContextTokensodetach_context()can unwind both, global first.The write path is unchanged in effect, so the interop #749 was after still works.
Tests
TestForeignGlobalParentadds two.test_foreign_global_span_is_not_adopted_as_parentfails on main:A foreign SDK span is made current in the global context, a Judgment root span is started, and on main that root comes back with a parent and the foreign trace's
trace_id.test_judgment_children_still_parent_to_judgment_spansis the guard in the other direction, with the same foreign span current, a nested Judgment span still parents to its Judgment parent and stays on the same trace.The three existing
TestGlobalContextBridgetests pass unchanged, includingtest_active_span_visible_to_external_when_global, which is the behaviour #749 was protecting. Full file is 19 passed.Happy to adjust naming or fold this into #752 instead if you'd rather keep that one, I mostly wanted the failing test to exist somewhere.