Skip to content

[BUG]: FastAPI: http.route doubles request path (e.g. /segmentation/segmentation instead of /segmentation) #19314

Description

@agarov

Tracer Version(s)

4.11.0

Python Version(s)

3.12

Pip Version(s)

pip 25.0.1

Bug Report

Summary

The ddtrace FastAPI/Starlette integration constructs http.route by concatenating the request path with the route pattern, resulting in doubled resource names (e.g. POST /segmentation/segmentation instead of POST /segmentation).

Reproduction Code

import ddtrace.auto  # noqa: F401
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
    return {"message": "ok"}

@app.post("/segmentation")
def segmentation():
    return {"result": "done"}

@app.post("/inpaint")
def inpaint():
    return {"result": "done"}

Notes

Routes are defined directly on the FastAPI() app instance — no APIRouter prefix is used.
root_path is not set in the app, Dockerfile, or uvicorn config.
Datadog's own http.inferred_route and http.path_group attributes are correct (e.g. /segmentation), confirming the issue is in how ddtrace sets http.route.
Both fastapi and starlette integrations are auto-enabled via ddtrace.auto — could the two integrations be stacking the route path?

Error Logs

Evidence from spans

# POST /segmentation request
http.url: http://$DOMAIN/segmentation
http.url_details.path: /segmentation        # ✅ correct
http.inferred_route: /segmentation           # ✅ correct
http.path_group: /segmentation               # ✅ correct
http.route: /segmentation/segmentation       # ❌ doubled
resource_name: POST /segmentation/segmentation  # ❌ doubled

# GET / health check
http.url: http://$DOMAIN/
http.url_details.path: /                     # ✅ correct
http.inferred_route: /                       # ✅ correct
http.route: //                               # ❌ doubled
resource_name: GET //                        # ❌ doubled

Libraries in Use

FastAPI: 0.138.0

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions