UNPKG

@sentry/nextjs

Version:
56 lines (53 loc) 2.49 kB
import * as origModule from '__SENTRY_NEXTJS_REQUEST_ASYNC_STORAGE_SHIM__'; import * as routeModule from '__SENTRY_WRAPPING_TARGET_FILE__'; export * from '__SENTRY_WRAPPING_TARGET_FILE__'; import * as Sentry from '@sentry/nextjs'; const asyncStorageModule = { ...origModule }; const requestAsyncStorage = "workUnitAsyncStorage" in asyncStorageModule ? asyncStorageModule.workUnitAsyncStorage : "requestAsyncStorage" in asyncStorageModule ? asyncStorageModule.requestAsyncStorage : void 0; const serverComponent = routeModule.default; let wrappedServerComponent; if (typeof serverComponent === "function") { wrappedServerComponent = new Proxy(serverComponent, { apply: (originalFunction, thisArg, args) => { let sentryTraceHeader = void 0; let baggageHeader = void 0; let headers = void 0; try { const requestAsyncStore = requestAsyncStorage?.getStore(); sentryTraceHeader = requestAsyncStore?.headers.get("sentry-trace") ?? void 0; baggageHeader = requestAsyncStore?.headers.get("baggage") ?? void 0; headers = requestAsyncStore?.headers; } catch { } return Sentry.wrapServerComponentWithSentry(originalFunction, { componentRoute: "__ROUTE__", componentType: "__COMPONENT_TYPE__", sentryTraceHeader, baggageHeader, headers }).apply(thisArg, args); } }); } else { wrappedServerComponent = serverComponent; } const generateMetadata = routeModule.generateMetadata ? Sentry.wrapGenerationFunctionWithSentry(routeModule.generateMetadata, { componentRoute: "__ROUTE__", componentType: "__COMPONENT_TYPE__", generationFunctionIdentifier: "generateMetadata", requestAsyncStorage }) : void 0; const generateImageMetadata = routeModule.generateImageMetadata ? Sentry.wrapGenerationFunctionWithSentry(routeModule.generateImageMetadata, { componentRoute: "__ROUTE__", componentType: "__COMPONENT_TYPE__", generationFunctionIdentifier: "generateImageMetadata", requestAsyncStorage }) : void 0; const generateViewport = routeModule.generateViewport ? Sentry.wrapGenerationFunctionWithSentry(routeModule.generateViewport, { componentRoute: "__ROUTE__", componentType: "__COMPONENT_TYPE__", generationFunctionIdentifier: "generateViewport", requestAsyncStorage }) : void 0; const wrappedServerComponent_default = wrappedServerComponent; export { wrappedServerComponent_default as default, generateImageMetadata, generateMetadata, generateViewport };