chore: added sentry integration for browser

This commit is contained in:
Junseo Park 2021-02-18 15:02:00 +09:00
parent b46cf2a069
commit de2fc315fd

View File

@ -1,17 +1,17 @@
import * as Sentry from '@sentry/node' import * as Sentry from '@sentry/node'
import { RewriteFrames } from '@sentry/integrations' import { RewriteFrames } from '@sentry/integrations'
import { Integrations } from '@sentry/tracing'
export const init = () => { export const init = () => {
if (process.env.NEXT_PUBLIC_SENTRY_DSN) { if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
const integrations = [] const integrations = []
if ( if (
process.env.NEXT_IS_SERVER === 'true' && process.env.NEXT_IS_SERVER === 'true'
process.env.NEXT_PUBLIC_SENTRY_SERVER_ROOT_DIR
) { ) {
// For Node.js, rewrite Error.stack to use relative paths, so that source // For Node.js, rewrite Error.stack to use relative paths, so that source
// maps starting with ~/_next map to files in Error.stack with path // maps starting with ~/_next map to files in Error.stack with path
// app:///_next // app:///_next
integrations.push( if(process.env.NEXT_PUBLIC_SENTRY_SERVER_ROOT_DIR) integrations.push(
new RewriteFrames({ new RewriteFrames({
iteratee: (frame) => { iteratee: (frame) => {
frame.filename = frame.filename.replace( frame.filename = frame.filename.replace(
@ -24,6 +24,7 @@ export const init = () => {
}) })
) )
} }
else integrations.push(new Integrations.BrowserTracing())
Sentry.init({ Sentry.init({
enabled: process.env.NODE_ENV === 'production', enabled: process.env.NODE_ENV === 'production',