Skip to content

Commit

Permalink
fix: shutdown Sentry instance after generate (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Oct 1, 2021
1 parent e51a438 commit ee4c293
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/core/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,11 @@ export async function initializeServerSentry (moduleContainer, options) {

process.sentry = Sentry
}

export async function shutdownServerSentry () {
if (process.sentry) {
await process.sentry.close()
// @ts-ignore
process.sentry = undefined
}
}
3 changes: 2 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import consola from 'consola'
import merge from 'lodash.mergewith'
import { Handlers as SentryHandlers, captureException, withScope } from '@sentry/node'
import { buildHook, initializeServerSentry, webpackConfigHook } from './core/hooks'
import { buildHook, initializeServerSentry, shutdownServerSentry, webpackConfigHook } from './core/hooks'
import { boolToText, canInitialize, clientSentryEnabled, envToBool, serverSentryEnabled } from './core/utils'

const logger = consola.withScope('nuxt:sentry')
Expand Down Expand Up @@ -109,6 +109,7 @@ export default function SentryModule (moduleOptions) {

if (serverSentryEnabled(options)) {
this.nuxt.hook('ready', () => initializeServerSentry(this, options))
this.nuxt.hook('generate:done', () => shutdownServerSentry())
}

// Enable publishing of sourcemaps
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"main": "lib/module.js",
"scripts": {
"dev:fixture": "nuxt -c ./test/fixture/default/nuxt.config.js",
"dev:generate": "nuxt generate -c ./test/fixture/default/nuxt.config.js",
"lint": "eslint --ext .vue,.js,.ts lib test types",
"lint:fixture": "eslint --ext .vue,.js --no-ignore 'test/fixture/*/.nuxt/sentry.*'",
"release": "release-it",
Expand Down

0 comments on commit ee4c293

Please sign in to comment.