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

> Agno `AgentOS(tracing=True)` stores traces named after the Agno run again on FastAPI 0.142.0 and later. AgentOS turns off FastAPI tracing on the app it builds, and `setup_tracing()` filters spans from other libraries.

- Published: 2026-10-29
- Author: Kaustubh Shukla
- Categories: Changelog
- Canonical: https://www.agno.com/blog/keep-run-session-and-agent-ids-in-traces-on-newer-fastapi
- Markdown: https://www.agno.com/blog/keep-run-session-and-agent-ids-in-traces-on-newer-fastapi.md

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:

```text
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](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/13_observability/read_traces.py), and learn more about [AgentOS tracing](https://docs.agno.com/agent-os/tracing/overview) in the documentation.
