Repository navigation
End the chain span when a link raises, and nest parallel storage spans under it - #233
Merged
Merged
Conversation
…s under it. A chain whose link raised never exited its vcon_processing span. The span stayed attached in the worker thread, so every chain that thread ran next became its child, and when garbage collection finally closed it, its status was unset. process() now holds the span in a with block. On failure the span records the exception, takes status ERROR, is detached and ended, and the exception reaches _handle_vcon, which moves the vCon to the DLQ as before. Parallel storage writes ran in pool threads, which start with an empty context, so each storage span began its own trace. Each write now runs in a copy of the caller's context and nests under the chain span. conserver/tests/test_chain_span_context.py covers the failed chain, the next chain in the same thread, the ERROR status, parallel storage, and the success path with its correlation attributes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ool threads. - The context stored for an egress list carries the chain span's trace and span ids. Moving the wrap-up outside the chain span makes it fail. - A KeyboardInterrupt or SystemExit from a link has ended and detached the chain span by the time it reaches the caller. The old manual enter and exit fails it. - The parallel storage test holds both writes in flight at once, so they run on two pool threads instead of one reused thread, and checks that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes three tracing defects in
conserver/main.py, seen in production traces.A failed chain's span stayed open.
process()entered thevcon_processing.<chain>span by hand and exited it only at the end of the success path. When a link raised, the span was never exited, so it stayed the current span in that worker thread. WithCONSERVER_VCON_CONCURRENCYabove 1, every later chain in the thread became its child: one trace collected several vCons' chains over many minutes, until the process restarted. The span ended only when garbage collection closed the abandoned context manager.That span ended with status unset. Only the failing
link.*span was ERROR, so a query on failed chains missed every vCon sent to the DLQ.Parallel storage spans were roots.
_process_storage_parallelruns each write in a thread pool, and pool threads start with an empty context, so eachstorage.*span began its own trace.Change
process()now holds the span in awithblock and runs the chain in_run_chain(), which is the old body unchanged. On failure the span records the exception, takes status ERROR, is detached and ended, and the exception reaches_handle_vcon, which moves the vCon to the DLQ as before.self._spanis still set for the correlation attributes. The success path still sets OK.contextvars.copy_context(), so its span nests under the chain span.Tests
New
conserver/tests/test_chain_span_context.py, with an in-memory span exporter and mocked Redis, queue, storage and links. It runs chains through_handle_vconin one pool thread, as a worker does. Each test, with its result before the fix and after it:test_failed_chain_detaches_and_ends_its_span_before_handle_vcon_returns: a chain whose link raises leaves no current span in the thread and has ended its chain span when_handle_vconreturns. Before:span 'vcon_processing.failing_chain' is still current in the worker thread. After: passes.test_next_chain_in_the_same_thread_gets_a_root_span_in_a_new_trace: the next chain in that thread gets a root span in a new trace. Before:next chain span has parent 847c3cf9c1747c2f; expected a root span. After: passes.test_failed_chain_span_is_error_with_the_exception_recorded: the failed chain span is ERROR with the exception recorded. Before:the failed chain span was never ended. After: passes.test_interrupt_from_a_link_still_ends_and_detaches_the_chain_span_on_its_way_out[KeyboardInterrupt]and[SystemExit](new): the interrupt from a link has ended and detached the chain span by the time it reaches the caller. Status is not checked. Before, on the old manual enter and exit:span 'vcon_processing.failing_chain' is still current in the worker thread, for both. After: both pass.test_egress_context_is_taken_inside_the_chain_span(new): the context stored for an egress list carries the chain span's trace id and span id. Before: passes, since the old code already ran egress inside the span. On a copy that calls the wrap-up after thewithblock:Expected 'store_context_sync' to have been called once. Called 0 times.After: passes.test_parallel_storage_spans_nest_under_the_chain_span: with parallel storage and two backends, eachstorage.*span has the chain span as parent and shares its trace. Changed: each fake write now waits on a two-party barrier, so both writes are in flight at once on two pool threads, and the test checks that. Without it the pool reused one thread for both. Before:storage.store_b is a root span. After: passes.test_successful_chain_span_is_ok_with_correlation_attributes: the success path still ends OK withvcon.uuid,tenant.idandcall.session_idon the chain span. Before: passes. After: passes.Without the fix: 6 failed, 2 passed. With it: 8 passed. Full suite on the host with Python 3.12 and a local plain Redis: 808 passed, 17 skipped (the skips need API keys or migration URLs).
A backport to the production build branch follows in a separate PR.
🤖 Generated with Claude Code