Skip to content

feat(a2aext/trace): W3C traceparent-based audit trail with MCP bridge hooks - #377

Open
kuangmi-bit wants to merge 1 commit into
a2aproject:mainfrom
kuangmi-bit:feat/trace-w3c-bridge
Open

feat(a2aext/trace): W3C traceparent-based audit trail with MCP bridge hooks#377
kuangmi-bit wants to merge 1 commit into
a2aproject:mainfrom
kuangmi-bit:feat/trace-w3c-bridge

Conversation

@kuangmi-bit

Copy link
Copy Markdown
Contributor

Summary

Alternative/complementary implementation of #365 with three key additions:

1. W3C traceparent format

Uses standard W3C Trace Context encoding (00-{trace_id}-{span_id}-{flags}) instead of a custom semicolon format. This enables interoperability with OpenTelemetry, MCP trace context, and any W3C-compliant observability stack.

Backward-compatible: ParseTraceHeader accepts both W3C and legacy formats.

2. Review fixes from #365

  • Child span inheritance: NewChildSpan now defaults to parent's TaskID/ContextID when empty
  • Validation: ParseTraceparent validates non-empty hex, 32-char trace ID, 16-char span ID
  • Chain() docs: Updated to clarify it returns the current agent:span identity

3. Cross-protocol bridge hooks

// A2A → MCP
tc := trace.BridgeToMCP(ctx)
mcpReq.Params.Meta["traceparent"] = tc["traceparent"]

// MCP → A2A
ctx = trace.BridgeFromMCP(ctx, traceparent, agentID)

Testing

20 tests, zero regressions on existing a2aext/a2asrv suites.

Relationship to #365

This is not a replacement — it is an alternative direction. #365 got the architecture right (interceptor pattern + context propagation). This PR adds W3C format + bridge hooks + review fixes. If maintainers prefer #365's approach, the bridge hooks and review fixes can be cherry-picked onto it.

Related:

…ridge hooks

Alternative implementation of a2aproject#365 with improvements:

- W3C traceparent format (00-{trace_id}-{span_id}-{flags}) as primary encoding
- Backward-compatible with legacy semicolon format via ParseTraceHeader
- Child spans inherit parent TaskID/ContextID by default
- BridgeToMCP() / BridgeFromMCP() hooks for cross-protocol propagation
- Strict validation: non-empty hex Check, 32-char trace ID, 16-char span ID
- Updated Chain() docs clarifying it returns current agent:span identity
- 20 tests covering: root/child span creation, W3C encode/decode, 3-hop chain,
  inheritance, bridge hooks, ID collisions, legacy format, invalid inputs

Zero regressions on existing a2aext/a2asrv/push/taskstore/workqueue suites.

Related: a2aproject#365 (gemini-code-assist original), deeparchi-ai/macs trace-bridge spec,
a2aproject/A2A#2026 (trace context proposal)
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@kuangmi-bit

Copy link
Copy Markdown
Contributor Author

@yarolegovich @nahapetyan-serob — gentle ping for review. This PR adds W3C traceparent-based audit trail with MCP bridge hooks. All CI green (4✓), mergeable. Related: spec discussion at a2aproject/A2A#2026.

@kuangmi-bit

Copy link
Copy Markdown
Contributor Author

@nahapetyan-serob would appreciate a review when you have time.

This PR is complementary to #365 — same audit trail domain, different approach:

  1. W3C traceparent format instead of custom encoding → interoperable with OpenTelemetry/MCP
  2. MCP bridge hooks → agent-card-embedded trace remapping for cross-protocol calls
  3. B3 multi-header fallback for Zipkin compatibility

All CI checks pass. The trace package is ~300 lines, pure stdlib (no external deps). Integration points are opt-in: a2asrv.WithTrace() and a2aclient.WithTracePropagation().

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