feat(runtime): export OpenTelemetry traces for agent runs
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend-api-design, observability
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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'smetadata.name;OTEL_RESOURCE_ATTRIBUTES;OTEL_EXPORTER_OTLP_HEADERS;- the sampling settings.
- Join the caller's trace. If the caller sends a
traceparentheader, 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_HEADERScan contain tokens. The existing tool env allowlist already prevents this; keep it that way. - Off in
acpandagentsessionsmodes. 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.levelEnvstays 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
- Shared setup. Add
runtimes/common/agentkit_serve_common/telemetry.pywith asetup_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
TracerProviderwithservice.nametaken fromOTEL_SERVICE_NAME, or the agent name if that's not set; - add a
BatchSpanProcessorthat wraps the HTTPOTLPSpanExporter; - set the provider as the global one.
- create a
- Treat the value like
OTEL_EXPORTER_OTLP_ENDPOINT: a base URL such ashttp://collector:4318. Add/v1/tracesyourself, because the exporter doesn't add it when you passendpoint=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.
- Read the env var named by
- Request spans. In
openaimode, give each request a span.opentelemetry-instrumentation-fastapidoes this and also handlestraceparent. Don't record request bodies or theAuthorizationheader. - 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.observabilitymodule, for exampleenable_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) oropeninference-instrumentation-langchain. Pick one that usesgen_ai.*names and can hide content, and explain the choice in the PR.
- pydantic-ai: use its built-in instrumentation (
- Capabilities. Add
otel-exportto the Go catalog and the YAML catalog for each runtime you finish. - Dependencies. Add
opentelemetry-sdkandopentelemetry-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
ModelUpstreamErrorand 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
traceparentheader, the agent's spans use the caller's trace ID. - Go: the catalog sync test passes, and validation accepts
endpointEnvfor runtimes withotel-exportand 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 anobservability.otelsection with an example and the env vars that matter.docs/runtime-capabilities.md: addotel-exportto 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.endpointEnvand 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-exportis listed for the runtimes that support it, and the build still rejects it for the others.
- Lingua principale
- Python
- Stelle
- 7
- Fork
- 5
- Merge medio
- 3h 39m
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di orka-agents/agentkit
-
fix(pydantic-ai): CI fails with newest pydantic-ai (unexpected 'history' argument)Forse già presa @gambtho l’ha presa 30 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
orka-agents/agentkit#77 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
orka-agents/agentkit#76 · 3 commenti ·
-
area/build area/orka area/runtime blocked enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
orka-agents/agentkit#69 ·
-
area/build area/orka area/runtime enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
orka-agents/agentkit#68 ·
-
area/build enhancement testing
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
orka-agents/agentkit#65 ·
Tutte le issue di orka-agents/agentkit
Issue simili
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Apertaenhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
DaoCloud/DaoCloud-docs#7839 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
sav-oss-org/ptusa_main#1610 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug status/accepted type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
microsoft/apm#4925 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sagemathinc/sagebrush#1701 ·
I maintainer di solito rispondono entro 1 giorno