Skip to content
Changelog

Keep run, session and agent IDs in traces on newer FastAPI

October 29, 20261 min read

Your Agno traces lost their run, session and agent IDs once FastAPI 0.142.0 began tracing requests by default. AgentOS(tracing=True) installs the global tracer provider that switches this on, so every run sat under a request span, the Runs view broke, and each UI request stored a trace of its own.

AgentOS now turns off FastAPI tracing on the app it builds, and setup_tracing() filters out spans from other libraries so the stored trace starts at the Agno run. Upgrading is the whole fix.

We sent one run, GET /sessions and GET /health through FastAPI's TestClient on FastAPI 0.162.0, with ScriptedModel as a stand-in for a real model. Earlier releases stored one trace per request, three in all, with empty run, session and agent IDs. This release stores one, named after the run. Real output:

Before: name='fastapi.dependencies' run_id=None session_id=None agent_id=None
Now:    name='Weather_Agent.arun' run_id='c6bc283f-d328-449e-ab9e-781269be5ae8' session_id='s1' agent_id='weather-agent'

The filter also covers a custom base_app, where FastAPI tracing stays on. In the same test, that app stored only Weather_Agent.arun. Apps without tracing=True keep FastAPI's defaults, so request spans can still reach your own backend.

See the cookbook, and learn more about AgentOS tracing in the documentation.

Frequently asked questions

FastAPI 0.142.0 starts its own OpenTelemetry tracing once a global tracer provider exists, and AgentOS(tracing=True) installs one. Each run became a child of the request span, and the stored trace took its name from the first span to finish, FastAPI's dependency span, with its run, session and agent IDs left empty. A stored trace from an earlier release read name='fastapi.dependencies' run_id=None session_id=None agent_id=None.

No. Those stored traces keep the old name and empty context. Traces recorded after the upgrade carry the name and identifiers of the Agno run.

A span you create inside a tool during a run stays in the trace. A top-level span outside any Agno run is dropped from the Agno database once setup_tracing() filters the provider.

AgentOS opts out only on the app it builds, with tracing=True, on a FastAPI version that accepts telemetry, and when Agno installed the tracer provider. An app without tracing=True or with its own provider keeps FastAPI request spans, and a custom base_app keeps them too while the Agno filter holds them out of the Agno database.

Shipped around the same time