Tracing Propagation #558
|
Is there a way to set the trace id received from an external source e.g., request header? |
Replies: 1 comment
|
Hi @lilianskim, yes, this works with standard OpenTelemetry context propagation. Apologies for the slow answer on what turns out to be good news. Strands parents its If the caller sends a W3C from opentelemetry import context
from opentelemetry.propagate import extract
ctx = extract(dict(request.headers))
token = context.attach(ctx)
try:
result = agent("hello")
finally:
context.detach(token)If you're on FastAPI, Flask, or similar, the corresponding OpenTelemetry instrumentation package (for example General tracing setup is covered here: traces. Hope this helps! |
Hi @lilianskim, yes, this works with standard OpenTelemetry context propagation. Apologies for the slow answer on what turns out to be good news.
Strands parents its
invoke_agentspan on the current OTel context, so if you attach the incoming trace context before invoking the agent, all agent, model, and tool spans nest under the external trace id.If the caller sends a W3C
traceparentheader, extract and attach it around the agent call:If you're on FastAPI, Flask, or similar, th…