Skip to content
Skip to Content
Coder Docs

OpenTelemetry tracing

Export Coder Agents traces that follow the OpenTelemetry GenAI semantic conventions.

On this page

Coder Agents exports OpenTelemetry traces that follow the OpenTelemetry GenAI semantic conventions. Observability backends that understand these conventions can attribute model usage, token spend, and tool activity to each user without custom mapping.

The GenAI conventions are still in development. Coder Agents follows the span names and gen_ai.* attributes in semantic conventions v1.41.0, and they might change as the conventions stabilize.

Enable tracing

Enable tracing

Start the Coder server with --trace (CODER_TRACE_ENABLE=true). Coder Agents spans are exported with the rest of the server's traces.

The server exports traces with OTLP over gRPC. Set the collector address with OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, and add headers with OTEL_EXPORTER_OTLP_HEADERS. OTEL_EXPORTER_OTLP_PROTOCOL has no effect, so OTLP over HTTP is not supported.

The connection is unencrypted by default, even for an https:// endpoint or with OTEL_EXPORTER_OTLP_INSECURE=false. To use TLS, set OTEL_EXPORTER_OTLP_CERTIFICATE to the collector's CA certificate, and set OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE and OTEL_EXPORTER_OTLP_CLIENT_KEY for mutual TLS.

Spans

Spans

Each chat turn is a separate trace. The root span covers the turn, and the model calls and tool calls of the turn are its descendants, including advisor and compaction calls. Model calls that run after a turn, such as title, status label, and chat summary generation, are traces of their own. They carry the same chat and user attributes, so you can attribute their tokens to the same user.

Span namegen_ai.operation.nameCovers
invoke_agent coderinvoke_agentOne chat turn, from the prompt to the reply
chat {gen_ai.request.model}chatOne model call, with span kind CLIENT
execute_tool {gen_ai.tool.name}execute_toolOne tool call that Coder Agents runs

The turn also contains spans for other lifecycle stages, such as generation_step, prepare, commit, and compaction. Every span carries a stage attribute with its lifecycle stage name, such as chat_turn, stream, or tool_call. Model calls outside the assistant stream, such as compaction and title generation, have the stage model_call. The stage attribute matches the stage label of the coderd_chatd_stage_duration_seconds Prometheus metric.

Attributes

Attributes

All three GenAI spans carry attributes that identify the chat and its owner:

AttributeValue
gen_ai.conversation.idThe chat ID
user.idThe ID of the user who owns the chat
coder.organization.idThe ID of the chat's organization
coder.workspace.idThe ID of the chat's workspace, if it has one
coder.chat.parent_idThe ID of the parent chat, for subagent chats
coder.chat.root_idThe ID of the root chat, for subagent chats

The invoke_agent coder span also carries gen_ai.agent.name (coder) and, once the turn selects a model, gen_ai.provider.name.

The chat span carries the model call's details:

AttributeValue
gen_ai.provider.nameThe provider, such as openai, anthropic, or aws.bedrock
gen_ai.request.modelThe model name
gen_ai.request.max_tokensThe output token limit Coder Agents requested, if one is set
gen_ai.request.temperatureThe temperature Coder Agents requested, if one is set
gen_ai.request.streamWhether the response was streamed
gen_ai.response.idThe response ID the provider reported, if any
gen_ai.response.finish_reasonsWhy the model stopped, if the provider reported it
gen_ai.usage.input_tokensInput tokens, including cache reads and cache writes
gen_ai.usage.output_tokensOutput tokens, including reasoning tokens
gen_ai.usage.cache_read.input_tokensInput tokens read from the provider's prompt cache, if any
gen_ai.usage.cache_creation.input_tokensInput tokens written to the provider's prompt cache, if any
gen_ai.usage.reasoning.output_tokensReasoning tokens, if the provider reports them
gen_ai.output.typejson, for structured output requested in OpenAI's JSON mode

The request attributes describe the limits Coder Agents asks for, not always the request sent to the provider. For example, a model configuration can set an OpenAI-specific output token limit that replaces the general limit, and some providers ignore temperature for reasoning models.

Token usage limits

Token usage limits

Token counts come from the model client Coder Agents uses, which drops some of what the provider reports:

  • Anthropic: when a response runs server-side tools such as web search, the model works in several internal iterations. Anthropic reports the input of all iterations, but the client keeps only the first iteration's input. gen_ai.usage.input_tokens and the cache attributes therefore undercount the billed input. Output tokens cover the whole response.
  • OpenAI-compatible providers, such as OpenRouter: the client does not read the cache writes these providers report, so gen_ai.usage.cache_creation.input_tokens is absent. The input token total still includes them.

AI Governance cost control has the same Anthropic gap, so its spend for those responses is also low.

The execute_tool span carries gen_ai.tool.name, gen_ai.tool.call.id, and gen_ai.tool.type. The tool type is function for built-in Coder Agents tools and extension for other tools, such as tools from MCP servers.

On chat and execute_tool spans, the operation name, provider, model, and tool attributes are set when the span starts, so samplers can use them. The invoke_agent coder span starts before the turn selects a model, so samplers see its operation name and chat attributes but not gen_ai.provider.name. A failed span has an error status and an error.type attribute. A tool call that returns an error result, such as an MCP server that cannot be reached, ends with error.type set to tool_error.

The gen_ai.* attributes contain metadata only: prompts, model responses, and tool arguments and results are not recorded in them. Other spans and span events in the same trace, such as AI Gateway spans and server log events, can contain parts of that content.