Skip to content
Discussion options

You must be logged in to vote

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_agent span 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 traceparent header, extract and attach it around the agent call:

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, th…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yonib05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants