-
Notifications
You must be signed in to change notification settings - Fork 9
fix(tracing): continue inbound W3C trace context at the ACP boundary #490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NiteshDhanpal
wants to merge
1
commit into
feat/obs-correlation-edge
Choose a base branch
from
fix/acp-w3c-ingress-trace-context
base: feat/obs-correlation-edge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """Unit tests for ACP inbound W3C trace-context extraction. | ||
|
|
||
| Regression guard for the async end-to-end tracing fix: FastACP must *continue* | ||
| an incoming traceparent (make it the active OpenTelemetry context) so the | ||
| downstream Temporal start/signal — and the work dispatched via | ||
| asyncio.create_task — run under the ingress trace instead of detaching into a | ||
| fresh trace. See RequestIDMiddleware / _attach_incoming_otel_context. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from opentelemetry.propagate import inject | ||
|
|
||
| from agentex.lib.sdk.fastacp.base.base_acp_server import ( | ||
| _detach_otel_context, | ||
| _attach_incoming_otel_context, | ||
| ) | ||
|
|
||
|
|
||
| def _active_traceparent() -> str | None: | ||
| carrier: dict[str, str] = {} | ||
| inject(carrier) | ||
| return carrier.get("traceparent") | ||
|
|
||
|
|
||
| def test_attach_makes_inbound_traceparent_the_active_context() -> None: | ||
| trace_id = "0af7651916cd43dd8448eb211c80319c" | ||
| headers = [ | ||
| (b"traceparent", f"00-{trace_id}-b7ad6b7169203331-01".encode()), | ||
| (b"content-type", b"application/json"), | ||
| ] | ||
| token = _attach_incoming_otel_context(headers) | ||
| try: | ||
| active = _active_traceparent() | ||
| assert active is not None, "no active traceparent after attach" | ||
| # The active context must carry the ingress trace id, so the Temporal | ||
| # interceptor propagates it downstream instead of starting a fresh trace. | ||
| assert trace_id in active, f"expected ingress trace {trace_id}, got {active}" | ||
| finally: | ||
| _detach_otel_context(token) | ||
|
|
||
|
|
||
| def test_no_inbound_traceparent_is_fail_open() -> None: | ||
| # No traceparent header: must not raise, and detach must be safe. | ||
| token = _attach_incoming_otel_context([(b"content-type", b"application/json")]) | ||
| _detach_otel_context(token) | ||
|
|
||
|
|
||
| def test_detach_none_is_safe() -> None: | ||
| _detach_otel_context(None) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting the raw ASGI header list to a dictionary retains only the final value of repeated
baggageortracestatefields, silently omitting earlier propagation metadata from downstream context.Prompt To Fix With AI