{"version":3,"file":"instrumentFetcher.js","sources":["../../../../src/instrumentations/worker/instrumentFetcher.ts"],"sourcesContent":["import type { Fetcher } from '@cloudflare/workers-types';\nimport { _INTERNAL_getTracingHeadersForFetchRequest } from '@sentry/core';\n\n/**\n * Wraps a fetch-like function to create a span and propagate trace headers\n * (`sentry-trace` and `baggage`) on the outgoing request.\n *\n * Useful for instrumenting Cloudflare bindings that expose a `fetch` method\n * (e.g. Durable Object stubs, Service bindings).\n */\nexport function instrumentFetcher(fetchFn: Fetcher['fetch']): Fetcher['fetch'] {\n return function (input: RequestInfo | URL, init?: RequestInit): Promise {\n const headers = _INTERNAL_getTracingHeadersForFetchRequest(input, { headers: init?.headers });\n\n if (input instanceof Request && init === undefined) {\n if (!headers) {\n return fetchFn(input);\n }\n\n // Newly created headers already include the previous headers from the original request\n // so we can clone the request and pass in all headers.\n const requestWithTracing = new Request(input, { headers: headers as HeadersInit });\n\n return fetchFn(requestWithTracing);\n }\n\n const mergedInit = {\n ...init,\n ...(headers ? { headers } : {}),\n } as NonNullable[1]>;\n\n return fetchFn(input, mergedInit);\n };\n}\n"],"names":["_INTERNAL_getTracingHeadersForFetchRequest"],"mappings":";;;;AAUO,SAAS,kBAAkB,OAAA,EAA6C;AAC7E,EAAA,OAAO,SAAU,OAA0B,IAAA,EAAuC;AAChF,IAAA,MAAM,UAAUA,+CAAA,CAA2C,KAAA,EAAO,EAAE,OAAA,EAAS,IAAA,EAAM,SAAS,CAAA;AAE5F,IAAA,IAAI,KAAA,YAAiB,OAAA,IAAW,IAAA,KAAS,MAAA,EAAW;AAClD,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,OAAO,QAAQ,KAAK,CAAA;AAAA,MACtB;AAIA,MAAA,MAAM,qBAAqB,IAAI,OAAA,CAAQ,KAAA,EAAO,EAAE,SAAiC,CAAA;AAEjF,MAAA,OAAO,QAAQ,kBAAkB,CAAA;AAAA,IACnC;AAEA,IAAA,MAAM,UAAA,GAAa;AAAA,MACjB,GAAG,IAAA;AAAA,MACH,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY;AAAC,KAC/B;AAEA,IAAA,OAAO,OAAA,CAAQ,OAAO,UAAU,CAAA;AAAA,EAClC,CAAA;AACF;;;;"}