@sentry/nextjs
Version:
Official Sentry SDK for Next.js
152 lines (125 loc) • 5.6 kB
JavaScript
import { addTracingExtensions, applySdkMetadata, getClient } from '@sentry/core';
import { Integrations as Integrations$1, getDefaultIntegrations, init as init$1, getCurrentScope } from '@sentry/node';
export * from '@sentry/node';
import { logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../common/debug-build.js';
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor.js';
import { getVercelEnv } from '../common/getVercelEnv.js';
import { isBuild } from '../common/utils/isBuild.js';
import { Http } from './httpIntegration.js';
import { OnUncaughtException } from './onUncaughtExceptionIntegration.js';
import { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
export { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
export { createReduxEnhancer } from '@sentry/react';
export { captureUnderscoreErrorException } from '../common/_error.js';
export { withSentryGetStaticProps, wrapGetStaticPropsWithSentry } from '../common/wrapGetStaticPropsWithSentry.js';
export { withSentryServerSideGetInitialProps, wrapGetInitialPropsWithSentry } from '../common/wrapGetInitialPropsWithSentry.js';
export { withSentryServerSideAppGetInitialProps, wrapAppGetInitialPropsWithSentry } from '../common/wrapAppGetInitialPropsWithSentry.js';
export { withSentryServerSideDocumentGetInitialProps, wrapDocumentGetInitialPropsWithSentry } from '../common/wrapDocumentGetInitialPropsWithSentry.js';
export { withSentryServerSideErrorGetInitialProps, wrapErrorGetInitialPropsWithSentry } from '../common/wrapErrorGetInitialPropsWithSentry.js';
export { withSentryGetServerSideProps, wrapGetServerSidePropsWithSentry } from '../common/wrapGetServerSidePropsWithSentry.js';
export { wrapServerComponentWithSentry } from '../common/wrapServerComponentWithSentry.js';
export { wrapRouteHandlerWithSentry } from '../common/wrapRouteHandlerWithSentry.js';
export { wrapApiHandlerWithSentryVercelCrons } from '../common/wrapApiHandlerWithSentryVercelCrons.js';
export { wrapMiddlewareWithSentry } from '../common/wrapMiddlewareWithSentry.js';
export { wrapPageComponentWithSentry } from '../common/wrapPageComponentWithSentry.js';
export { wrapGenerationFunctionWithSentry } from '../common/wrapGenerationFunctionWithSentry.js';
export { withServerActionInstrumentation } from '../common/withServerActionInstrumentation.js';
export { withSentry, withSentryAPI, wrapApiHandlerWithSentry } from '../common/wrapApiHandlerWithSentry.js';
const Integrations = {
...Integrations$1,
Http,
OnUncaughtException,
};
/**
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
* so they should simply be a passthrough.
*/
const ErrorBoundary = (props) => {
if (!props.children) {
return null;
}
if (typeof props.children === 'function') {
return (props.children )();
}
// since Next.js >= 10 requires React ^16.6.0 we are allowed to return children like this here
return props.children ;
};
/**
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
* SSR errors so they should simply be a passthrough.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function withErrorBoundary(
WrappedComponent,
) {
return WrappedComponent ;
}
/**
* Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
*/
function showReportDialog() {
return;
}
// TODO (v8): Remove this
/**
* @deprecated This constant will be removed in the next major update.
*/
const IS_BUILD = isBuild();
const IS_VERCEL = !!process.env.VERCEL;
/** Inits the Sentry NextJS SDK on node. */
function init(options) {
addTracingExtensions();
if (isBuild()) {
return;
}
const customDefaultIntegrations = [
...getDefaultIntegrations(options).filter(
integration => !['Http', 'OnUncaughtException'].includes(integration.name),
),
rewriteFramesIntegration(),
new Http(),
new OnUncaughtException(),
];
const opts = {
environment: process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV,
defaultIntegrations: customDefaultIntegrations,
...options,
// Right now we only capture frontend sessions for Next.js
autoSessionTracking: false,
};
if (DEBUG_BUILD && opts.debug) {
logger.enable();
}
DEBUG_BUILD && logger.log('Initializing SDK...');
if (sdkAlreadyInitialized()) {
DEBUG_BUILD && logger.log('SDK already initialized');
return;
}
applySdkMetadata(opts, 'nextjs', ['nextjs', 'node']);
init$1(opts);
const filterTransactions = event => {
return event.type === 'transaction' && event.transaction === '/404' ? null : event;
};
filterTransactions.id = 'NextServer404TransactionFilter';
const scope = getCurrentScope();
scope.setTag('runtime', 'node');
if (IS_VERCEL) {
scope.setTag('vercel', true);
}
scope.addEventProcessor(filterTransactions);
if (process.env.NODE_ENV === 'development') {
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
}
DEBUG_BUILD && logger.log('SDK successfully initialized');
}
function sdkAlreadyInitialized() {
return !!getClient();
}
// TODO (v8): Remove this
/**
* @deprecated This constant will be removed in the next major update.
*/
const deprecatedIsBuild = () => isBuild();
export { ErrorBoundary, IS_BUILD, Integrations, init, deprecatedIsBuild as isBuild, showReportDialog, withErrorBoundary };
//# sourceMappingURL=index.js.map