Skip to content

Commit ec6fe22

Browse files
committed
Update CORS guidance in distributed tracing documentation to clarify header configuration and improve clarity on potential issues.
1 parent 1065f99 commit ec6fe22

File tree

1 file changed

+3
-44
lines changed
  • docs/platforms/javascript/common/tracing/distributed-tracing/dealing-with-cors-issues

1 file changed

+3
-44
lines changed

docs/platforms/javascript/common/tracing/distributed-tracing/dealing-with-cors-issues/index.mdx

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ notSupported:
1616
- javascript.nestjs
1717
---
1818

19-
If your frontend and backend are hosted on different domains (for example, your frontend is on `https://example.com` and your backend is on `https://api.example.com`), you may need to configure your backend [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) headers to ensure distributed tracing works properly.
19+
If your frontend and backend are hosted on different domains (for example, your frontend is on `https://example.com` and your backend is on `https://api.example.com`), you need to configure your backend [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) headers to prevent requests from being blocked by the browser.
2020

2121
## Understanding Trace Propagation
2222

@@ -26,7 +26,7 @@ Sentry doesn't attach the `sentry-trace` and `baggage` headers to every outgoing
2626
- Requests containing `localhost` in their URL (e.g., `http://localhost:3000/api`)
2727
- Requests whose URL starts with `/` (e.g., `/api/users`, `/graphql`)
2828

29-
This default behavior helps prevent sending trace data to third-party services and reduces potential CORS issues.
29+
This default behavior helps prevent sending trace data to third-party services and avoids potential CORS issues.
3030

3131
## Configuring Trace Propagation
3232

@@ -55,48 +55,7 @@ Access-Control-Allow-Headers: sentry-trace, baggage
5555

5656
Your server's exact configuration will depend on your setup, but the important part is allowing both the `sentry-trace` and `baggage` headers.
5757

58-
## Example Scenarios
59-
60-
### Single Backend Domain
61-
62-
If your frontend calls a single backend domain:
63-
64-
```javascript
65-
// Frontend configuration
66-
Sentry.init({
67-
dsn: "___PUBLIC_DSN___",
68-
tracePropagationTargets: [
69-
"localhost", // For development
70-
"https://api.example.com" // Your backend
71-
],
72-
});
73-
```
74-
75-
```
76-
# Backend CORS configuration
77-
Access-Control-Allow-Headers: sentry-trace, baggage
78-
```
79-
80-
### Multiple Services
81-
82-
If your frontend calls multiple backend services:
83-
84-
```javascript
85-
// Frontend configuration
86-
Sentry.init({
87-
dsn: "___PUBLIC_DSN___",
88-
tracePropagationTargets: [
89-
"localhost",
90-
"https://api.example.com",
91-
"https://auth.example.com",
92-
"https://media.example.com"
93-
],
94-
});
95-
```
96-
97-
Each backend service needs to allow the headers in their CORS configuration.
98-
99-
### Disabling Trace Propagation
58+
## Disabling Trace Propagation
10059

10160
If you want to disable distributed tracing entirely and ensure no trace headers are sent:
10261

0 commit comments

Comments
 (0)