Skip to content

Trace exclusions match anywhere in the URL, and miss the Litestar health check #156

Open
1 of 2 issues completed

Description

@lesnik512

opentelemetry_exclude_urls (default ["/metrics"]) and the health-check path added by define_exclude_urls() reach OpenTelemetry's ExcludeList and Litestar's exclude as bare strings. Both search them unanchored, so a route merely containing one loses its span. On Litestar the opposite also happens: /health/ never matches, because Litestar strips the trailing slash from scope["path"].

Reproduction on main (2e3c8e2), each bootstrapper with opentelemetry_generate_health_check_spans=False, an in-memory exporter, and routes /api/metrics-report and /api/health/details (both 200):

/api/metrics-report /api/health/details /health/
FastAPI no span no span excluded
FastMCP no span no span excluded
Litestar no span no span traced as GET /health

modern-python/lite-bootstrap fixed the same thing (modern-python/lite-bootstrap#248, modern-python/lite-bootstrap#282) by anchoring only the paths the library itself derives, keeping the trailing slash optional: ^\w+://[^/]*{re.escape(path.rstrip("/"))}(?:/|$) for ExcludeList, which sees the full URL, and ^{re.escape(path.rstrip("/"))}(?:/|$) for Litestar's exclude, which sees the path. User-supplied regexes stay verbatim. Here the default "/metrics" lives in the user-facing list, so it would need to become an anchored pattern too, or the metrics path could be derived from the Prometheus settings instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions