API calls start failing CORS after Sentry tracing is added to a Vue app
Your error
Reason: missing token 'sentry-trace' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel3 more lines it can showFix it fast
Most common cause, 1 of 3The default target list sends trace headers to your own API on another port
Add sentry-trace and baggage to the headers the API allows.
import cors from 'cors'
app.use(cors({
origin: 'http://localhost:5173',
allowedHeaders: ['Content-Type', 'Authorization', 'sentry-trace', 'baggage'],
}))
// any other server: answer the preflight with
Access-Control-Allow-Headers: Content-Type, Authorization, sentry-trace, baggageShort answer
Missing token 'sentry-trace' or 'baggage' in Access-Control-Allow-Headers means the Sentry browser SDK (@sentry/vue 11) added its tracing headers to an API call and the preflight answer did not allow them. The default tracePropagationTargets matches any localhost URL. Add both headers to the API's allowed list, or narrow tracePropagationTargets to hosts that accept them.
Which cause do you have?
Replay the browser's preflight from a terminal and look at which request headers the API says it accepts. When sentry-trace and baggage are absent from that answer, the API is the side that blocks the call.
curl -i -X OPTIONS http://localhost:8000/api/users \
-H "Origin: http://localhost:5173" \
-H "Access-Control-Request-Method: GET" \
-H "Access-Control-Request-Headers: sentry-trace, baggage"Then find the line you see in this list and open its fix:
- 1The default target list sends trace headers to your own API on another port
The app runs on localhost:5173, the API on localhost:8000 or similar, and the console names sentry-trace or baggage - 2A third-party API you cannot configure matches a target pattern
The blocked request goes to a host you do not run, such as a maps, payment or analytics endpoint - 3propagateTraceparent is on, which adds a third header
Reason: missing token 'traceparent' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel
What does the error look like?
Reason: missing token 'sentry-trace' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channelReason: missing token 'baggage' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channelCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/api/users.API requests worked until Sentry.init with browserTracingIntegration was added
Cause 1 of 3
The default target list sends trace headers to your own API on another port
You seeThe app runs on localhost:5173, the API on localhost:8000 or similar, and the console names sentry-trace or baggage
Check
Missing token 'sentry-trace' on a call from localhost:5173 to localhost:8000 comes from Sentry's default tracePropagationTargets, ['localhost', /^\//], which covers every URL that contains localhost. A different port makes the API a different origin, so the browser first sends a preflight asking whether these extra headers may be used, and the API has to name them in its answer. Check whether the API sets an explicit header list.
grep -rn "allowedHeaders\|Access-Control-Allow-Headers" server/Fix
Add sentry-trace and baggage to the headers the API allows. With the Express cors package, leaving allowedHeaders out also works, because it then echoes the headers the browser asked for.
import cors from 'cors'
app.use(cors({
origin: 'http://localhost:5173',
allowedHeaders: ['Content-Type', 'Authorization', 'sentry-trace', 'baggage'],
}))
// any other server: answer the preflight with
Access-Control-Allow-Headers: Content-Type, Authorization, sentry-trace, baggageVerify
Repeat the curl preflight. The reply now lists both headers, and the request goes through in the browser.
curl -s -i -X OPTIONS http://localhost:8000/api/users -H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: GET" -H "Access-Control-Request-Headers: sentry-trace, baggage" | grep -i allow-headersConfirmed by docs.sentry.io
Cause 2 of 3
A third-party API you cannot configure matches a target pattern
You seeThe blocked request goes to a host you do not run, such as a maps, payment or analytics endpoint
Check
Missing token 'sentry-trace' on a request to a service you do not run means one of your tracePropagationTargets patterns matches that service. A string entry, like the default 'localhost', matches any URL that contains it. A loose string or regular expression pulls in outside services that will never allow the Sentry headers. Read the list in your Sentry.init call.
grep -rn "tracePropagationTargets" srcFix
List only the origins you control, with anchored patterns. If you do not need traces joined across frontend and backend at all, an empty list stops the headers completely.
Sentry.init({
// keep app and your other options as they are
dsn: import.meta.env.VITE_SENTRY_DSN,
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 0.2,
tracePropagationTargets: [/^\/api\//, 'https://api.example.com'],
// or: tracePropagationTargets: [] to send no trace headers
})Verify
Reload the app and look at the request headers in the Network panel: the third-party call no longer carries sentry-trace.
grep -rn "tracePropagationTargets" srcConfirmed by docs.sentry.io
Cause 3 of 3
propagateTraceparent is on, which adds a third header
You seeReason: missing token 'traceparent' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel
Check
Missing token 'traceparent' appears when propagateTraceparent is true, because the SDK then sends a traceparent header too, so an allow list that already has sentry-trace and baggage still fails. Search your Sentry setup for the option.
grep -rn "propagateTraceparent" srcFix
Add traceparent to the allowed headers next to the two Sentry headers.
Access-Control-Allow-Headers: Content-Type, sentry-trace, baggage, traceparentVerify
Run the preflight with all three headers in Access-Control-Request-Headers and confirm each one comes back allowed.
curl -s -i -X OPTIONS http://localhost:8000/api/users -H "Origin: http://localhost:5173" -H "Access-Control-Request-Method: GET" -H "Access-Control-Request-Headers: sentry-trace, baggage, traceparent" | grep -i allow-headersConfirmed by docs.sentry.io
How do I stop it coming back?
- Write tracePropagationTargets out in Sentry.init, listing only the API origins you run.
- Add sentry-trace and baggage to the API's allowed CORS headers in the same change that turns tracing on.
- Make sure proxies and gateways in front of the API pass sentry-trace and baggage through unchanged.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.