@sentry/nextjs
Version:
Official Sentry SDK for Next.js
119 lines (100 loc) • 5.4 kB
JavaScript
import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
import { Integrations as Integrations$1, init as init$1, getCurrentScope, getDefaultIntegrations as getDefaultIntegrations$1 } from '@sentry/react';
export * from '@sentry/react';
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor.js';
import { getVercelEnv } from '../common/getVercelEnv.js';
import { BrowserTracing } from './browserTracingIntegration.js';
export { BrowserTracing } from './browserTracingIntegration.js';
import { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
export { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
import { applyTunnelRouteOption } from './tunnelRoute.js';
export { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation.js';
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';
const Integrations = {
...Integrations$1,
BrowserTracing,
};
// Treeshakable guard to remove all code related to tracing
/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
function init(options) {
const opts = {
environment: getVercelEnv(true) || process.env.NODE_ENV,
defaultIntegrations: getDefaultIntegrations(options),
...options,
};
fixBrowserTracingIntegration(opts);
applyTunnelRouteOption(opts);
applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']);
init$1(opts);
const scope = getCurrentScope();
scope.setTag('runtime', 'browser');
const filterTransactions = event =>
event.type === 'transaction' && event.transaction === '/404' ? null : event;
filterTransactions.id = 'NextClient404Filter';
scope.addEventProcessor(filterTransactions);
if (process.env.NODE_ENV === 'development') {
scope.addEventProcessor(devErrorSymbolicationEventProcessor);
}
}
// TODO v8: Remove this again
// We need to handle BrowserTracing passed to `integrations` that comes from `@sentry/tracing`, not `@sentry/sveltekit` :(
function fixBrowserTracingIntegration(options) {
const { integrations } = options;
if (!integrations) {
return;
}
if (Array.isArray(integrations)) {
options.integrations = maybeUpdateBrowserTracingIntegration(integrations);
} else {
options.integrations = defaultIntegrations => {
const userFinalIntegrations = integrations(defaultIntegrations);
return maybeUpdateBrowserTracingIntegration(userFinalIntegrations);
};
}
}
function maybeUpdateBrowserTracingIntegration(integrations) {
const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing');
// If BrowserTracing was added, but it is not our forked version,
// replace it with our forked version with the same options
if (browserTracing && !(browserTracing instanceof BrowserTracing)) {
const options = (browserTracing ).options;
// These two options are overwritten by the custom integration
delete options.routingInstrumentation;
// eslint-disable-next-line deprecation/deprecation
delete options.tracingOrigins;
integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
}
return integrations;
}
function getDefaultIntegrations(options) {
const customDefaultIntegrations = [...getDefaultIntegrations$1(options), rewriteFramesIntegration()];
// This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
// will get treeshaken away
if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
if (hasTracingEnabled(options)) {
customDefaultIntegrations.push(new BrowserTracing());
}
}
return customDefaultIntegrations;
}
/**
* Just a passthrough in case this is imported from the client.
*/
function withSentryConfig(exportedUserNextConfig) {
return exportedUserNextConfig;
}
export { Integrations, init, withSentryConfig };
//# sourceMappingURL=index.js.map