Runner OTLP Trace Export Authentication#
The Agenta SDK (used by runners) exports OpenTelemetry spans to a platform-hosted OTLP endpoint. Authentication for those exports happens in two layers: a static API key set at init time, and per-trace credentials resolved dynamically from platform authorization on each incoming run request.
Endpoint and Host Resolution#
At ag.init(), the SDK selects the Agenta host using this priority order :
- Explicit
hostargument AGENTA_HOSTenv varbackend_host/hostfrom config fileAGENTA_API_URLenv var (default:https://cloud.agenta.ai)
The selected value is passed through parse_url(), which:
- Strips a trailing
/and a trailing/apipath segment - Rewrites
localhosttohost.docker.internalwhenDOCKER_NETWORK_MODE=bridge - Returns
AGENTA_API_INTERNAL_URLwhen set and host containslocalhost
The OTLP traces endpoint is then constructed as {host}/api/otlp/v1/traces .
Known bugs in parse_url / host derivation — see Known Issues below.
Static API Key (Init-time)#
If an api_key is provided (or AGENTA_API_KEY is set), Tracing.configure() adds it as a static Authorization: ApiKey <key> header for all OTLP exports . This header is attached to every export request regardless of per-trace credentials.
Per-trace Credential Flow#
For runners deployed as FastAPI services, the SDK attaches AuthMiddleware, which performs a credential check on every incoming run request:
- Middleware intercepts the request, reads
Authorizationheaders /sAccessTokencookies, and calls{host}/api/permissions/verify. - Platform returns
{"effect": "allow", "credentials": "<token>"}on success . Non-alloweffects raise aDenyException. - Credentials are stored on
request.state.authand propagated intoTracingContext. - At span start, the
instrumentdecorator reads credentials fromTracingContextand stores them in a TTL/LRU cache keyed bytrace_id. The cache has a 1-hour TTL . - At export,
OTLPExporter.export()groups spans by trace ID, looks up credentials from the cache per trace, and calls_export()in an exporting context per credential group . The_export()method setsAuthorization: <credentials>on the HTTP session when credentials are present .
If the permission check returns no credential (or the request has no auth), credentials is None and spans for that trace are exported without an Authorization header override (the static API key header, if configured, still applies).
Known Issues#
Three related bugs have been filed against host derivation and credential attachment:
#6787 — Unanchored /api strip breaks hosts named api
parse_url() calls url.endswith("/api") , which is an improvement over the original rsplit("/api", 1) pattern described in the issue — but the issue notes the original unanchored rsplit in an older init.py would match //api inside http://api:8000, producing a malformed host and a broken OTLP endpoint. Verify the current parse_url is what is actually running in your deployment.
#6880 — Strict proxy: duplicated /api or missing port
When the API URL already contains a path (e.g., http://proxy/api), the stripped host becomes http://proxy and the OTLP URL becomes http://proxy/api/otlp/v1/traces — correct in this case — but edge cases with ports or /api appearing elsewhere in the path can produce a malformed endpoint. The runner's OTLP export silently skips if setup fails .
#6439 — 127.0.0.1 not rewritten for sandboxed runs
parse_url() rewrites localhost but not 127.0.0.1 . A self-hosted deployment using AGENTA_API_URL=http://127.0.0.1:... will hand that loopback address unchanged into a sandboxed runner, making the OTLP endpoint unreachable and causing credential resolution to fail.
Key Source Files#
| File | Role |
|---|---|
sdk/agenta/sdk/agenta_init.py | Host resolution, OTLP URL construction, ag.init() |
sdk/agenta/sdk/utils/helpers.py | parse_url() — normalization and localhost rewriting |
sdk/agenta/sdk/tracing/tracing.py | Tracing.configure(), credentials TTL cache |
sdk/agenta/sdk/tracing/exporters.py | OTLPExporter — per-trace credential grouping and Authorization header injection |
sdk/agenta/sdk/middleware/auth.py | AuthMiddleware — permission verification, credential extraction |
sdk/agenta/sdk/decorators/tracing.py | instrument decorator — stores credentials in trace-ID cache |