| [ Web Proxy ] |
| Viewing: https://adk.dev/integrations/../../live/dev-guide/../../../a2a/../../observability/traces/ | [Back] [Original] |
[logo]
Agent Development Kit (ADK) provides distributed tracing capabilities to help you visualize the end-to-end journey of a request as it travels through your agent's architecture. While metrics tell you how long a process took and logs tell you what happened, traces connect these events, showing you exactly where the time was spent and the hierarchical relationship between LLM reasoning, tool calls, and external APIs.
ADK's approach to tracing is built on standard protocols to ensure seamless integration with your existing observability stack.
When tracing is enabled, ADK automatically instruments key operations following the OpenTelemetry GenAI Semantic Conventions for Agents. A typical trace waterfall includes the following spans:
| Span Name | Type | Description | Key Attributes |
|---|---|---|---|
invoke_agent {agent.name} |
Client / Internal Span | Describes GenAI agent invocation over a remote service or locally. Represents the lifecycle of an agent interaction. | gen_ai.operation.name, gen_ai.agent.name, gen_ai.agent.description, gen_ai.conversation.id |
invoke_workflow {workflow.name} |
Child Span | Describes the invocation of a multi-step agentic workflow. | gen_ai.operation.name, gen_ai.workflow.name, gen_ai.conversation.id, gen_ai.workflow.nested (nested workflows only) |
execute_tool {tool.name} |
Child Span | Represents the execution of a specific tool or function call requested by the GenAI system. | gen_ai.operation.name, gen_ai.tool.name, gen_ai.tool.description, gen_ai.tool.type, gen_ai.tool.call.id, error.type |
generate_content {model.name} |
Internal Span | Represents the invocation of the underlying language model (via the GenAI SDK) to generate content. It tracks the request parameters, response details, and usage metrics. | gen_ai.operation.name, gen_ai.system, gen_ai.request.model, gen_ai.agent.name, gen_ai.conversation.id, gen_ai.response.finish_reasons, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens |
If you are running your agent using the adk web or adk api_server CLI commands, you can configure trace exports.
To export traces to an OTLP-compatible backend, set the standard OTel environment variables:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://your-collector:4318/v1/traces"
adk web path/to/your/agents_dir
Note: You can also set the general
OTEL_EXPORTER_OTLP_ENDPOINTenvironment variable if you would like to send metrics and logs to the same endpoint in addition to traces.
To enable trace export to Google Cloud Trace, use the --otel_to_cloud flag:
You can also configure trace export programmatically in your application code.
To enable tracing and export spans to an OpenTelemetry Collector programmatically:
from google.adk.telemetry.setup import maybe_set_otel_providers
import os
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "http://your-collector:4318/v1/traces"
os.environ["OTEL_SERVICE_NAME"] = "your-adk-agent"
os.environ["OTEL_RESOURCE_ATTRIBUTES"] = "key1=value1,key2=value2"
maybe_set_otel_providers()
To export traces to Google Cloud Trace programmatically, use the OpenTelemetry Google Cloud exporter. Here is an example in Python:
from google.adk.telemetry.google_cloud import get_gcp_exporters
from google.adk.telemetry.setup import maybe_set_otel_providers
import os
gcp_exporters = get_gcp_exporters(
enable_cloud_tracing = True,
)
os.environ["OTEL_SERVICE_NAME"] = "your-adk-agent"
os.environ["OTEL_RESOURCE_ATTRIBUTES"] = "key1=value1,key2=value2"
maybe_set_otel_providers([gcp_exporters])
In Kotlin, ADK automatically uses the GlobalOpenTelemetry instance to export traces. You should configure your OpenTelemetry SDK before starting the agent.
To enable tracing and export spans to an OpenTelemetry Collector, configure the OpenTelemetry SDK and register it globally:
// 1. Configure OpenTelemetry (Traces)
// ADK Kotlin uses GlobalOpenTelemetry to resolve its tracer on the JVM.
val spanExporter = OtlpGrpcSpanExporter.builder().setEndpoint("http://localhost:4317").build()
val resource =
Resource.getDefault()
.merge(
Resource.create(
Attributes.of(AttributeKey.stringKey("service.name"), "my-kotlin-agent"),
),
)
val tracerProvider =
SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build())
.setResource(resource)
.build()
OpenTelemetrySdk.builder().setTracerProvider(tracerProvider).buildAndRegisterGlobal()
// 2. Optional: Configure ADK Telemetry behavior
// Enable capturing full message content in traces (use with caution in production)
TelemetryConfig.captureMessageContent = true
// 3. Initialize Agent and Runner with LoggingPlugin for console output
val agent = LlmAgent(name = "my_agent", model = Gemini(name = "gemini-flash-latest"))
val runner =
InMemoryRunner(
App(appName = "my_agent", rootAgent = agent, plugins = listOf(LoggingPlugin())),
)
// The runner will now automatically emit traces via GlobalOpenTelemetry
// and log activity to the console via the LoggingPlugin.
runner.run(
userId = "user123",
sessionId = "session456",
newMessage = Content.fromText(Role.USER, "Hello!"),
)
| Web Proxy Viewer | New URL | Original Page |