feat(runtime): export OpenTelemetry traces for agent runs

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
fastapi, python

Research direction

Start with runtimes/common/agentkit_serve_common/config.py and cli.py, then check server.py and the runtime agent_factory.py files for tracing entry points. Use parity.py and InMemorySpanExporter to run the shared tests without network access; also review the catalog files and docs/development.md for capability and dependency requirements. Done means the requested runtimes export safe, correctly joined traces, tests pass, and the docs and capability lists are updated.

Written by the indexing model from the issue text.

Description

area/runtime enhancement

Problem

When an agent gives a slow or wrong answer, there's no way to see what happened during the run. You can't tell which model calls it made, which tools it used, how long each step took, how many tokens it spent, or which step failed. The logs only show the HTTP request.

The Agentkitfile already has a field for this, but every runtime turns it down:

observability:
  otel:
    endpointEnv: OTEL_EXPORTER_OTLP_ENDPOINT
runtime "pydantic-ai" does not support requested capabilities: otel-export

The Python config reader rejects it too, with observability.otel.endpointEnv is not supported by current runtimes.

What

Make observability.otel.endpointEnv work. When the field is set and the env var it names has a value at runtime, the agent sends traces with OpenTelemetry (OTel). OTel is the open standard that most tracing tools accept, including Jaeger, Grafana Tempo, Honeycomb, Datadog, Azure Monitor and Langfuse.

Each request becomes one trace:

POST /v1/chat/completions
└─ agent run
   ├─ model call          model name, tokens in/out
   ├─ tool call: fetch    tool name, ok/failed
   └─ model call

Use the OpenTelemetry GenAI attribute names (gen_ai.*) so tracing tools display these steps well.

Rules
  • Off unless asked. Tracing runs only when the Agentkitfile sets the field and the named env var has a value. If the field is set but the env var is empty, start normally with tracing off and log one line saying so.
  • No message content. Spans never include prompts, answers, tool arguments or tool results, because they can hold private data. Optional content recording can come later.
  • No raw error text from frameworks or model providers. This is the same rule the API errors follow. Record the safe error code instead, such as ModelUpstreamError.
  • Standard OTel env vars work as usual:
    • OTEL_SERVICE_NAME, which defaults to the agent's metadata.name;
    • OTEL_RESOURCE_ATTRIBUTES;
    • OTEL_EXPORTER_OTLP_HEADERS;
    • the sampling settings.
  • Join the caller's trace. If the caller sends a traceparent header, the agent's spans join the caller's trace.
  • Never break or slow a request. Send spans in the background. If the collector is down, drop them.
  • Keep OTel settings away from tools. Tool processes must not get the OTel env vars, because OTEL_EXPORTER_OTLP_HEADERS can contain tokens. The existing tool env allowlist already prevents this; keep it that way.
  • Off in acp and agentsessions modes. Those modes have strict rules about outgoing network access.

The capability system already supports adding this one runtime at a time: a runtime lists otel-export only once it supports it. Start with pydantic-ai and Microsoft Agent Framework, which have OTel support built in. LangGraph can follow in a separate PR.

Out of scope
  • Metrics and logs. This issue covers traces only, and observability.logs.levelEnv stays rejected.
  • Recording prompt or answer content.
  • Setup specific to Foundry or Application Insights.
  • Sending over gRPC. Start with OTLP over HTTP (port 4318), which avoids pulling in grpcio.

Why

  • Debugging: see which step was slow or failed.
  • Cost: see token use per request and per model call.
  • Production use: most teams won't run a service they can't trace.
  • Low effort: all three frameworks already support OTel, so most of the work is connecting it.

How

