import getConfig from 'next/config' ; import React from 'react' ; let Sentry ; const { publicRuntimeConfig } = getConfig ( ) ; const SENTRY_URL = publicRuntimeConfig . SENTRY_URL ; const dev = process . env . NODE_ENV !== 'production' ; if ( process . browser ) { Sentry = require ( '@sentry/browser' ) ; } else { Sentry = require ( '@sentry/node' ) ; } if ( ! dev ) { Sentry . init ( { dsn : SENTRY_URL } ) ; } export function logException ( ex , context ? ) { Sentry . captureException ( ex , { extra : context , } ) ; typeof window !== 'undefined' && window . console && console . error && console . error ( ex ) ; } export function logMessage ( msg ) { Sentry . captureMessage ( msg ) ; } export default function withSentry < T > ( WrappedComponent ) { return class SentryComponent extends React . Component < T > { render ( ) { try { return < WrappedComponent { ... this . props } / > ; } catch ( ex ) { logException ( ex ) ; } } } ; }