Repository navigation
Description
Summary
Design and evaluate approaches for OTEL GenAI trace observability (Agent + LLM spans visible in MLflow/Phoenix) that require minimal or zero changes to agent code, while passing the same E2E tests introduced in PR #569.
Currently, PR kagenti/agent-examples#114 adds ~551 lines of observability.py to the weather agent with middleware, explicit MLflow/OpenInference/GenAI attribute setting. This works but is invasive - every agent needs this boilerplate.
Goal: Find infrastructure-level solutions where the platform handles observability, not individual agents.
The Root Span Problem
graph TD
subgraph "What MLflow Needs"
RS[Root Span: invoke_agent weather-assistant]
RS -->|mlflow.spanInputs| INPUT[User Input]
RS -->|mlflow.spanOutputs| OUTPUT[Agent Response]
RS -->|mlflow.traceName| NAME[weather-assistant]
RS -->|gen_ai.conversation.id| SESSION[Session ID]
RS --> LC[LangChain Spans]
LC --> LLM[LLM Call Spans]
LLM -->|gen_ai.usage.input_tokens| TOKENS[Token Counts]
LC --> TOOL[Tool Call Spans]
end
The root span is the main challenge:
- MLflow reads
mlflow.spanInputs/mlflow.spanOutputsfrom the ROOT span only - Auto-instrumented LLM metrics (tokens) come from nested spans - this works fine
- If root span starts inside agent = agent needs custom code (current approach)
- If root span starts outside agent (proxy) = challenge is connecting it to agent's internal traces
- OTEL Collector cannot create new spans - only modify existing ones
Research Findings
OTEL Collector Capabilities (Verified)
| Capability | Supported? |
|---|---|
| Create new spans | NO - requires custom processor/connector |
| Modify span attributes | YES - transform processor |
| Modify parent_span_id (static) | YES - OTTL |
| Dynamic reparenting (cross-span) | NO - no cross-span awareness |
| Promote span attrs to resource | YES - groupbyattrs processor |
| Copy attributes between spans | NO - requires custom processor |
AuthBridge ext_proc (Existing Infrastructure)
- Go-based gRPC server at
localhost:9090inside agent pods - Handles inbound JWT validation + outbound token exchange
- Currently processes headers only (
request_body_mode: NONE) - No OTEL instrumentation - only basic logging
- Auto-injected via webhook when
kagenti.io/inject=enabled
Istio Waypoint
- Native tracing creates HTTP-level spans but cannot parse request bodies
- WasmPlugin is supported but requires Wasm development
- ext_proc requires Envoy Gateway as waypoint (additional component)
Approaches to Evaluate
Approach A: AuthBridge ext_proc Root Span (Zero Agent Changes) ⭐
sequenceDiagram
participant Client
participant Envoy as Envoy Sidecar
participant ExtProc as ext_proc<br/>(AuthBridge + OTEL)
participant Agent as Agent Code
participant LLM as LLM Provider
participant Collector as OTEL Collector
participant MLflow
Client->>Envoy: A2A JSON-RPC Request
Envoy->>ExtProc: Request Headers + Body
Note over ExtProc: Parse A2A JSON-RPC<br/>Extract user input, context_id
Note over ExtProc: Create root span:<br/>invoke_agent weather-assistant
Note over ExtProc: Set traceparent header
ExtProc->>Envoy: Modified headers (+ traceparent)
Envoy->>Agent: Request (with trace context)
Agent->>LLM: LLM call (auto-instrumented)
Note over Agent: LangChain/OpenAI spans<br/>inherit trace context
LLM-->>Agent: Response + token counts
Agent-->>Envoy: A2A Response
Envoy->>ExtProc: Response Headers + Body
Note over ExtProc: Parse response<br/>Set mlflow.spanOutputs on root span
ExtProc-->>Envoy: OK
Envoy-->>Client: Response
ExtProc->>Collector: Root span with all MLflow attrs
Agent->>Collector: Nested LLM/Tool spans
Collector->>MLflow: Complete trace tree
What changes:
- Extend AuthBridge Go ext_proc to create OTEL root spans
- Change Envoy config:
request_body_mode: BUFFERED,response_body_mode: BUFFERED - Add OTEL SDK to Go ext_proc code
Agent needs only:
- OTEL SDK setup (TracerProvider + OTLP exporter) - standard boilerplate
- Auto-instrumentation libraries (LangChain, OpenAI) - already needed
- W3C Trace Context propagation configured
- Zero custom observability code
Why this works:
- AuthBridge already intercepts ALL agent traffic via iptables
- ext_proc can access request/response bodies with BUFFERED mode
- W3C traceparent header injection ensures agent spans become children
- Root span lives in ext_proc with full MLflow/OpenInference/GenAI attributes
Approach B: Minimal Agent Boilerplate + Collector Enrichment (Minimal Changes)
Since OTEL Collector cannot create spans, agent needs ONE root span. But make it as simple as possible:
# ENTIRE agent observability code (~15 lines)
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
trace.set_tracer_provider(provider)
# Middleware: just create named root span, nothing else
tracer = trace.get_tracer("agent")
async def middleware(request, call_next):
with tracer.start_as_current_span("invoke_agent my-agent"):
return await call_next(request)OTEL Collector does ALL the enrichment:
transform/genai_to_mlflow:
trace_statements:
- context: span
statements:
- set(attributes["mlflow.spanType"], "AGENT") where IsRootSpan()
- set(attributes["mlflow.traceName"], resource.attributes["service.name"]) where IsRootSpan()
- set(attributes["mlflow.source"], resource.attributes["service.name"]) where IsRootSpan()
# ... etcLimitations:
- Agent still needs ~15 lines of boilerplate (TracerProvider + middleware)
- No input/output capture without body parsing (collector can't access HTTP body)
- Session tracking requires agent to set
gen_ai.conversation.id
Approach C: Envoy Sidecar + Correlation ID (From Team Discussion)
graph LR
subgraph "Agent Pod"
E[Envoy Sidecar] -->|x-request-id| A[Agent]
A -->|x-request-id| E
end
E -->|Independent spans<br/>with correlation ID| OC[OTEL Collector]
OC -->|Post-hoc<br/>reconstruction| J[Jaeger/Tempo]
- Envoy sidecars inject trust metadata headers (caller-id, target, etc.)
- Shared correlation ID propagated through all hops
- Reconstruct causal chain post-hoc using temporal backtracking
Assessment: NOT viable for MLflow E2E tests
- MLflow expects real parent-child trace tree, not post-hoc correlation
- Temporal backtracking adds complexity and latency
- Better suited for delegation/provenance tracking (complementary use case)
- Could complement Approach A for trust chain visibility
Approach D: Istio WasmPlugin on Waypoint (Zero Agent Changes, Higher Effort)
- Write a Wasm plugin (Rust/Go) for waypoint proxy
- Plugin buffers A2A request/response bodies
- Creates OTEL spans with all required attributes
- Exports to OTEL Collector via HTTP
Assessment: Medium viability
- WasmPlugin is officially supported on waypoints
- Wasm development is more complex than extending Go ext_proc
- Body buffering in Wasm has performance implications
- Less practical than Approach A since AuthBridge already exists
Approach E: Agent Middleware (Current Baseline from PR 114)
The current working approach for reference:
- ~551 lines of
observability.pyin agent code - Middleware creates root span with all attributes
- Agent code sets input/output on root span
- Auto-instrumentation for LangChain + OpenAI
- Most invasive but most reliable
Success Criteria
Each approach must pass the MLflow E2E tests from test_mlflow_traces.py:
-
TestWeatherAgentTracesInMLflow- traces exist, identified by service.name -
TestGenAITracesInMLflow- LLM spans with tree structure -
TestMLflowTraceMetadata- request_id, timing, state -
TestSessionTracking- gen_ai.conversation.id present -
TestRootSpanAttributes- mlflow.spanInputs/Outputs, user, traceName, version, runName + OpenInference input/output.value + GenAI conversation.id, agent.name -
TestTokenUsageVerification- gen_ai.usage.input/output_tokens on LLM spans -
TestToolCallSpanAttributes- tool name, input/output, span kind -
TestErrorSpanValidation- error status and exception details
Implementation Plan
- Create worktree per approach from
upstream/main - Each approach gets a draft PR with implementation + documentation
- Run E2E tests (TDD loop) against each approach
- Compare results - which tests pass, performance impact, complexity
- Document findings - tradeoffs, recommendations
Related
- PR ✨ Add MLflow integration for LLM trace observability #569 - MLflow integration (merged, defines E2E tests)
- kagenti/agent-examples#114 - Current agent-side approach
- OTEL GenAI Semantic Conventions
- MLflow OTEL Tracing
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Ladas commentedon Feb 12, 2026
Draft PRs Created
Each approach has a worktree and draft PR with a design document:
.worktrees/otel-authbridge-approach.worktrees/otel-minimal-agent.worktrees/otel-correlation-sidecarResearch Findings Summary
OTEL Collector Limitations (Verified)
IsRootSpan()(v0.104.0+)AuthBridge Infrastructure (Existing)
Istio Waypoint (Alternative to AuthBridge)
Next Steps
Ladas commentedon Feb 12, 2026
Implementation Complete - All CI Green
All three draft PRs are implemented, pushed, and passing CI (lint, build, DCO, security, Deploy & Test):
PR Status
otel_tracing.go,process_with_otel.go), Envoy body buffering config, agent-otel ConfigMapobservability_minimal.py(50 lines),transform/agent_enrichmentin otel-collector.yaml (15 OTTL statements)Shared Across All PRs
AGENT_OBSERVABILITY_VARIANTenv var +VariantProfiledataclassbaseline,minimal,authbridge,noneComparison: Agent Code Required
input.value,output.value,gen_ai.agent.name,gen_ai.conversation.idmlflow.*,openinference.span.kind,llm.token_count.*, etc.Next Steps: TDD on Cluster
To validate each approach passes the MLflow E2E tests, deploy to a cluster and run:
# For each approach, set the variant and run AGENT_OBSERVABILITY_VARIANT=minimal pytest -m observability -v AGENT_OBSERVABILITY_VARIANT=authbridge pytest -m observability -vThis requires:
76 remaining items
esnible commentedon Feb 19, 2026
Note that Kuadrant/mcp-gateway#595 added observability to the MCP Gateway.
I am surprised we needed 551 lines to add observability. Kagenti already adds
OTEL_EXPORTER_OTLP_ENDPOINTto the agents, and I see deep traces from the agent already. I have viewed these traces in both Phoenix and with Tempo (using Jaeger UI).evaline-ju commentedon Feb 19, 2026
fyi I've tried this out with Kagenti - we'll need to connect some dots here to bring this in, starting with #616 (I know this is in progress)
feat: Minimal agent instrumentation for AuthBridge OTEL (Approach A)
feat: Add Starlette OTEL instrumentation for traceparent extraction
feat: Minimal agent instrumentation for AuthBridge OTEL (Approach A)
feat: Add Starlette OTEL instrumentation for traceparent extraction
esnible commentedon Apr 14, 2026
@ilya-kolchinsky are you working on this?
ilya-kolchinsky commentedon Apr 15, 2026
@esnible I have a non-Kagenti prototype here. Got some pushback on it (both internally and from the Kagenti team) due to lack of support of Go and compiled languages in general. This gap is real, but unfortunately very hard to address due to the very rudimentary support of the above by the OTel operator. So for now this PoC has been put on the shelf.
If there is still interest in this direction, and if you believe the lack of Go support is not a dealbreaker, I'm open to further discussing this and contributing the feature as a Kagenti operator extension.
github-actions commentedon Jul 22, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. If this issue is still relevant, please comment or remove the stale label.
github-actions commentedon Aug 5, 2026
This issue was closed because it has been stale for 14 days with no activity. Feel free to reopen if this is still relevant.