-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as Sentry from '@sentry/node' | ||
import { H3Error } from 'h3' | ||
|
||
export default defineNitroPlugin((nitroApp) => { | ||
const { public: { sentry } } = useRuntimeConfig() | ||
|
||
// If no sentry DSN set, ignore and warn in the console | ||
if (!sentry.dsn) { | ||
console.warn('Sentry DSN not set, skipping Sentry initialization') | ||
return | ||
} | ||
|
||
// Initialize Sentry | ||
Sentry.init({ | ||
dsn: sentry.dsn, | ||
environment: sentry.environment, | ||
integrations: [], | ||
// Performance Monitoring | ||
tracesSampleRate: 1.0, // Change in production! | ||
// Set sampling rate for profiling - this is relative to tracesSampleRate | ||
profilesSampleRate: 1.0, // Change in production! | ||
}) | ||
|
||
nitroApp.hooks.hook('error', (error) => { | ||
// Do not handle 404s and 422s | ||
if (error instanceof H3Error) { | ||
if (error.statusCode === 404 || error.statusCode === 422) { | ||
return | ||
} | ||
} | ||
|
||
Sentry.captureException(error) | ||
}) | ||
|
||
nitroApp.hooks.hook('request', (event) => { | ||
event.context.$sentry = Sentry | ||
}) | ||
|
||
nitroApp.hooks.hookOnce('close', async () => { | ||
await Sentry.close(2000) | ||
}) | ||
}) |