fix(starlette): Stop duplicating scope["root_path"] in URLs#6579
4 issues
code-review: Found 4 issues (3 medium, 1 low)
Medium
Quart integration silently drops all monitoring when `package_version()` returns None - `sentry_sdk/integrations/quart.py:95-98`
If package_version("quart") returns None (e.g. package metadata is unavailable in a bundled/frozen app), the new or version is None guard causes the patched ASGI app to silently bypass the Sentry middleware entirely, losing all request monitoring. Consider falling back to a safe default (e.g. path_includes_root_path=False) instead of skipping the middleware.
test_request_url fails on Django 3.0–5.0 due to version-unaware path assertion - `tests/integrations/django/asgi/test_asgi.py:1085-1101`
The test passes scope["path"] = "/root/nomessage" together with scope["root_path"] = "/root", but for Django < 5.1 the SDK uses path_includes_root_path=False, which prepends root_path to path, yielding "/root/root/nomessage" — not the asserted "/root/nomessage". Either restrict the test to django.VERSION >= (5, 1) or use path "/nomessage" (without the root prefix) so that root_path + path gives the expected URL on all versions.
Also found at:
sentry_sdk/integrations/django/asgi.py:103
test_request_url does not exercise the root_path duplication fix for Starlette - `tests/integrations/starlette/test_starlette.py:1486-1525`
The test uses TestClient with its default root_path="", so the Sentry middleware (which wraps Starlette.__call__ and captures the outer ASGI scope) always sees root_path="". With an empty root_path, the path_includes_root_path flag makes no difference and the duplication bug is never triggered. Consider using TestClient(starlette_app, root_path="/root") with a route at /nomessage (similar to the Quart test which passes root_path="/root" in the request) to actually exercise the fix.
Also found at:
tests/integrations/quart/test_quart.py:1021
Low
Default `path_includes_root_path=True` changes URL behavior for direct `SentryAsgiMiddleware` users on non-spec-compliant frameworks - `sentry_sdk/integrations/_asgi_common.py:35`
The new default path_includes_root_path=True makes _get_url() use scope["path"] directly instead of always prepending scope["root_path"]. This is correct for ASGI-spec-compliant frameworks (it fixes the previous root_path duplication). However, a user who wires SentryAsgiMiddleware directly around a non-spec-compliant framework (where scope["path"] does NOT contain scope["root_path"]) will now see root_path dropped from reported URLs/transaction names — a behavioral change. The built-in integrations for the known non-compliant frameworks (Starlite, Litestar, old Starlette/Quart) pass path_includes_root_path=False, so they are unaffected. The mitigation for direct users is to pass path_includes_root_path=False explicitly, but this is not documented as a migration step in the PR. Consider noting this in the changelog/docs.
Also found at:
sentry_sdk/integrations/asgi.py:462
⏱ 9m 11s · 2.6M in / 110.1k out · $3.74
Annotations
Check warning on line 98 in sentry_sdk/integrations/quart.py
sentry-warden / warden: code-review
Quart integration silently drops all monitoring when `package_version()` returns None
If `package_version("quart")` returns `None` (e.g. package metadata is unavailable in a bundled/frozen app), the new `or version is None` guard causes the patched ASGI app to silently bypass the Sentry middleware entirely, losing all request monitoring. Consider falling back to a safe default (e.g. `path_includes_root_path=False`) instead of skipping the middleware.
Check warning on line 1101 in tests/integrations/django/asgi/test_asgi.py
sentry-warden / warden: code-review
test_request_url fails on Django 3.0–5.0 due to version-unaware path assertion
The test passes `scope["path"] = "/root/nomessage"` together with `scope["root_path"] = "/root"`, but for Django < 5.1 the SDK uses `path_includes_root_path=False`, which prepends `root_path` to `path`, yielding `"/root/root/nomessage"` — not the asserted `"/root/nomessage"`. Either restrict the test to `django.VERSION >= (5, 1)` or use path `"/nomessage"` (without the root prefix) so that `root_path + path` gives the expected URL on all versions.
Check warning on line 103 in sentry_sdk/integrations/django/asgi.py
sentry-warden / warden: code-review
[8KA-TNT] test_request_url fails on Django 3.0–5.0 due to version-unaware path assertion (additional location)
The test passes `scope["path"] = "/root/nomessage"` together with `scope["root_path"] = "/root"`, but for Django < 5.1 the SDK uses `path_includes_root_path=False`, which prepends `root_path` to `path`, yielding `"/root/root/nomessage"` — not the asserted `"/root/nomessage"`. Either restrict the test to `django.VERSION >= (5, 1)` or use path `"/nomessage"` (without the root prefix) so that `root_path + path` gives the expected URL on all versions.
Check warning on line 1525 in tests/integrations/starlette/test_starlette.py
sentry-warden / warden: code-review
test_request_url does not exercise the root_path duplication fix for Starlette
The test uses `TestClient` with its default `root_path=""`, so the Sentry middleware (which wraps `Starlette.__call__` and captures the outer ASGI scope) always sees `root_path=""`. With an empty root_path, the `path_includes_root_path` flag makes no difference and the duplication bug is never triggered. Consider using `TestClient(starlette_app, root_path="/root")` with a route at `/nomessage` (similar to the Quart test which passes `root_path="/root"` in the request) to actually exercise the fix.
Check warning on line 1021 in tests/integrations/quart/test_quart.py
sentry-warden / warden: code-review
[KML-HJY] test_request_url does not exercise the root_path duplication fix for Starlette (additional location)
The test uses `TestClient` with its default `root_path=""`, so the Sentry middleware (which wraps `Starlette.__call__` and captures the outer ASGI scope) always sees `root_path=""`. With an empty root_path, the `path_includes_root_path` flag makes no difference and the duplication bug is never triggered. Consider using `TestClient(starlette_app, root_path="/root")` with a route at `/nomessage` (similar to the Quart test which passes `root_path="/root"` in the request) to actually exercise the fix.