Where things are
File What it does
pkg/agentkit/runtimes/catalog.go and runtimes/catalog/<runtime>.yaml Each runtime's capability list. Add otel-export once a runtime supports it. A Go test keeps the two lists in sync.
pkg/agentkit/config/validate.go Already requires otel-export when observability.otel.endpointEnv is set. No change needed.
runtimes/common/agentkit_serve_common/config.py ObservabilityOTelSpec rejects the field. Remove that rejection and keep the env-name check.
runtimes/common/agentkit_serve_common/cli.py Process startup for every protocol mode. Set up tracing here, before the server starts.
runtimes/common/agentkit_serve_common/server.py The OpenAI server. Wrap each request in a span here.
runtimes/<runtime>/agentkit_serve/agent_factory.py Where each framework is set up. Turn on its tracing here.
runtimes/common/agentkit_serve_common/parity.py A fake model server plus shared runtime tests. Use it to check spans without network access.
Steps
  1. Shared setup. Add runtimes/common/agentkit_serve_common/telemetry.py with a setup_tracing(spec) function:
    • Read the env var named by spec.observability.otel.endpoint_env. If it's empty, return and leave tracing off.
    • Otherwise:
      • create a TracerProvider with service.name taken from OTEL_SERVICE_NAME, or the agent name if that's not set;
      • add a BatchSpanProcessor that wraps the HTTP OTLPSpanExporter;
      • set the provider as the global one.
    • Treat the value like OTEL_EXPORTER_OTLP_ENDPOINT: a base URL such as http://collector:4318. Add /v1/traces yourself, because the exporter doesn't add it when you pass endpoint= directly.
    • Flush spans on shutdown so the last ones get sent.
    • The shared package must not import any agent framework. Keep framework code in the runtime packages.
  2. Request spans. In openai mode, give each request a span. opentelemetry-instrumentation-fastapi does this and also handles traceparent. Don't record request bodies or the Authorization header.
  3. Framework spans. In each runtime, turn these on only when tracing is on:
    • pydantic-ai: use its built-in instrumentation (instrument= / InstrumentationSettings) with content recording off (include_content=False). Check the exact names in the pinned pydantic-ai version.
    • Microsoft Agent Framework: use the agent_framework.observability module, for example enable_instrumentation, with sensitive data off. Don't let MAF create its own exporters; use the provider from step 1. Check the exact functions in the pinned version, since they have changed between releases.
    • LangGraph (later PR): it has no built-in OTel, so it needs an instrumentation package. Options are opentelemetry-instrumentation-langchain (OpenLLMetry) or openinference-instrumentation-langchain. Pick one that uses gen_ai.* names and can hide content, and explain the choice in the PR.
  4. Capabilities. Add otel-export to the Go catalog and the YAML catalog for each runtime you finish.
  5. Dependencies. Add opentelemetry-sdk and opentelemetry-exporter-otlp-proto-http, plus the FastAPI instrumentation if you use it.
    • Give them version ranges like the existing dependencies.
    • CI also runs tests with the lowest allowed versions (see docs/development.md), so pick lower bounds that actually work.

Because tracing is set up once at startup, framework spans also show up in foundry and orka modes. This issue only requires the request span in openai mode.

Tests

Use InMemorySpanExporter from opentelemetry.sdk.trace.export.in_memory_span_exporter with the fake model in parity.py, so no network is needed.

  • Shape: one tool call produces the request → run → model call / tool call tree. Spans include the model name, token counts and the tool name.
  • Privacy: put a unique marker string in the prompt, the model reply, the tool result and a secret env var. Check that it appears in no span attribute or event. The parity suite already uses markers like this (_UNDECLARED_SECRET).
  • Failure: when the model returns 500, the span is marked as an error with ModelUpstreamError and contains no text from the upstream response.
  • Off by default: without the field, there are no spans and no exporter.
  • Empty env var: with the field set but the env var empty, the agent starts and produces no spans.
  • Joining a trace: with a traceparent header, the agent's spans use the caller's trace ID.
  • Go: the catalog sync test passes, and validation accepts endpointEnv for runtimes with otel-export and still rejects it for the others.

Run:

uv run --directory runtimes/common --extra dev pytest -q
cd runtimes/<runtime> && python -m pytest -q
go test ./...
make lint
Docs
  • docs/agentkitfile.md: add an observability.otel section with an example and the env vars that matter.
  • docs/runtime-capabilities.md: add otel-export to the supported runtimes in the table.
  • README.md: add a short "Trace agent runs" section that runs a local Jaeger, points the agent at it, and opens the trace.

Done when

  • For pydantic-ai and Microsoft Agent Framework, an agent built with observability.otel.endpointEnv and pointed at a local collector such as Jaeger shows one trace per request, with model and tool steps.
  • No prompt, answer, tool data or secret appears in any span.
  • Without the field, or with the env var empty, nothing changes.
  • otel-export is listed for the runtimes that support it, and the build still rejects it for the others.
Dominant language
Python
Stars
7
Forks
5
Avg merge
3h 39m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from orka-agents/agentkit

All issues in orka-agents/agentkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.