You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(tracing): Make shouldAttachHeaders not fall back to default values (#6238)
This patch fixes a bug in our `shouldAttachHeaders` function that determines internally if outgoing requests should have headers attached or not.
Previously, we assigned the default values to `tracingOrigins` as well as `tracePropagationTargets` and overwrote these defaults, if users provided one (or (unlikely) both) options. In `shouldAttachHeaders`, we then first tested `tracingOrigins` for a match and in case there was no match, we'd test `tracePropagationTargets`. This, however, also meant that if users specified `tracingOrigins` and an URL didn't match them, there was still a chance that headers would be attached - in case the url matched the `tracePropagationTargets`' default values.
With this fix, we don't assign default values to either option but check for definedness of them and only if they're both undefined, well fall back to defaults.
### Example:
url: `/api/test/123`
tracingOrigins: `[]`
tracePropTargets: `['localhost', /^\//]` // default values
`shouldAttachHeaders` returned `true` but should have returned `false`. This PR fixes this behaviour.
In case, both options are defined, we prefer `tracePropagationTargets` over `tracingOrigins`, as defined in the [dev specification](https://develop.sentry.dev/sdk/performance/#example).
Furthermore, this patch extracts the `shouldAttachHeaders` function by wrapping it in a factory function so that it's easier to test this behaviour. And it adds some tests to verify correct behaviour.
We can get rid of some code around this in v8 when we finally remove `tracingOrigins`.
Side-note: Because we're exporting `defaultRequestInstrumentationOptions` as public API, I decided to leave the optional value assignment in place but to simply not take the default values from it anymore in `instrumentOutgoingRequests` (see [aed40a6](aed40a6)).
0 commit comments