nuxt-community / sentry-module

Sentry module for Nuxt 2
https://sentry.nuxtjs.org
MIT License
500 stars 113 forks source link

serverConfig doesn't replace dsn #567

Closed arkhamvm closed 1 year ago

arkhamvm commented 1 year ago

Version

@nuxtjs/sentry: 7.2.4 nuxt: 2.15.8

Sentry configuration

  modules: [
    '@nuxtjs/axios',
    ['@nuxtjs/sentry', { ignore: ['node_modules'] }],
  ],
  sentry: {
    dsn: 'vue_dsn', 
    serverConfig: {
      dsn: 'node_dsn',
    },
    lazy: false,
    disabled: false,
    debug: true,
    tracing: {
      tracesSampleRate: 1.0,
    },
    config: {
      environment: 'codesandbox',
    },
  },

Reproduction Link

https://codesandbox.io/p/sandbox/zealous-blackburn-00w1y6?file=%2Fpages%2Fabout%2Findex.vue%3A28%2C4

Steps to reproduce

Open about page

What is Expected?

Server Error sended to dsn from serverConfig

What is actually happening?

Server Error sended to default dsn

image

image

rchl commented 1 year ago

Good catch. The logic of merging default/user/server config was backwards that resulted in the global dsn having priority. Fixed in #568.

rchl commented 1 year ago

BTW. The ignore setting doesn't apply where you've put it. It's part of the publishRelease object and defaults to:

      ignore: [
        'node_modules',
        '.nuxt/dist/client/img',
      ],

already so maybe you shouldn't even override it.

And if you are not using publishRelease then you can just remove it.

arkhamvm commented 1 year ago

@rchl Can you also check perfomance tracing? Looks like it's same issue.

https://codesandbox.io/p/sandbox/hopeful-knuth-bou0pb?file=%2Fpages%2Fabout%2Findex.vue%3A15%2C42

VueJS tracing is OK: image

NodeJS tracing not working: image

rchl commented 1 year ago

Can you apply this patch in node_modules/@nuxtjs/sentry/dist/module.mjs and see what is printed on starting Nuxt? It should tell you exactly what config is used and whether it's a config issue.

--- /node_modules/@nuxtjs/sentry/dist/module.mjs    Wed May 10 14:45:01 2023
+++ /node_modules/@nuxtjs/sentry/dist/module.mjs    Fri May 19 09:07:12 2023
@@ -532,6 +532,7 @@
   const config = defu({ release }, serverOptions.config);
   process.sentry = Sentry;
   if (canInitialize(moduleOptions)) {
+    console.info({config})
     Sentry.init(config);
     sentryHandlerProxy.errorHandler = Sentry.Handlers.errorHandler();
     sentryHandlerProxy.requestHandler = Sentry.Handlers.requestHandler(moduleOptions.requestHandlerConfig);
arkhamvm commented 1 year ago

prod build

$ npm run build
✔ Sentry reporting is enabled (client side: enabled, server side: enabled)
ℹ Production build
ℹ Bundling for server and client side
ℹ Target: server
✔ Builder initialized
✔ Nuxt files generated   

sentry_config {                                                                                                                
  config: {
    dsn: 'SERVER_DSN',
    integrations: [
      [Http],
      [Dedupe],
      [ExtraErrorData],
      [RewriteFrames],
      [Transaction]
    ],
    environment: 'production',
    tracesSampleRate: 1,
  }
}

dev watch

$ npm run dev

✔ Sentry reporting is enabled (client side: enabled, server side: enabled)    
ℹ Preparing project for development
ℹ Initial build may take a while
✔ Builder initialized
✔ Nuxt files generated

sentry_config {
  config: {
    dsn: 'SERVER_DSN',
    integrations: [
      [Dedupe],
      [ExtraErrorData],
      [RewriteFrames],
      [Transaction]
    ],
    environment: 'dev'
  }
}

DSN looks ok, but why tracesSampleRate disappears in dev env?\ As well [Http] integration too.

Config:

    sentry: {
        dsn:          'CLIENT_DSN',
        serverConfig: {
            dsn: 'SERVER_DSN',
        },
        lazy:     false,
        disabled: false,
        tracing:  {
            tracesSampleRate: 1.0,
        },
        config: {
            environment: sentryEnv,
        },
        ignoreErrors: [
            'Non-Error exception captured',
            'Non-Error promise rejection captured',
            'Network Error',
            'Request aborted',
        ],
        clientIntegrations: {
            ReportingObserver: false,
        },
    },
rchl commented 1 year ago

Off... this needs a proper look. :)

BTW. ignoreErrors is in a wrong place. Should be in config/clientConfig/serverConfig.