# Apm-agent-python: FastAPI ≥0.137 breaks ElasticAPM middleware - AttributeError "'\_IncludedRouter' object has no attribute 'path'"

**URL:** <https://discuss.elastic.co/t/apm-agent-python-fastapi-0-137-breaks-elasticapm-middleware-attributeerror-includedrouter-object-has-no-attribute-path/387112>\
**Category:** APM\
**Tags:** python\
**Created:** [June 22, 2026, 10:21am UTC](https://discuss.elastic.co/t/apm-agent-python-fastapi-0-137-breaks-elasticapm-middleware-attributeerror-includedrouter-object-has-no-attribute-path/387112 "2026-06-22T10:21:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sophie\_Clark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sophie_clark/32/147706_2.png) [@Sophie\_Clark](https://discuss.elastic.co/u/Sophie_Clark)\
**Post date:** [June 22, 2026, 10:21am UTC](https://discuss.elastic.co/t/apm-agent-python-fastapi-0-137-breaks-elasticapm-middleware-attributeerror-includedrouter-object-has-no-attribute-path/387112/1 "2026-06-22T10:21:48Z")

</div>

**APM Agent language and version:** Python - elastic-apm (6.26.1). The bug affects all current releases (≤ 6.26.1): the newest agent (6.26.1, 25 May 2026) predates FastAPI 0.137.0 (14 Jun 2026), so no released version handles it.

The breakage was triggered when an unpinned FastAPI dependency resolved to ≥ 0.137.0 on an image rebuild.

**Is there anything special in your setup?** Standard FastAPI app. Two relevant details: (1) we run FastAPI ≥ 0.137.0 (the trigger), and (2) we register routers via many `app.include_router(...)` calls. APM is enabled with `app.add_middleware(ElasticAPM, ...)`. Nothing unusual in the APM transport/output.

**Description of the problem including expected versus actual behavior:**

Since FastAPI 0.137.0, the Starlette/FastAPI middleware raises `AttributeError: '_IncludedRouter' object has no attribute 'path'` on every request that matches a route registered via `include_router(...)`, returning HTTP 500.

The middleware's `get_route_name()` → `_get_route_name()` (in elasticapm/contrib/starlette/\__init_\_.py) iterates `app.routes` and reads `route.path`. FastAPI 0.137.0 ( [♻️ Refactor internals to preserve `APIRouter` and `APIRoute` instances by tiangolo · Pull Request #15745 · fastapi/fastapi · GitHub](https://github.com/fastapi/fastapi/pull/15745) ) changed include\_router() so app.routes no longer contains flat APIRoute objects with .path; it now contains \_IncludedRouter wrappers that match lazily and have no .path ( [0.137.0: how to get all paths of a router? · fastapi/fastapi · Discussion #15782 · GitHub](https://github.com/fastapi/fastapi/discussions/15782) ).

Expected: 200; transaction named by the route template (e.g. GET /items).

Actual: 500 on every matched request — the agent's route-name resolution throws before the endpoint runs

**Steps to reproduce:**

1. Install fastapi\>=0.137.0 and elastic-apm.
2. Create an app that includes a router and adds the ElasticAPM middleware (below).
3. Send any request matching a route in the included router → 500.

```python
from elasticapm.contrib.starlette import ElasticAPM, make_apm_client
from fastapi import APIRouter, FastAPI
from starlette.testclient import TestClient

router = APIRouter()

@router.get("/items")
def items():
    return {"ok": True}

app = FastAPI()
app.include_router(router) # FastAPI >=0.137 -> _IncludedRouter (no .path) in app.routes

apm = make_apm_client({"SERVICE_NAME": "repro", "DISABLE_SEND": True})
app.add_middleware(ElasticAPM, client=apm)

print(TestClient(app, raise_server_exceptions=False).get("/items").status_code)
# 500 on FastAPI >=0.137.0, 200 on <0.137.0

```

**Provide logs and/or server output (if relevant):**

```kibana
File ".../elasticapm/contrib/starlette/ __init__.py", line 244, in _request_started

    transaction_name = self.get_route_name(request) or request.url.path

File ".../elasticapm/contrib/starlette/ __init__.py", line 251, in get_route_name

    route_name = self._get_route_name(scope, routes)

File ".../elasticapm/contrib/starlette/ __init__.py", line 274, in _get_route_name

    route_name = route.path

AttributeError: '_IncludedRouter' object has no attribute 'path'

```

Pinning Fast API pre 0.137.0 to avoid the issue for now. However, would be good if **elastic-apm** adopts FastAPI's new `fastapi.routing.iter_route_contexts()` to fix the dependency issue or recurse into the wrapper's child routes like the existing `Mount` branch. Same break is hitting OpenTelemetry, prometheus-fastapi-instrumentator ( [AttributeError: '\_IncludedRouter' object has no attribute 'path' with FastAPI 0.137.0 · Issue #370 · trallnag/prometheus-fastapi-instrumentator · GitHub](https://github.com/trallnag/prometheus-fastapi-instrumentator/issues/370) ), and vLLM ([[Bug]: vLLM 0.23.0 API server returns HTTP 500 on /v1/models due to prometheus\_fastapi\_instrumentator AttributeError: '\_IncludedRouter' object has no attribute 'path' · Issue #45596 · vllm-project/vllm · GitHub](https://github.com/vllm-project/vllm/issues/45596)).

---

<div class="post-metadata">

**Author:** ![riccardom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/riccardom/32/132044_2.png) [@riccardom](https://discuss.elastic.co/u/riccardom)\
**Post date:** [June 22, 2026, 10:30am UTC](https://discuss.elastic.co/t/apm-agent-python-fastapi-0-137-breaks-elasticapm-middleware-attributeerror-includedrouter-object-has-no-attribute-path/387112/2 "2026-06-22T10:30:28Z")

</div>

Hello Sophie, FastAPI 137.0 introduced some breaking changes in their routing, we are going to cut a 6.26.2 release handling the changes.

BTW for reporting issues I suggest to take a look at github, this has been reported in [FastAPI 0.137 regression: Elastic APM Starlette middleware crashes on \_IncludedRouter (path missing) · Issue #2681 · elastic/apm-agent-python · GitHub](https://github.com/elastic/apm-agent-python/issues/2681)

---

<div class="post-metadata">

**Author:** ![riccardom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/riccardom/32/132044_2.png) [@riccardom](https://discuss.elastic.co/u/riccardom)\
**Post date:** [June 23, 2026, 7:25am UTC](https://discuss.elastic.co/t/apm-agent-python-fastapi-0-137-breaks-elasticapm-middleware-attributeerror-includedrouter-object-has-no-attribute-path/387112/3 "2026-06-23T07:25:06Z")

</div>

elastic-apm 6.26.2 has been released yesterday, please update.
