{"version":3,"file":"server.edge.cjs","sources":["../src/util/highlight-edge.ts","../src/server.edge.ts","../src/util/with-highlight-edge.ts"],"sourcesContent":["import {\n\tH as CloudflareH,\n\tHighlightEnv as CloudflareHighlightEnv,\n} from '@highlight-run/cloudflare'\nimport type { HighlightContext, Metric, NodeOptions } from '@highlight-run/node'\nimport type { Span } from '@opentelemetry/api'\nimport { HighlightInterface } from './types'\n\nexport type HighlightEnv = NodeOptions\n\nexport const H: HighlightInterface = {\n\t...CloudflareH,\n\tinit: (_: HighlightEnv) => {\n\t\tthrow new Error(\n\t\t\t'H.init is not supported by the Edge runtime. Try H.initEdge instead.',\n\t\t)\n\t},\n\tisInitialized: () => CloudflareH.isInitialized(),\n\tinitEdge: function init(env: HighlightEnv) {\n\t\tif (CloudflareH.isInitialized()) {\n\t\t\treturn\n\t\t}\n\n\t\tconst cloudflareEnv: CloudflareHighlightEnv = {\n\t\t\tHIGHLIGHT_PROJECT_ID: env.projectID,\n\t\t\tHIGHLIGHT_OTLP_ENDPOINT: env.otlpEndpoint,\n\t\t}\n\n\t\tif (env.serviceVersion) {\n\t\t\tconsole.warn(\n\t\t\t\t'Highlight does not support serviceVersion on Cloudflare Workers',\n\t\t\t)\n\t\t}\n\n\t\tif (env.enableFsInstrumentation) {\n\t\t\tconsole.warn(\n\t\t\t\t'Highlight does not support enableFsInstrumentation on Cloudflare Workers',\n\t\t\t)\n\t\t}\n\n\t\treturn CloudflareH.init(cloudflareEnv, env.serviceName)\n\t},\n\tmetrics: function (metrics: Metric[], highlightContext?: HighlightContext) {\n\t\tfor (const m of metrics) {\n\t\t\tCloudflareH.recordMetric({\n\t\t\t\tsecureSessionId: highlightContext?.secureSessionId ?? '',\n\t\t\t\trequestId: highlightContext?.requestId ?? '',\n\t\t\t\t...m,\n\t\t\t})\n\t\t}\n\t},\n\tflush: async () => {\n\t\tawait CloudflareH.flush()\n\t},\n\tconsumeAndFlush: async function (error: Error) {\n\t\tCloudflareH.consumeError(error)\n\t\tawait this.flush()\n\t},\n\tstop: async () => {\n\t\tthrow new Error('H.stop is not supported by the Edge runtime.')\n\t},\n\t// NB: edge runtime uses `recordMetric` for all metric types\n\trecordMetric: (metric: Metric) => {\n\t\treturn CloudflareH.recordMetric({\n\t\t\t...metric,\n\t\t\tsecureSessionId:\n\t\t\t\tmetric.tags?.find((t) => t.name === 'highlight.session_id')\n\t\t\t\t\t?.value ?? '',\n\t\t\trequestId:\n\t\t\t\tmetric.tags?.find((t) => t.name === 'highlight.trace_id')\n\t\t\t\t\t?.value ?? '',\n\t\t})\n\t},\n\trecordCount: function (metric: Metric): void {\n\t\treturn this.recordMetric(metric)\n\t},\n\trecordIncr: function (metric: Omit<Metric, 'value'>): void {\n\t\treturn this.recordMetric({ ...metric, value: 1 })\n\t},\n\trecordHistogram: function (metric: Metric): void {\n\t\treturn this.recordMetric(metric)\n\t},\n\trecordUpDownCounter: function (metric: Metric): void {\n\t\treturn this.recordMetric(metric)\n\t},\n\tasync runWithHeaders<T>(\n\t\tname: string,\n\t\theaders: any,\n\t\tcb: (span: Span) => Promise<T>,\n\t\toptions?: any,\n\t) {\n\t\treturn CloudflareH.runWithHeaders(name, headers, cb, options)\n\t},\n}\n","export { H } from './util/highlight-edge'\nexport { highlightMiddleware } from './util/highlight-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport type { HighlightEnv } from './util/types'\n\nimport * as withHighlightEdge from './util/with-highlight-edge'\n\nimport type { HighlightEnv } from './util/types'\n\nexport function registerHighlight() {}\n\nexport function EdgeHighlight(env: HighlightEnv) {\n\tif (process.env.NEXT_RUNTIME === 'edge') {\n\t\treturn withHighlightEdge.Highlight(env)\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Do not use EdgeHighlight() in the ${process.env.NEXT_RUNTIME} runtime`,\n\t\t)\n\t}\n}\n\nexport function PageRouterHighlight(_: HighlightEnv) {\n\tthrow new Error('Do not use PageRouterHighlight() in the edge runtime.')\n}\n\nexport function AppRouterHighlight(_: HighlightEnv) {\n\tthrow new Error('Do not use AppRouterHighlight() in the edge runtime.')\n}\n","import type { NodeOptions } from '@highlight-run/node'\nimport { H } from './highlight-edge'\n\nexport type NextFetchEvent = {\n\tparams: Promise<Record<string, string>>\n}\nexport type NextRequest = any\n\nexport type HighlightEnv = NodeOptions\n\nexport type EdgeHandler = (\n\trequest: NextRequest,\n\tcontext: NextFetchEvent,\n) => Promise<Response>\n\nexport function Highlight(env: HighlightEnv) {\n\treturn function withHighlight(handler: EdgeHandler) {\n\t\tif (env.enableFsInstrumentation) {\n\t\t\tconsole.warn(\n\t\t\t\t'enableFsInstrumentation is incompatible with Edge... disabling now.',\n\t\t\t)\n\n\t\t\tenv.enableFsInstrumentation = false\n\t\t}\n\t\tH.initEdge(env)\n\t\treturn async function (request: NextRequest, context: NextFetchEvent) {\n\t\t\ttry {\n\t\t\t\treturn await H.runWithHeaders(\n\t\t\t\t\t`${request.method?.toUpperCase()} - ${request.url}`,\n\t\t\t\t\trequest.headers,\n\t\t\t\t\tasync (span) => {\n\t\t\t\t\t\tspan.setAttribute('next.runtime', 'edge')\n\t\t\t\t\t\treturn await handler(request, context)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t} finally {\n\t\t\t\tawait H.flush()\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["H","CloudflareH","init","_","Error","isInitialized","initEdge","env","cloudflareEnv","HIGHLIGHT_PROJECT_ID","projectID","HIGHLIGHT_OTLP_ENDPOINT","otlpEndpoint","serviceVersion","console","warn","enableFsInstrumentation","serviceName","metrics","highlightContext","m","recordMetric","secureSessionId","requestId","flush","async","consumeAndFlush","error","consumeError","this","stop","metric","tags","find","t","name","value","recordCount","recordIncr","recordHistogram","recordUpDownCounter","headers","cb","options","runWithHeaders","process","NEXT_RUNTIME","handler","request","context","method","toUpperCase","url","span","setAttribute","withHighlightEdge.Highlight"],"mappings":"8HAUO,MAAMA,EAAwB,IACjCC,EAAAA,EACHC,KAAOC,IACN,MAAM,IAAIC,MACT,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