Skip to content

fix(logging): record the complete request path for variant endpoints - #862

Open
davereinhart wants to merge 1 commit into
release-2026.3.0from
fix/davereinhart/logging-full-path
Open

fix(logging): record the complete request path for variant endpoints#862
davereinhart wants to merge 1 commit into
release-2026.3.0from
fix/davereinhart/logging-full-path

Conversation

@davereinhart

Copy link
Copy Markdown
Collaborator

This pull request updates how the request path is logged in the context for incoming requests. Instead of using request.url.path, which could incorrectly truncate paths at the # character, it now uses the ASGI scope's path directly to ensure the full path is captured. This change addresses an issue where different /variants routes were being logged as the same path.

Logging improvements:

  • Updated the set_context method in context.py to use request.scope["path"] instead of request.url.path for more accurate logging of request paths, especially for variant URNs containing # characters.

PopulatedRawContextMiddleware took the request path from request.url.path. Starlette builds that URL
by reassembling the scope into a string and re-parsing it, so urlsplit reads everything after the
first '#' as a fragment. A variant URN is {score_set_urn}#{n}, which means the path in the canonical
log line stopped at the score set: the variant number and the sub-resource were both dropped, and so
was the query string, which sits after the '#' in the reassembled string. /variants/{urn},
/variants/{urn}/csv and /variants/{urn}/csv-namespaces logged one indistinguishable path, and no log
line recorded which variant had been asked for.

Read the path from the ASGI scope, which arrives percent-decoded and whole. ASGI guarantees 'path' on
both http and websocket scopes, so this needs none of the defensiveness the method read below it
carries, where only an http scope has the key.

Nothing reads this context key. log_request serializes the context into the "Request completed." line
and no behaviour depends on the value, so the change is confined to what the logs say.
lib/slack.py interpolates request.url whole, and URL.__str__ returns the unparsed string, so the
fragment survives there and it was never affected.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33686096846

Warning

No base build found for commit 5aefb34 on release-2026.3.0.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 88.841%

Details

  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15611
Covered Lines: 13869
Line Coverage: 88.84%
Coverage Strength: 0.89 hits per line

💛 - Coveralls

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.

2 participants