Sentry module for Nuxt.js
The module enables error logging through Sentry.
- Please note that version 2.2.0 of this package removed the older
public_keyandprivate_keyoptions, since the updated Sentry packages don't support these anymore. - Please note that version 2.0.0 of this package introduces a breaking change. See #30 for more information.
- Add
@nuxtjs/sentrydependency using yarn or npm to your project - Add
@nuxtjs/sentrytomodulessection ofnuxt.config.js
{
modules: [
'@nuxtjs/sentry',
],
sentry: {
dsn: '', // Enter your project's DSN here
config: {}, // Additional config
}
}Versions of NuxtJS before v2.4.0 are not supported by this package.
Enter your DSN in the NuxtJS config file. Additional config settings can be found here.
In a Vue component, Sentry is available as this.$sentry, so we can call functions like
this.$sentry.captureException(new Error('example'))where this is a Vue instance.
While using Nuxt's asyncData method, there's $sentry object in the context:
async asyncData ({ params, $sentry }) {
try {
let { data } = await axios.get(`https://my-api/posts/${params.id}`)
return { title: data.title }
} catch (error) {
$sentry.captureException(error)
}
}For the other special Nuxt lifecycle areas like plugins, middleware, and nuxtServerInit, the $sentry object is also accessible through the context object like so:
async nuxtServerInit({ commit }, { $sentry }) {
try {
let { data } = await axios.get(`https://my-api/timestamp`)
commit('setTimeStamp', data)
} catch (error) {
$sentry.captureException(error)
}
}Options can be passed using either environment variables or sentry section in nuxt.config.js.
Normally, setting required DSN information would be enough.
- Type:
String- Default:
process.env.SENTRY_DSN || false - If no
dsnis provided, Sentry will be initialised, but errors will not be logged. See #47 for more information about this.
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_DISABLED || false - Sentry will not be initialised if set to
true.
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_DISABLE_CLIENT_SIDE || false
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_DISABLE_SERVER_SIDE || false
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_INITIALIZE || true - Can be used to add the
$sentryobject without initializing it, which will result in not reporting errors to Sentry when they happen but not crashing on calling the Sentry APIs.
- Default:
- Type:
Boolean- Default:
true - Whether to log calls to the mocked
$sentryclient-side object in the console - Only applies when mocked instance is used (when
disabled = trueordisableClientSide = true)
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_PUBLISH_RELEASE || false - See https://docs.sentry.io/workflow/releases for more information
- Default:
- Type:
String- Default:
source-map - Only has effect when
publishRelease = true - The type of source maps generated when publishing release to Sentry. See https://webpack.js.org/configuration/devtool for a list of available options
- Note: Consider using
hidden-source-mapinstead. For most people, that should be a better option but due to it being a breaking change, it won't be set as the default until next major release
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_AUTO_ATTACH_COMMITS || false - Only has effect when
publishRelease = true
- Default:
- Type:
String- Default:
process.env.SENTRY_RELEASE_REPO || false - Only has effect when
publishRelease = true && attachCommits = true
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_DISABLE_SERVER_RELEASE || false - See https://docs.sentry.io/workflow/releases for more information
- Default:
- Type:
Boolean- Default:
process.env.SENTRY_DISABLE_CLIENT_RELEASE || false - See https://docs.sentry.io/workflow/releases for more information
- Default:
- Type:
Dictionary- Default:
{ Dedupe: {}, ExtraErrorData: {}, ReportingObserver: {}, RewriteFrames: {}, Vue: {attachProps: true} }
- See https://docs.sentry.io/platforms/node/pluggable-integrations/ for more information
- Type:
Dictionary- Default:
{ Dedupe: {}, ExtraErrorData: {}, RewriteFrames: {}, Transaction: {} }
- See https://docs.sentry.io/platforms/node/pluggable-integrations/ for more information
- Type:
Object- Default:
{ environment: this.options.dev ? 'development' : 'production' }
- Default:
- Type:
Object- Default:
{ } - If specified, values will override config values for server sentry plugin
- Default:
- Type:
Object- Default:
{ } - If specified, values will override config values for client sentry plugin
- Default:
- Type:
Object- Default: Refer to
module.jssince defaults include various options that also change dynamically based on other options. - Options passed to
@sentry/webpack-plugin. See documentation at https://github.com/getsentry/sentry-webpack-plugin/blob/master/README.md
- Default: Refer to
Support for the sentry-webpack-plugin was introduced #a6cd8d3. This can be used to send releases to Sentry. Use the publishRelease option to enable this feature.
Note that releases are only submitted to Sentry when (options.publishRelease && !isDev) is true.
Copyright (c) Diederik van den Burger [email protected]