Skip to content

Commit 946d35b

Browse files
author
Luca Forstner
committed
Better explanation
1 parent ec77cca commit 946d35b

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

packages/tracing-internal/src/browser/request.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable max-lines */
21
import {
32
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
43
getClient,
@@ -34,15 +33,20 @@ export interface RequestInstrumentationOptions {
3433
* List of strings and/or Regular Expressions used to determine which outgoing requests will have `sentry-trace` and `baggage`
3534
* headers attached.
3635
*
37-
* By default, if this option is not provided, tracing headers will be attached to all outgoing requests to the same origin as the current page.
36+
* **Default:** If this option is not provided, tracing headers will be attached to all outgoing requests.
37+
* If you are using a browser SDK, by default, tracing headers will only be attached to outgoing requests to the same origin.
3838
*
39-
* NOTE: Carelessly setting this option may result into CORS errors.
39+
* **Disclaimer:** Carelessly setting this option in browser environments may result into CORS errors!
40+
* Only attach tracing headers to requests to the same origin, or to requests to services you can control CORS headers of.
41+
* Cross-origin requests, meaning requests to a different domain, for example a request to `https://api.example.com/` while you're on `https://example.com/`, take special care.
42+
* If you are attaching headers to cross-origin requests, make sure the backend handling the request returns a `"Access-Control-Allow-Headers: sentry-trace, baggage"` header to ensure your requests aren't blocked.
4043
*
41-
* If you provide a `tracePropagationTargets` array, the entries you provide will be matched against two values:
42-
* - The entire URL of the outgoing request.
43-
* - The pathname of the outgoing request (only if it is a same-origin request)
44+
* If you provide a `tracePropagationTargets` array, the entries you provide will be matched against the entire URL of the outgoing request.
45+
* If you are using a browser SDK, the entries will also be matched against the pathname of the outgoing requests.
46+
* This is so you can have matchers for relative requests, for example, `/^\/api/` if you want to trace requests to your `/api` routes on the same domain.
4447
*
4548
* If any of the two match any of the provided values, tracing headers will be attached to the outgoing request.
49+
* Both, the string values, and the RegExes you provide in the array will match if they partially match the URL or pathname.
4650
*
4751
* Examples:
4852
* - `tracePropagationTargets: [/^\/api/]` and request to `https://same-origin.com/api/posts`:
@@ -246,7 +250,6 @@ export function shouldAttachHeaders(
246250
*
247251
* @returns Span if a span was created, otherwise void.
248252
*/
249-
// eslint-disable-next-line complexity
250253
export function xhrCallback(
251254
handlerData: HandlerDataXhr,
252255
shouldCreateSpan: (url: string) => boolean,

packages/types/src/options.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,20 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
226226
* List of strings and/or Regular Expressions used to determine which outgoing requests will have `sentry-trace` and `baggage`
227227
* headers attached.
228228
*
229-
* By default, if this option is not provided, tracing headers will be attached to all outgoing requests to the same origin as the current page.
229+
* **Default:** If this option is not provided, tracing headers will be attached to all outgoing requests.
230+
* If you are using a browser SDK, by default, tracing headers will only be attached to outgoing requests to the same origin.
230231
*
231-
* NOTE: Carelessly setting this option may result into CORS errors.
232+
* **Disclaimer:** Carelessly setting this option in browser environments may result into CORS errors!
233+
* Only attach tracing headers to requests to the same origin, or to requests to services you can control CORS headers of.
234+
* Cross-origin requests, meaning requests to a different domain, for example a request to `https://api.example.com/` while you're on `https://example.com/`, take special care.
235+
* If you are attaching headers to cross-origin requests, make sure the backend handling the request returns a `"Access-Control-Allow-Headers: sentry-trace, baggage"` header to ensure your requests aren't blocked.
232236
*
233-
* If you provide a `tracePropagationTargets` array, the entries you provide will be matched against two values:
234-
* - The entire URL of the outgoing request.
235-
* - The pathname of the outgoing request (only if it is a same-origin request)
237+
* If you provide a `tracePropagationTargets` array, the entries you provide will be matched against the entire URL of the outgoing request.
238+
* If you are using a browser SDK, the entries will also be matched against the pathname of the outgoing requests.
239+
* This is so you can have matchers for relative requests, for example, `/^\/api/` if you want to trace requests to your `/api` routes on the same domain.
236240
*
237241
* If any of the two match any of the provided values, tracing headers will be attached to the outgoing request.
242+
* Both, the string values, and the RegExes you provide in the array will match if they partially match the URL or pathname.
238243
*
239244
* Examples:
240245
* - `tracePropagationTargets: [/^\/api/]` and request to `https://same-origin.com/api/posts`:

0 commit comments

Comments
 (0)