How can OpenTelemetry be used to monitor AI agents?
Summary
- OpenTelemetry (OTel) monitors AI agents by modeling each run as a trace and each step (model call, tool call, retrieval, sub-agent) as a span with a parent, a status and attributes.
- The OpenTelemetry GenAI semantic conventions standardize agent attributes such as the operation type, requested model, token usage and tool name. Any OTel-aware backend can then read agent spans without custom parsing.
- Because OTel is vendor-neutral, you instrument once with any OTel SDK, export spans over OTLP, and keep the freedom to send them to more than one backend.
- On Databricks, MLflow Tracing is built on OpenTelemetry and stores OTel traces in Unity Catalog. Unity Gateway writes every model and MCP request to a unified trace table in OTel format (Beta) that can also take your application's own spans.
How can OpenTelemetry be used to monitor AI agents?
OpenTelemetry monitors AI agents by recording every run as a trace and every step inside it as a span: each model call, tool call, retrieval and sub-agent hop. Each span carries a parent ID, a success or error status, timing, and attributes that follow the OpenTelemetry GenAI semantic conventions for the model, token usage and tool name. You instrument with any OTel SDK, export over the standard OTLP protocol, and analyze spans wherever they land. The payoff comes from storing those spans where you can query them alongside cost, identity and quality data, so an agent's behavior becomes something you can measure, not guess at.
How OpenTelemetry concepts map to agents
| OTel concept | What it means for an agent | Example field or attribute |
|---|---|---|
| Trace | One agent run or request tree | trace_id |
| Span | One step: a model call, tool call or sub-agent | name, kind, start and end times |
| Parent and child spans | Agent calls a model, which triggers a tool | parent_span_id (empty on the root span) |
| Status | Did the step succeed? | status.code such as STATUS_CODE_ERROR |
| Operation type | Chat, tool execution or agent invocation | gen_ai.operation.name (chat, execute_tool, invoke_agent) |
| Token usage | The main cost driver | gen_ai.usage.input_tokens, gen_ai.usage.output_tokens |
| Tool details | What the agent called, with what | gen_ai.tool.name, gen_ai.tool.call.arguments |
| Session and user | Group turns into conversations | session.id, user.id |
| Context propagation | Link spans across services | W3C traceparent header |
What OTel doesn't give you on its own is somewhere to keep, govern and analyze the spans. That's the decision that shapes everything downstream.
How Databricks uses OpenTelemetry for agent monitoring
MLflow Tracing is OpenTelemetry underneath. Every trace MLflow captures is a set of OTel spans. Autologging and @mlflow.trace produce them for you, and MLflow can export them outbound to any OpenTelemetry-compatible platform over OTLP. Set OTEL_EXPORTER_OTLP_TRACES_ENDPOINT to send traces only to an external collector, or add MLFLOW_ENABLE_DUAL_EXPORT to send them to Databricks MLflow and your existing stack at the same time.
Store OTel traces in Unity Catalog. Databricks recommends Unity Catalog trace storage for new and production workloads. When you bind an MLflow experiment to a Unity Catalog location, MLflow creates _otel_spans, _otel_logs, _otel_metrics and _otel_annotations tables under your chosen prefix. Third-party OTel clients can write spans to the Databricks-hosted OTLP endpoint (/api/2.0/otel/v1/traces) with an X-Databricks-UC-Table-Name header naming the target spans table. Custom OTel instrumentation uses the OTel tracing preview. For spans to render correctly, set gen_ai.operation.name and gen_ai.input.messages / gen_ai.output.messages on each span, and put token counts and session.id on the root span.
Capture gateway traffic with the unified trace table (Beta). Unity Gateway writes every request and response across its model and MCP services to one Unity Catalog table in OpenTelemetry format, with no per-endpoint setup. Spans use an MLflow-compatible OTel schema, so MLflow tools can read them directly. Your applications can send their own client-side spans (Beta, enabled per workspace) to the same table through the gateway's OTLP endpoint. Standard exporter variables are enough:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://<workspace-url>/ai-gateway/otel/v1/traces"
export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer%20<token>"
export OTEL_SERVICE_NAME="<your-application-name>"
The endpoint accepts uncompressed OTLP over HTTP with binary protobuf only. When your app propagates W3C trace context, gateway trace linking (Beta) can place the gateway's request spans in the same trace as your application's spans.
Analyze the spans like any other data. Because traces are Delta tables, you can query them with SQL, build AI/BI dashboards and alerts, ask Genie Code questions about them, and run MLflow judges over them for quality.
Where OpenTelemetry helps most
- Multi-framework agent fleets. Teams on different agent frameworks and languages emit one span format into one place.
- Debugging multi-step runs. Filter on error status, then follow
parent_span_idfrom the failing tool span up to the request that caused it. - Cost attribution. Sum
gen_ai.usage.*tokens by service, user or session. - Keeping existing tools. Dual export sends the same spans to Databricks and to the observability platform your SRE team already runs.
FAQs
Do I have to choose between MLflow Tracing and OpenTelemetry?
No. MLflow Tracing is built on OpenTelemetry, so MLflow traces are OTel spans. You can keep them in Databricks, export them over OTLP, or both.
What happens if I forget to set service.name?
In the Unity Gateway unified trace table, client-side spans without a service.name resource attribute appear under unknown_external_service. Set it on every tracer provider.
Which OTLP encodings does the Unity Gateway endpoint accept?
Only OTLP over HTTP with binary protobuf (http/protobuf), sent uncompressed. JSON and gRPC aren't supported, and the endpoint returns HTTP 400 for bodies that aren't valid OTLP protobuf.
Can OTel traces replace audit logs?
No. Databricks describes unified trace delivery as best-effort and positions the trace table as a complement to audit logs, which remain the system of record for compliance.
The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.