9

I'm using http://localhost:3000 to development my website, but I always get CROS error from Sentry, what am I missing?

in Sentry's Setting: I've set the project's Allowed Domains to *, but it's looks like not work....

Access to fetch at 'my-sentry-dsn' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Vue3 + Vite

yarn add @sentry/tracing @sentry/vue

in main.ts

import * as Sentry from "@sentry/vue"
import { Integrations } from "@sentry/tracing"
const app = createApp(App)
// Initialize Sentry
const dsnSentry = import.meta.env.VITE_SENTRY_DSN as string
if (!!dsnSentry) {
  const env = import.meta.env.VITE_ENV
  const isDebug = env !== "production"
  Sentry.init({
    app,
    dsn: dsnSentry,
    // integrations: [new Integrations.BrowserTracing()],
    integrations: [
      new Integrations.BrowserTracing({
        routingInstrumentation: Sentry.vueRouterInstrumentation(router),
        tracingOrigins: ["localhost:3000", /^\//],
      }),
    ],
    tracesSampleRate: 1.0,
    debug: isDebug,
  })
}

app.mount("#app")

1 Answer 1

13

I solved this problem by using * in the tracingOrigins param.

Like this:

Sentry.init({
  dsn: "__DNS__",
  integrations: [new BrowserTracing({ tracingOrigins: ["*"] })],
  tracesSampleRate: 1.0,
});

Another problem, can be ads block extension like adblock, ublock.

7
  • 1
    omg I was going crraaazzzyyy with CORS, this was it!
    – ihor.eth
    Commented Jan 6, 2023 at 23:18
  • 3
    do note tracingOrigins option doesnt exist anymore github.com/getsentry/sentry-javascript/blob/master/packages/…
    – ihor.eth
    Commented Jan 6, 2023 at 23:32
  • 1
    @ihor.eth, what is the alternative? Thanks!
    – ddsultan
    Commented Jan 26, 2023 at 8:54
  • 1
    @ddsultan no idea I removed tracing altogether since I dont need it, the docs are kind of vague about this.
    – ihor.eth
    Commented Jan 26, 2023 at 23:16
  • the alternative may be tracePropagationTargets but use as the top level option in Sentry.init() Sentry.init({ app, dsn: import.meta.env.VITE_APP_SENTRY_DSN, environment: import.meta.env.MODE, tracePropagationTargets: ['*'], <--- this ...
    – phuongtm
    Commented Dec 20, 2023 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.