Distributed tracing context in ADK #3461
Replies: 2 comments 1 reply
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Yes, this is possible! ADK uses the OpenTelemetry standard for tracing. To connect the traces, you don't need to manually export context from ADK. Instead, you need to instrument your MCP server with an OpenTelemetry SDK, which will automatically pick up the trace context ADK sends in the HTTP request headers. Hello! That's an excellent question, and you've hit on a core concept of modern application observability. What you're looking to achieve is called "distributed tracing," and the good news is that the ADK ecosystem is designed to support this. The key is that ADK's tracing capabilities are built on the OpenTelemetry (OTEL) standard. [1] Here’s how it works for your use case:
This is what links the two systems together into a single, coherent trace, removing the "black box" you're seeing. What you need to doYou don't need to change anything on the ADK side. Your focus should be on your MCP server. You need to integrate an OpenTelemetry SDK into it. The specific implementation will depend on the language and framework your MCP server is built with, but the general steps are:
The official OpenTelemetry documentation is the best resource for how to instrument your specific service. The documentation for Thank you for your willingness to contribute! In this case, since the mechanism relies on instrumenting your own service, no contribution to the ADK repository is needed. [1] https://cloud.google.com/trace/docs/overview |
Beta Was this translation helpful? Give feedback.
-
|
Adding more info for this. The trace context is not propagated automatically. I had to do it manually. My supplier basically get's current active span and pushes it through to downstream Cloud Run MCP server. The traceID and spanID match what's shown on cloud-trace for On my MCP CloudRun service (FastAPI + gunicorn + CloudRun Service). we had issues like spanID being changed when the request came to us. This spanID was not existing in cloud-trace and some sources on the internet say the infra layer before my service adds it's own spans. My textmap propagators look like this I have also added a gunicorn shutdown hook to ensure spans are flushed. Also added an Finally I have also tried nuking every span attribute, events and links From local service runs everything runs perfectly fine (Importing from existing trace and new traces) and everything is pushed to cloud-trace perfectly. From cloudrun some of my spans are coming through i.e MCP Enabling debug logging tells me so I'm assuming export is happening. Any help here is appreciated. Metadata |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I'm trying out ADK and I wanted to know if we can 'export' trace context from ADK to downstream HTTP calls.
Description :
We have an MCP server running (StreamableHTTP) and I wanted to the ADK deployment on AgentEngine to connect to this via the
MCPToolsetalong with traces. The connection is working fine, the agent recognizes the tools and instruments all of the calls as well but only within it's server boundary. So once it calls one of the MCP Tools on another server, it essentially black-boxes it in the trace. Our MCP tools are potentially be multistep processes that require their own spans. Now I can implement my own instrumentation and tracing on our MCP server but I would like to somehow be able to pass the existing trace-context from the ADK created root-span and pass it along to the MCP server to import, so our traces maintain coherence.I checked out the repo and could not find anything that solves my use-case here. Please let me know if something like this can be implemented.
Open toe contribute into the project if required.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions