this.$sentry is undefined in a local environment

lukaVarga
3
lukaVarga
commented 2 years ago

Version

3.0.0

Reproduction link

https://codesandbox.io/embed/codesandbox-nuxt-m0vmy

Steps to reproduce

  • Add the '@nuxtjs/sentry' v 3.0.0 to the app
  • Add the package in nuxt config
  • Add sentry configuration in nuxt config
  • Do not add DSN (or let it be null)
  • Call one of the sentry methods, eg this.$sentry.setContext(params)

What is expected ?

Calling sentry methods should not trigger any errors, if DSN is empty (or if sentry is disabled for the environment), this.$sentry should not be undefined, it should, instead, implement mock methods that don't really do anything

What is actually happening?

Sentry object is available on window, but not within the components. Calling this.$sentry.foo, where foo is one of the sentry methods, results in an error (cannot call 'foo' of undefined)

Additional comments?

If @nuxtjs/sentry is added as a nuxt module, then this.$sentry should be available in the components regardless of the configuration as it's quite common to not define DSN for development / testing, or to use disabled: true in the module for the development / testing environment. In this case, this.$sentry should just be a mock object that just implements the methods but doesn't do anything with them.

bug
0
mrleblanc101
0
mrleblanc101
commented 2 years ago

Just had this problem, had to wrap every sentry call in an if statement

0
rchl
2.3k
rchl
commented 2 years ago

Don't use disabled and try initialize: false instead. But you need to set dsn in that case as otherwise $sentry object won't be added either.

0
lukaVarga
3
lukaVarga
commented 2 years ago

Yes, that's what I did for now, but according to the readme, dsn should not be needed in such cases

0
Informations
Bug ReportOpen
#c70 - Created 2 years ago