Skip to content

feat(tracing): adopt ambient W3C/OTel trace id for agent spans#470

Closed
mohammadatallah-scale wants to merge 2 commits into
nextfrom
feat/agentex-adopt-w3c-trace-id
Closed

feat(tracing): adopt ambient W3C/OTel trace id for agent spans#470
mohammadatallah-scale wants to merge 2 commits into
nextfrom
feat/agentex-adopt-w3c-trace-id

Conversation

@mohammadatallah-scale

Copy link
Copy Markdown

Agentex hard-passes its own task/thread id as the SGP trace_id (_build_sgp_span), which overrides the SDK's W3C adoption. So even with the SDK change (scaleapi/sgp-python-beta#178), agent-originated business traces stay on a separate id namespace from the observability trace. This closes that gap.

What changed

  • _build_sgp_span now sets trace_id=_resolve_trace_id(span.trace_id): prefer the active OTel/W3C trace id (32-hex), fall back to agentex's own id when no OTel context is present.
  • _add_source_to_span stamps the original agentex id into span metadata (__agentex_trace_id__) so the task linkage survives once the SGP trace_id adopts the W3C id.
  • opentelemetry stays a soft dependency (helper returns None if absent).

Behavior

No-op today: agentex has no OTel context at its entrypoint, so _active_otel_trace_id() returns None and the agentex id is kept (unchanged behavior). It activates automatically once the agent runtime carries a W3C context.

Test plan

  • Unit: prefers OTel id / falls back to agentex id; real SpanContext → 32-hex; metadata preserves the agentex id (test_sgp_tracing_processor.py)
  • Full processor test file green (37 passed), ruff clean

Remaining follow-up (separate)

Instrument the agentex request entrypoint (ACP server) to establish an OTel context from the inbound W3C traceparent. Until then this seam is inert. Likely belongs to the OTel Integration effort.

Part of the trace-id unification epic (OVE-350). Pairs with sgp-python-beta#178, scaleapi#153175, scaleapi/sgp#4271.

mohammadatallah-scale and others added 2 commits July 23, 2026 14:08
Agentex hard-passed its own task/thread id as the SGP trace_id, which
overrode the SDK's W3C adoption and kept agent traces on a separate id
namespace from the observability trace. _build_sgp_span now prefers the
active OTel/W3C trace id (falling back to agentex's id when no OTel context
is present) and preserves the original id in span metadata.

This is a no-op until the agent runtime carries an OTel context; the
entrypoint instrumentation that establishes it is the remaining follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
span.data is Optional; assert it is a dict before indexing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mohammadatallah-scale
mohammadatallah-scale changed the base branch from main to next July 23, 2026 18:11
@mohammadatallah-scale

Copy link
Copy Markdown
Author

Closing as superseded by #465. That PR solves the same agentex business-span ↔ observability-trace correlation with the correct non-destructive design: it keeps the run-level business trace_id and adds obs.trace_id/obs.span_id link tags, rather than overwriting trace_id (which this PR did, and which shatters one agent run across N per-turn obs traces). #465/#466/#467 cover span-tag → ACP ingress → Temporal propagation end to end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant