Skip to content

Fix timing metric names for included FastAPI routers - #384

Open
2836048681 wants to merge 1 commit into
fastapiutils:masterfrom
2836048681:fix/382-timing-included-routes
Open

2836048681 wants to merge 1 commit into
fastapiutils:masterfrom
2836048681:fix/382-timing-included-routes

Conversation

@2836048681

Copy link
Copy Markdown

Fixes #382.

Starting with FastAPI 0.137, a request to a route registered with include_router() can be logged as <Path: /v1/items/42>. The middleware now follows the matched router to the endpoint so intermediate and final records use the configured route name, such as api.app.views.read_item.

The lookup uses FastAPI's included router matcher to preserve router prefixes, route order, and path converters. FastAPI 0.137.0 returns the router wrapper from the top-level match, so the lookup uses its internal matcher to find the endpoint. Older FastAPI versions continue to use a flat route list.

The regression test makes a request through two nested routers with prefixes and verifies both timing records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] FastAPI 0.137.0 breaks fastapiutils

1 participant