-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Update default trace propagation targets logic in the browser #10621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
size-limit report 📦
|
33ecd22
to
cfca488
Compare
['https://not-my-origin.com/api', /api/, true], | ||
|
||
['/api', /^\/api/, true], // matches pathname | ||
['/api', /\/\/my-origin\.com\/api/, true], // matches full url |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['/api', /\/\/my-origin\.com\/api/, true], // matches full url | ||
['foobar', /\/foobar/, true], // matches full url | ||
['foobar', /^\/api\/foobar/, true], // full url match | ||
['some-url.com', /\/some-url\.com/, true], |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['foobar', /\/foobar/, true], // matches full url | ||
['foobar', /^\/api\/foobar/, true], // full url match | ||
['some-url.com', /\/some-url\.com/, true], | ||
['some-url.com', /^\/some-url\.com/, false], // does not match pathname or full url |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['foobar', /^\/api\/foobar/, true], // full url match | ||
['some-url.com', /\/some-url\.com/, true], | ||
['some-url.com', /^\/some-url\.com/, false], // does not match pathname or full url | ||
['some-url.com', /^\/api\/some-url\.com/, true], // matches pathname |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['https://not-my-origin.com/api', /api/, true], | ||
|
||
['/api', /^\/api/, true], | ||
['/api', /\/\/my-origin\.com\/api/, false], |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['/api', /\/\/my-origin\.com\/api/, false], | ||
['foobar', /\/foobar/, false], | ||
['foobar', /^\/api\/foobar/, false], | ||
['some-url.com', /\/some-url\.com/, false], |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['foobar', /\/foobar/, false], | ||
['foobar', /^\/api\/foobar/, false], | ||
['some-url.com', /\/some-url\.com/, false], | ||
['some-url.com', /^\/some-url\.com/, false], |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
['foobar', /^\/api\/foobar/, false], | ||
['some-url.com', /\/some-url\.com/, false], | ||
['some-url.com', /^\/some-url\.com/, false], | ||
['some-url.com', /^\/api\/some-url\.com/, false], |
Check failure
Code scanning / CodeQL
Missing regular expression anchor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I like this, feels super understandable as well instead of this default regex which is slightly confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great change - Good job!
Before this change, the default behaviour to which requests we added tracing headers when
tracePropagationTargets
were not defined was flawed:fetch("http://my-same-origin/api")
) were not getting traced.fetch("http://api.localhost/posts")
) were getting trace headers attached and causing CORS errors.We solve this by attaching tracing headers to all same-origin requests when
tracePropagationTargets
is not defined.Apart from that, our matching logic was not powerful enough:
fetch
andxhr
as a comparator. E.g. When doingfetch("/api")
, we only matchedtracePropagationTargets
against"/api"
and not against the full URL. This makes it very hard to properly trace requests done by 3rd party libraries where you may not know whether they send the requests to"/api"
or"${window.location.origin}/api"
.We aim to solve this by always comparing the provided
tracePropagationTargets
against the full URL to which the request is sent, and to preserve a certain degree of backwards compatibility, if users defined a relative matcher like/^\/api/
, we also compare the definedtracePropagationTargets
against thepathame
(in the technical sense), iff the request is a same-origin request. (The last part is important because we don't want to hand people a footgun to run into CORS errors.)Resolves #9764