Skip to content

fix(asgi): Stop duplicating scope["root_path"] in URLs#6579

Open
alexander-alderman-webb wants to merge 12 commits into
masterfrom
webb/asgi/double-mount-prefix
Open

fix(asgi): Stop duplicating scope["root_path"] in URLs#6579
alexander-alderman-webb wants to merge 12 commits into
masterfrom
webb/asgi/double-mount-prefix

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Description

Add the path_includes_root_path boolean parameter to _get_url() and related functions.

If the parameter is True (the default), scope["path"] is considered to include scope["root_path"], where scope is the ASGI scope. Otherwise, the existing behavior that prepends scope["root_path"] when forming the url is preserved.

Add tests to each ASGI-based integration. Some are compliant with the ASGI spec in which scope["path"] includes scope["root_path"], while others are not. In particular, Starlite, LiterStar and old versions of Starlette and Quart are not compliant with the spec. In these cases, path_includes_root_path=False is set.

Issues

Closes #6577

Reminders

Comment thread sentry_sdk/integrations/_asgi_common.py
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90998 passed | ⏭️ 6135 skipped | Total: 97133 | Pass Rate: 93.68% | Execution Time: 318m 48s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +178
Passed Tests 📈 +172
Failed Tests
Skipped Tests 📈 +6

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2409 uncovered lines.
✅ Project coverage is 89.86%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/quart.py 100.00% ⚠️ 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.85%    89.86%    +0.01%
==========================================
  Files          192       192         —
  Lines        23745     23748        +3
  Branches      8198      8198         —
==========================================
+ Hits         21334     21339        +5
- Misses        2411      2409        -2
- Partials      1344      1344         —

Generated by Codecov Action

Comment thread tests/integrations/starlette/test_starlette.py
Comment thread tests/integrations/starlite/test_starlite.py
Comment thread tests/integrations/litestar/test_litestar.py
Comment thread sentry_sdk/integrations/asgi.py
Comment thread tests/integrations/django/asgi/test_asgi.py
@alexander-alderman-webb alexander-alderman-webb changed the title fix(asgi): Stop duplicating root_path in URLs fix(asgi): Stop duplicating scope["root_path"] in URLs Jun 19, 2026
Comment thread sentry_sdk/integrations/quart.py
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review June 19, 2026 12:51
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner June 19, 2026 12:51

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b420587. Configure here.

Comment thread sentry_sdk/integrations/quart.py
Comment thread sentry_sdk/integrations/quart.py

@wahajahmed010 wahajahmed010 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #6579

Summary: Clean fix for ASGI URL duplication when scope["root_path"] is already included in scope["path"]. The approach is sound — thread a path_includes_root_path boolean through the URL construction pipeline.

✅ What works well

  • Backward compatible — default is True, preserving existing behavior for frameworks that don't include root_path in path
  • Framework-specific handling — correctly version-gated for Starlette (>=0.33), Quart (>=0.19), and hardcoded for Litestar/Starlite
  • Test coverage — all 6 integrations tested (Django ASGI, FastAPI, Litestar, Quart, Starlette, Starlite), both span streaming and static lifecycle modes
  • Clean threading — parameter flows through _get_url_get_request_data_get_request_attributes_get_transaction_name_and_source_get_segment_name_and_source

⚠️ Potential issues

  1. Django ASGI test — The test sets comm.scope["root_path"] = "/root" but Django defaults to path_includes_root_path=True. Does Django ASGI actually include root_path in path? If not, this test might pass but produce incorrect URLs in production. Worth verifying Django's ASGI behavior.
  2. No test for path_includes_root_path=False — The Starlette/FastAPI tests only exercise the True path (Starlette >= 0.33). The old behavior (False) has no dedicated test.
  3. Edge case: empty path — When path_includes_root_path=True and scope["path"] is empty, the URL would be just scheme+host with no path. Unlikely but worth noting.

Verdict

Solid PR. The core logic is correct and well-structured. The main risk is the Django default assumption — worth double-checking before merging.

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.

ASGI integration doubles the mount prefix in request.url for Starlette Mounted sub-apps (root_path + path)

3 participants