You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To maintain correlation between traces generated by different agents for the same request, it is necessary to propagate a unique identifier (e.g., test-case-id) through the trace context. This ensures that traces from all agent executions related to a single test case can be linked and analyzed together.
OpenTelemetry (OTEL) provides support for context propagation, but leveraging it in practice requires additional setup and configuration. This capability becomes particularly critical when evaluating agents across multiple test cases: once an agent is invoked, we need a way to associate all resulting traces with the current test case. Passing this identifier as baggage to the agent enables downstream spans to carry this metadata, which can later be used to filter or correlate traces.
User stories:
Distributed tracing for distributed multi-agents: Observe and analyse distributed agent's behaviors
Simplified Agent evaluation: Need a correlation id to filter traces for each test-case accurately and efficiently.
Session/Task Id support: Tracking sessions and task through a correlation id.
Approaches for Achieving Context Propagation
1) Framework Instrumentation (e.g., FastAPI)
Automatically extracts context from incoming requests. Propagates baggage to all child spans, including agent traces.
fromfastapiimportFastAPIfromopentelemetry.instrumentation.fastapiimportFastAPIInstrumentorfromopentelemetry.instrumentation.requestsimportRequestsInstrumentorapp=FastAPI()
# These two lines fix propagation for the entire appFastAPIInstrumentor.instrument_app(app) # Extracts context from incoming headersRequestsInstrumentor().instrument() # Injects context into outgoing requests
Notes:
Works only with supported frameworks (e.g., FastAPI, Flask).
Requires modifying the application code to register instrumentation for each app instance.
2) Manual Propagation
Explicitly extract incoming headers and attach them to the OpenTelemetry context in the code. Baggage can then be propagated to all spans spawned during agent execution.
fromfastapiimportRequestfromopentelemetryimportpropagateimportrequests@app.get("/chat")asyncdefchat_agent(request: Request):
# 1. Extract context from incoming FastAPI headersctx=propagate.extract(request.headers)
# 2. Inject context into a headers dictionary for outgoing 'requests'headers= {}
propagate.inject(headers, context=ctx)
# 3. Use the headers in your callresponse=requests.get("https://other-service.com", headers=headers)
returnresponse.json()
Notes:
Works with any framework or service type.
Requires changes in the code wherever context propagation is needed.
3) Auto-Instrumentation with OpenTelemetry
Uses OTEL’s auto-instrumentation capabilities to capture context across HTTP, RPC, or other supported protocols.
a. Installation
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
Provides broad coverage without manual instrumentation.
Limited by supported frameworks and languages.
4) Hybrid approach to extend amp-instumentation (Recommended)
To support any framework without modifying user code, I propose extending sitecustomization.py to handle context propagation centrally.
fromopentelemetry.instrumentation.fastapiimportFastAPIInstrumentor# 1. Initialize the instrumentor FIRST# Repeat for other supported frameworks FastAPIInstrumentor().instrument()
# 2. ONLY NOW import and use FastAPIfromfastapiimportFastAPIapp=FastAPI()
This approach enables us to enhance our existing amp-instrumentation package to provide context propagation not only for FastAPI but for any supported framework. By implementing this centralized mechanism, we can ensure consistent trace correlation across distributed agents, streamline agent evaluations, and minimize the need for framework-specific instrumentation or manual code changes.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
To maintain correlation between traces generated by different agents for the same request, it is necessary to propagate a unique identifier (e.g., test-case-id) through the trace context. This ensures that traces from all agent executions related to a single test case can be linked and analyzed together.
OpenTelemetry (OTEL) provides support for context propagation, but leveraging it in practice requires additional setup and configuration. This capability becomes particularly critical when evaluating agents across multiple test cases: once an agent is invoked, we need a way to associate all resulting traces with the current test case. Passing this identifier as baggage to the agent enables downstream spans to carry this metadata, which can later be used to filter or correlate traces.
User stories:
Approaches for Achieving Context Propagation
1) Framework Instrumentation (e.g., FastAPI)
Automatically extracts context from incoming requests. Propagates baggage to all child spans, including agent traces.
Notes:
2) Manual Propagation
Explicitly extract incoming headers and attach them to the OpenTelemetry context in the code. Baggage can then be propagated to all spans spawned during agent execution.
Notes:
3) Auto-Instrumentation with OpenTelemetry
Uses OTEL’s auto-instrumentation capabilities to capture context across HTTP, RPC, or other supported protocols.
a. Installation
b. Run
Notes:
4) Hybrid approach to extend
amp-instumentation(Recommended)To support any framework without modifying user code, I propose extending sitecustomization.py to handle context propagation centrally.
This approach enables us to enhance our existing
amp-instrumentationpackage to provide context propagation not only for FastAPI but for any supported framework. By implementing this centralized mechanism, we can ensure consistent trace correlation across distributed agents, streamline agent evaluations, and minimize the need for framework-specific instrumentation or manual code changes.Beta Was this translation helpful? Give feedback.
All reactions