fix(Laravel): fix incorrect URL path construction in httpTarget()#607
Merged
ChrisLightfootWild merged 2 commits intoJun 10, 2026
Conversation
The original code had two bugs caused by PHP operator precedence:
1. The string concatenation operator (.) has higher precedence than the
strict equality operator (===), so the expression:
$request->getBaseUrl() . $request->getPathInfo() === '/' ? '/?' : '?'
was evaluated as:
($request->getBaseUrl() . $request->getPathInfo()) === '/' ? '/?' : '?'
This made $question equal to '/?' only when the full concatenated path
was exactly '/', not just when getPathInfo() returned '/'.
2. The return statement used $request->path(), which in Laravel strips the
leading slash for non-root paths (e.g. '/hello' becomes 'foo'), and for
the root path '/' combined with the '/?' separator would produce '//?' .
These bugs resulted in:
- Root path with query: '/' + '/?' + query => '//?query' (double slash)
- Non-root path with query: 'foo' + '?' + query => 'foo?query' (missing leading slash)
Fix by using getBaseUrl() . getPathInfo() consistently as the base path
and appending the query string with a plain '?', which correctly produces:
- Root path with query: '/?query'
- Non-root path with query: '/hello?query'
The httpTarget() method in the Kernel hook was previously untested, which allowed the operator precedence bug to go undetected. Add four integration tests that verify the URL_PATH span attribute is correctly set for each path pattern: - test_url_path_root: GET / => URL_PATH = '/' - test_url_path_non_root: GET /hello => URL_PATH = '/hello' - test_url_path_root_with_query_string: GET /?foo=bar => URL_PATH = '/?foo=bar' - test_url_path_with_query_string: GET /hello?foo=bar => URL_PATH = '/hello?foo=bar' Before the fix, test_url_path_root_with_query_string would have produced '//?foo=bar' (double slash) and test_url_path_with_query_string would have produced 'foo?foo=bar' (missing leading slash).
zigzagdev
marked this pull request as draft
June 9, 2026 11:22
zigzagdev
marked this pull request as ready for review
June 9, 2026 11:28
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
=========================================
Coverage 81.09% 81.09%
Complexity 1521 1521
=========================================
Files 93 93
Lines 5431 5431
=========================================
Hits 4404 4404
Misses 1027 1027 Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
ChrisLightfootWild
approved these changes
Jun 10, 2026
ChrisLightfootWild
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix @zigzagdev 👍
ChrisLightfootWild
merged commit Jun 10, 2026
31ba9f7
into
open-telemetry:main
128 of 175 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Content
httpTarget()where.(concatenation) has higher precedence than===(strict equality). This caused incorrect path construction when appending query strings.$request->path()(which strips the leading slash in Laravel) with a robust combination of$request->getBaseUrl() . $request->getPathInfo().Cause
The original code was evaluated incorrectly due to operator precedence:
This caused the following incorrect behaviors:
/?foo=bar→ URL_PATH =//?foo=bar(double slash)/hello?foo=bar→ URL_PATH =foo?foo=bar(missing leading slash)Fixed code:
Test Results