async function e(e){if("nodejs"===process.env.NEXT_RUNTIME){const{H:s}=await import("@highlight-run/node");s.init(e)}else console.info(`Highlight not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`)}import{HIGHLIGHT_REQUEST_HEADER as s,H as r}from"@highlight-run/node";var t={init:e=>{r.isInitialized()||r.init(e)},isInitialized:()=>r.isInitialized(),metrics:(e,s)=>{const t=global.__HIGHLIGHT__;if(t&&!s&&(s=t),!s?.secureSessionId)return console.warn("H.metrics session could not be inferred the handler context.");for(const t of e)r.recordMetric(s.secureSessionId,t.name,t.value,s.requestId,t.tags)}},i=e=>t=>async(i,a)=>{r.isInitialized()||r.init(e);const o=()=>{if(i.headers&&i.headers[s]){const[e,r]=`${i.headers[s]}`.split("/");if(e&&r)return global.__HIGHLIGHT__={secureSessionId:e,requestId:r},{secureSessionId:e,requestId:r}}return{secureSessionId:void 0,requestId:void 0}},{secureSessionId:n,requestId:c}=o(),u=new Date;try{return await t(i,a)}catch(e){throw e instanceof Error&&(r.consumeError(e,n,c),await r.flush()),a.statusCode=500,a.statusMessage="Internal Server Error",e}finally{const e=1e6*((new Date).getTime()-u.getTime()),{secureSessionId:s,requestId:t}=o();s&&(r.recordMetric(s,"latency",e,t),await r.flush())}};import{uploadSourcemaps as a}from"@highlight-run/sourcemap-uploader/dist/lib";var o=async(e,s)=>{const r=await(async(e,s)=>{const r="production"===process.env.NODE_ENV,t=!!process.env.HIGHLIGHT_SOURCEMAP_UPLOAD_API_KEY||!!s?.apiKey;let i=null;if(e.generateBuildId){const s=e.generateBuildId();i="string"==typeof s?s:await s}return{uploadSourceMaps:r&&(s?.uploadSourceMaps??(!e.productionBrowserSourceMaps&&t)),configureHighlightProxy:s?.configureHighlightProxy??!0,apiKey:s?.apiKey??"",appVersion:s?.appVersion??i??"",serviceName:s?.serviceName??"",sourceMapsPath:s?.sourceMapsPath??".next/",sourceMapsBasePath:s?.sourceMapsBasePath??"_next/"}})(e,s);let t=e.rewrites;(r.uploadSourceMaps||r.configureHighlightProxy)&&(t=async()=>{let s;s=e.rewrites?await e.rewrites():new Array;const t={source:"/:path*.map",destination:"/404"},i={source:"/highlight-events",destination:"https://pub.highlight.run"};return!s||Array.isArray(s)?{beforeFiles:r.uploadSourceMaps?[t]:[],afterFiles:r.configureHighlightProxy?(s??[]).concat(i):[],fallback:[]}:{beforeFiles:r.uploadSourceMaps?(s.beforeFiles??[]).concat(t):s.beforeFiles,afterFiles:r.configureHighlightProxy?(s.afterFiles??[]).concat(i):s.afterFiles,fallback:s.fallback}});let i=e.webpack;return r.uploadSourceMaps&&(i=(s,t)=>{let i=s;return e.webpack&&(i=e.webpack(s,t)),i.plugins.push(new class{apiKey;appVersion;path;basePath;constructor(e,s,r,t){this.apiKey=e,this.appVersion=s,this.path=r,this.basePath=t}apply(e){return e.hooks.afterEmit.tap("HighlightWebpackPlugin",(()=>{a({apiKey:this.apiKey,appVersion:this.appVersion,path:this.path,basePath:this.basePath,allowNoop:!0})})),e}}(r.apiKey,r.appVersion,r.sourceMapsPath,r.sourceMapsBasePath)),i}),{...e,productionBrowserSourceMaps:r.uploadSourceMaps||e.productionBrowserSourceMaps,rewrites:t,webpack:i}},n=async(e,s)=>"function"==typeof e?async(r,{defaultConfig:t})=>{const i=e(r,{defaultConfig:t});if("function"==typeof i){const e=await i;return await o(e,s)}return await o(i,s)}:await o(e,s);export{t as H,i as Highlight,e as registerHighlight,n as withHighlightConfig};//# sourceMappingURL=server.mjs.map