@sentry/cloudflare 11.3.0 → 11.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/build/cjs/dev/baseSdk.js +4 -1
  2. package/build/cjs/dev/baseSdk.js.map +1 -1
  3. package/build/cjs/dev/durableobject.js +2 -2
  4. package/build/cjs/dev/durableobject.js.map +1 -1
  5. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js +1 -1
  6. package/build/cjs/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  7. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js +1 -1
  8. package/build/cjs/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  9. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +1 -1
  10. package/build/cjs/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  11. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js +1 -1
  12. package/build/cjs/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  13. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js +2 -2
  14. package/build/cjs/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  15. package/build/cjs/dev/instrumentations/worker/instrumentD1.js +2 -2
  16. package/build/cjs/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  17. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js +1 -1
  18. package/build/cjs/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  19. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js +1 -1
  20. package/build/cjs/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  21. package/build/cjs/dev/instrumentations/worker/instrumentR2.js +1 -1
  22. package/build/cjs/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  23. package/build/cjs/dev/options.js +1 -1
  24. package/build/cjs/dev/options.js.map +1 -1
  25. package/build/cjs/dev/utils/asyncContextStrategy.js +13 -0
  26. package/build/cjs/dev/utils/asyncContextStrategy.js.map +1 -0
  27. package/build/cjs/dev/withSentry.js +2 -2
  28. package/build/cjs/dev/withSentry.js.map +1 -1
  29. package/build/cjs/dev/workflows.js +3 -3
  30. package/build/cjs/dev/workflows.js.map +1 -1
  31. package/build/cjs/dev/wrapRequestHandlerWithInit.js +2 -2
  32. package/build/cjs/dev/wrapRequestHandlerWithInit.js.map +1 -1
  33. package/build/cjs/prod/baseSdk.js +4 -1
  34. package/build/cjs/prod/baseSdk.js.map +1 -1
  35. package/build/cjs/prod/durableobject.js +2 -2
  36. package/build/cjs/prod/durableobject.js.map +1 -1
  37. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js +1 -1
  38. package/build/cjs/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  39. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js +1 -1
  40. package/build/cjs/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  41. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +1 -1
  42. package/build/cjs/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  43. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js +1 -1
  44. package/build/cjs/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  45. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js +2 -2
  46. package/build/cjs/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  47. package/build/cjs/prod/instrumentations/worker/instrumentD1.js +2 -2
  48. package/build/cjs/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  49. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js +1 -1
  50. package/build/cjs/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  51. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js +1 -1
  52. package/build/cjs/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  53. package/build/cjs/prod/instrumentations/worker/instrumentR2.js +1 -1
  54. package/build/cjs/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  55. package/build/cjs/prod/options.js +1 -1
  56. package/build/cjs/prod/options.js.map +1 -1
  57. package/build/cjs/prod/utils/asyncContextStrategy.js +13 -0
  58. package/build/cjs/prod/utils/asyncContextStrategy.js.map +1 -0
  59. package/build/cjs/prod/withSentry.js +2 -2
  60. package/build/cjs/prod/withSentry.js.map +1 -1
  61. package/build/cjs/prod/workflows.js +3 -3
  62. package/build/cjs/prod/workflows.js.map +1 -1
  63. package/build/cjs/prod/wrapRequestHandlerWithInit.js +2 -2
  64. package/build/cjs/prod/wrapRequestHandlerWithInit.js.map +1 -1
  65. package/build/esm/dev/baseSdk.js +5 -2
  66. package/build/esm/dev/baseSdk.js.map +1 -1
  67. package/build/esm/dev/durableobject.js +2 -2
  68. package/build/esm/dev/durableobject.js.map +1 -1
  69. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js +3 -3
  70. package/build/esm/dev/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  71. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js +3 -3
  72. package/build/esm/dev/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  73. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -3
  74. package/build/esm/dev/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  75. package/build/esm/dev/instrumentations/instrumentSqlStorage.js +3 -3
  76. package/build/esm/dev/instrumentations/instrumentSqlStorage.js.map +1 -1
  77. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js +2 -2
  78. package/build/esm/dev/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  79. package/build/esm/dev/instrumentations/worker/instrumentD1.js +4 -4
  80. package/build/esm/dev/instrumentations/worker/instrumentD1.js.map +1 -1
  81. package/build/esm/dev/instrumentations/worker/instrumentQueue.js +3 -3
  82. package/build/esm/dev/instrumentations/worker/instrumentQueue.js.map +1 -1
  83. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js +3 -3
  84. package/build/esm/dev/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  85. package/build/esm/dev/instrumentations/worker/instrumentR2.js +3 -3
  86. package/build/esm/dev/instrumentations/worker/instrumentR2.js.map +1 -1
  87. package/build/esm/dev/options.js +2 -2
  88. package/build/esm/dev/options.js.map +1 -1
  89. package/build/esm/dev/package.json +1 -1
  90. package/build/esm/dev/utils/asyncContextStrategy.js +11 -0
  91. package/build/esm/dev/utils/asyncContextStrategy.js.map +1 -0
  92. package/build/esm/dev/withSentry.js +2 -2
  93. package/build/esm/dev/withSentry.js.map +1 -1
  94. package/build/esm/dev/workflows.js +5 -5
  95. package/build/esm/dev/workflows.js.map +1 -1
  96. package/build/esm/dev/wrapRequestHandlerWithInit.js +1 -1
  97. package/build/esm/dev/wrapRequestHandlerWithInit.js.map +1 -1
  98. package/build/esm/prod/baseSdk.js +5 -2
  99. package/build/esm/prod/baseSdk.js.map +1 -1
  100. package/build/esm/prod/durableobject.js +2 -2
  101. package/build/esm/prod/durableobject.js.map +1 -1
  102. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js +3 -3
  103. package/build/esm/prod/instrumentations/agents/instrumentAgentCallableRpc.js.map +1 -1
  104. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js +3 -3
  105. package/build/esm/prod/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  106. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js +3 -3
  107. package/build/esm/prod/instrumentations/instrumentDurableObjectSyncKvStorage.js.map +1 -1
  108. package/build/esm/prod/instrumentations/instrumentSqlStorage.js +3 -3
  109. package/build/esm/prod/instrumentations/instrumentSqlStorage.js.map +1 -1
  110. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js +2 -2
  111. package/build/esm/prod/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  112. package/build/esm/prod/instrumentations/worker/instrumentD1.js +4 -4
  113. package/build/esm/prod/instrumentations/worker/instrumentD1.js.map +1 -1
  114. package/build/esm/prod/instrumentations/worker/instrumentQueue.js +3 -3
  115. package/build/esm/prod/instrumentations/worker/instrumentQueue.js.map +1 -1
  116. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js +3 -3
  117. package/build/esm/prod/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  118. package/build/esm/prod/instrumentations/worker/instrumentR2.js +3 -3
  119. package/build/esm/prod/instrumentations/worker/instrumentR2.js.map +1 -1
  120. package/build/esm/prod/options.js +2 -2
  121. package/build/esm/prod/options.js.map +1 -1
  122. package/build/esm/prod/package.json +1 -1
  123. package/build/esm/prod/utils/asyncContextStrategy.js +11 -0
  124. package/build/esm/prod/utils/asyncContextStrategy.js.map +1 -0
  125. package/build/esm/prod/withSentry.js +2 -2
  126. package/build/esm/prod/withSentry.js.map +1 -1
  127. package/build/esm/prod/workflows.js +5 -5
  128. package/build/esm/prod/workflows.js.map +1 -1
  129. package/build/esm/prod/wrapRequestHandlerWithInit.js +1 -1
  130. package/build/esm/prod/wrapRequestHandlerWithInit.js.map +1 -1
  131. package/build/types/baseSdk.d.ts.map +1 -1
  132. package/build/types/index.d.ts.map +1 -1
  133. package/build/types/instrumentations/instrumentSqlStorage.d.ts.map +1 -1
  134. package/build/types/instrumentations/worker/instrumentD1.d.ts.map +1 -1
  135. package/build/types/instrumentations/worker/instrumentR2.d.ts.map +1 -1
  136. package/build/types/utils/asyncContextStrategy.d.ts +6 -0
  137. package/build/types/utils/asyncContextStrategy.d.ts.map +1 -0
  138. package/build/types/workflows.d.ts.map +1 -1
  139. package/build/types/wrapRequestHandlerWithInit.d.ts.map +1 -1
  140. package/package.json +5 -5
  141. package/build/cjs/dev/utils/streaming.js +0 -16
  142. package/build/cjs/dev/utils/streaming.js.map +0 -1
  143. package/build/cjs/prod/utils/streaming.js +0 -16
  144. package/build/cjs/prod/utils/streaming.js.map +0 -1
  145. package/build/esm/dev/utils/streaming.js +0 -14
  146. package/build/esm/dev/utils/streaming.js.map +0 -1
  147. package/build/esm/prod/utils/streaming.js +0 -14
  148. package/build/esm/prod/utils/streaming.js.map +0 -1
  149. package/build/types/utils/streaming.d.ts +0 -17
  150. package/build/types/utils/streaming.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentR2.js","sources":["../../../../../src/instrumentations/worker/instrumentR2.ts"],"sourcesContent":["import type { R2Bucket, R2ListOptions, R2MultipartUpload } from '@cloudflare/workers-types';\nimport {\n CLOUDFLARE_R2_BUCKET,\n CLOUDFLARE_R2_OPERATION,\n CLOUDFLARE_R2_REQUEST_DELIMITER,\n CLOUDFLARE_R2_REQUEST_KEY,\n CLOUDFLARE_R2_REQUEST_PART_NUMBER,\n CLOUDFLARE_R2_REQUEST_PREFIX,\n SENTRY_OP,\n} from '@sentry/conventions/attributes';\nimport {\n OBJECT_DELETE,\n OBJECT_GET,\n OBJECT_HEAD,\n OBJECT_LIST,\n OBJECT_MULTIPART_UPLOAD_ABORT,\n OBJECT_MULTIPART_UPLOAD_COMPLETE,\n OBJECT_MULTIPART_UPLOAD_CREATE,\n OBJECT_PUT,\n OBJECT_UPLOAD_PART,\n} from '@sentry/conventions/op';\nimport { isObjectLike, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\n\nconst ORIGIN = 'auto.faas.cloudflare.r2';\n\nconst R2_OPERATIONS = {\n get: { spanName: 'r2_get', op: OBJECT_GET, operation: 'GetObject' },\n head: { spanName: 'r2_head', op: OBJECT_HEAD, operation: 'HeadObject' },\n put: { spanName: 'r2_put', op: OBJECT_PUT, operation: 'PutObject' },\n delete: { spanName: 'r2_delete', op: OBJECT_DELETE, operation: 'DeleteObject' },\n list: { spanName: 'r2_list', op: OBJECT_LIST, operation: 'ListObjects' },\n uploadPart: { spanName: 'r2_uploadPart', op: OBJECT_UPLOAD_PART, operation: 'UploadPart' },\n abortMultipartUpload: {\n spanName: 'r2_abortMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_ABORT,\n operation: 'AbortMultipartUpload',\n },\n createMultipartUpload: {\n spanName: 'r2_createMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_CREATE,\n operation: 'CreateMultipartUpload',\n },\n completeMultipartUpload: {\n spanName: 'r2_completeMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_COMPLETE,\n operation: 'CompleteMultipartUpload',\n },\n} as const;\n\ntype R2OperationKey = keyof typeof R2_OPERATIONS;\n\nfunction isR2ListOptions(key: unknown): key is R2ListOptions {\n return isObjectLike(key) && !Array.isArray(key);\n}\n\nfunction createSpanOptions(bindingName: string, r2Op: R2OperationKey, key?: string | string[] | R2ListOptions) {\n const { spanName, op, operation } = R2_OPERATIONS[r2Op];\n const requestKey = Array.isArray(key) ? key.join(', ') : typeof key === 'string' ? key : undefined;\n\n return {\n op,\n name: spanName,\n attributes: {\n [CLOUDFLARE_R2_OPERATION]: operation,\n [CLOUDFLARE_R2_BUCKET]: bindingName,\n ...(requestKey !== undefined && { [CLOUDFLARE_R2_REQUEST_KEY]: requestKey }),\n ...(isR2ListOptions(key) && key.prefix !== undefined && { [CLOUDFLARE_R2_REQUEST_PREFIX]: key.prefix }),\n ...(isR2ListOptions(key) && key.delimiter !== undefined && { [CLOUDFLARE_R2_REQUEST_DELIMITER]: key.delimiter }),\n [SENTRY_OP]: op,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n },\n };\n}\n\nfunction instrumentR2MultipartUpload(upload: R2MultipartUpload, bindingName: string): R2MultipartUpload {\n const { key } = upload;\n\n return new Proxy(upload, {\n get(target, prop, receiver) {\n if (prop === 'uploadPart') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2MultipartUpload['uploadPart']>) {\n const [partNumber] = args;\n const spanOptions = createSpanOptions(bindingName, 'uploadPart', key);\n\n return startSpan(\n {\n ...spanOptions,\n attributes: {\n ...spanOptions.attributes,\n [CLOUDFLARE_R2_REQUEST_PART_NUMBER]: partNumber,\n },\n },\n () => Reflect.apply(original, target, args),\n );\n };\n }\n\n if (prop === 'abort') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown) {\n return startSpan(createSpanOptions(bindingName, 'abortMultipartUpload', key), () =>\n Reflect.apply(original, target, []),\n );\n };\n }\n\n if (prop === 'complete') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2MultipartUpload['complete']>) {\n return startSpan(createSpanOptions(bindingName, 'completeMultipartUpload', key), () =>\n Reflect.apply(original, target, args),\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\n/**\n * Wraps a Cloudflare R2 Bucket binding to create spans on bucket operations.\n *\n * Instrumented methods: get, head, put, delete, list, createMultipartUpload,\n * resumeMultipartUpload (and the resulting multipart upload operations).\n */\nexport function instrumentR2Bucket<T extends R2Bucket>(bucket: T, bindingName: string): T {\n return new Proxy(bucket, {\n get(target, prop, receiver) {\n if (prop === 'get' || prop === 'head' || prop === 'put' || prop === 'delete' || prop === 'list') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2Bucket[typeof prop]>) {\n const [key] = args;\n\n return startSpan(createSpanOptions(bindingName, prop, key), () => Reflect.apply(original, target, args));\n };\n }\n\n if (prop === 'createMultipartUpload') {\n const original = Reflect.get(target, prop, receiver) as R2Bucket['createMultipartUpload'];\n\n return function (this: unknown, ...args: Parameters<R2Bucket['createMultipartUpload']>) {\n const [key] = args;\n\n return startSpan(createSpanOptions(bindingName, 'createMultipartUpload', key), async () => {\n const upload = await Reflect.apply(original, target, args);\n return instrumentR2MultipartUpload(upload, bindingName);\n });\n };\n }\n\n if (prop === 'resumeMultipartUpload') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2Bucket['resumeMultipartUpload']>) {\n const upload = Reflect.apply(original, target, args);\n\n return instrumentR2MultipartUpload(upload, bindingName);\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n"],"names":["OBJECT_GET","OBJECT_HEAD","OBJECT_PUT","OBJECT_DELETE","OBJECT_LIST","OBJECT_UPLOAD_PART","OBJECT_MULTIPART_UPLOAD_ABORT","OBJECT_MULTIPART_UPLOAD_CREATE","OBJECT_MULTIPART_UPLOAD_COMPLETE","isObjectLike","CLOUDFLARE_R2_OPERATION","CLOUDFLARE_R2_BUCKET","CLOUDFLARE_R2_REQUEST_KEY","CLOUDFLARE_R2_REQUEST_PREFIX","CLOUDFLARE_R2_REQUEST_DELIMITER","SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","CLOUDFLARE_R2_REQUEST_PART_NUMBER"],"mappings":";;;;;;AAuBA,MAAM,MAAA,GAAS,yBAAA;AAEf,MAAM,aAAA,GAAgB;AAAA,EACpB,KAAK,EAAE,QAAA,EAAU,UAAU,EAAA,EAAIA,aAAA,EAAY,WAAW,WAAA,EAAY;AAAA,EAClE,MAAM,EAAE,QAAA,EAAU,WAAW,EAAA,EAAIC,cAAA,EAAa,WAAW,YAAA,EAAa;AAAA,EACtE,KAAK,EAAE,QAAA,EAAU,UAAU,EAAA,EAAIC,aAAA,EAAY,WAAW,WAAA,EAAY;AAAA,EAClE,QAAQ,EAAE,QAAA,EAAU,aAAa,EAAA,EAAIC,gBAAA,EAAe,WAAW,cAAA,EAAe;AAAA,EAC9E,MAAM,EAAE,QAAA,EAAU,WAAW,EAAA,EAAIC,cAAA,EAAa,WAAW,aAAA,EAAc;AAAA,EACvE,YAAY,EAAE,QAAA,EAAU,iBAAiB,EAAA,EAAIC,qBAAA,EAAoB,WAAW,YAAA,EAAa;AAAA,EACzF,oBAAA,EAAsB;AAAA,IACpB,QAAA,EAAU,yBAAA;AAAA,IACV,EAAA,EAAIC,gCAAA;AAAA,IACJ,SAAA,EAAW;AAAA,GACb;AAAA,EACA,qBAAA,EAAuB;AAAA,IACrB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AAM,CAAC,GAAG,CAAA,GAAI,IAAA;AAEd,UAAA,OAAOA,eAAU,iBAAA,CAAkB,WAAA,EAAa,uBAAA,EAAyB,GAAG,GAAG,YAAY;AACzF,YAAA,MAAM,SAAS,MAAM,OAAA,CAAQ,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AACzD,YAAA,OAAO,2BAAA,CAA4B,QAAQ,WAAW,CAAA;AAAA,UACxD,CAAC,CAAA;AAAA,QACH,CAAA;AAAA,MACF;AAEA,MAAA,IAAI,SAAS,uBAAA,EAAyB;AACpC,QAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,MAAM,QAAQ,CAAA;AAEnD,QAAA,OAAO,YAA4B,IAAA,EAAqD;AACtF,UAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,CAAM,QAAA,EAAU,QAAQ,IAAI,CAAA;AAEnD,UAAA,OAAO,2BAAA,CAA4B,QAAQ,WAAW,CAAA;AAAA,QACxD,CAAA;AAAA,MACF;AAEA,MAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,QAAQ,CAAA;AAAA,IAC3C;AAAA,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"instrumentR2.js","sources":["../../../../../src/instrumentations/worker/instrumentR2.ts"],"sourcesContent":["import type { R2Bucket, R2ListOptions, R2MultipartUpload } from '@cloudflare/workers-types';\nimport {\n CLOUDFLARE_R2_BUCKET,\n CLOUDFLARE_R2_OPERATION,\n CLOUDFLARE_R2_REQUEST_DELIMITER,\n CLOUDFLARE_R2_REQUEST_KEY,\n CLOUDFLARE_R2_REQUEST_PART_NUMBER,\n CLOUDFLARE_R2_REQUEST_PREFIX,\n SENTRY_OP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport {\n OBJECT_DELETE,\n OBJECT_GET,\n OBJECT_HEAD,\n OBJECT_LIST,\n OBJECT_MULTIPART_UPLOAD_ABORT,\n OBJECT_MULTIPART_UPLOAD_COMPLETE,\n OBJECT_MULTIPART_UPLOAD_CREATE,\n OBJECT_PUT,\n OBJECT_UPLOAD_PART,\n} from '@sentry/conventions/op';\nimport { isObjectLike, startSpan } from '@sentry/core';\n\nconst ORIGIN = 'auto.faas.cloudflare.r2';\n\nconst R2_OPERATIONS = {\n get: { spanName: 'r2_get', op: OBJECT_GET, operation: 'GetObject' },\n head: { spanName: 'r2_head', op: OBJECT_HEAD, operation: 'HeadObject' },\n put: { spanName: 'r2_put', op: OBJECT_PUT, operation: 'PutObject' },\n delete: { spanName: 'r2_delete', op: OBJECT_DELETE, operation: 'DeleteObject' },\n list: { spanName: 'r2_list', op: OBJECT_LIST, operation: 'ListObjects' },\n uploadPart: { spanName: 'r2_uploadPart', op: OBJECT_UPLOAD_PART, operation: 'UploadPart' },\n abortMultipartUpload: {\n spanName: 'r2_abortMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_ABORT,\n operation: 'AbortMultipartUpload',\n },\n createMultipartUpload: {\n spanName: 'r2_createMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_CREATE,\n operation: 'CreateMultipartUpload',\n },\n completeMultipartUpload: {\n spanName: 'r2_completeMultipartUpload',\n op: OBJECT_MULTIPART_UPLOAD_COMPLETE,\n operation: 'CompleteMultipartUpload',\n },\n} as const;\n\ntype R2OperationKey = keyof typeof R2_OPERATIONS;\n\nfunction isR2ListOptions(key: unknown): key is R2ListOptions {\n return isObjectLike(key) && !Array.isArray(key);\n}\n\nfunction createSpanOptions(bindingName: string, r2Op: R2OperationKey, key?: string | string[] | R2ListOptions) {\n const { spanName, op, operation } = R2_OPERATIONS[r2Op];\n const requestKey = Array.isArray(key) ? key.join(', ') : typeof key === 'string' ? key : undefined;\n\n return {\n op,\n name: spanName,\n attributes: {\n [CLOUDFLARE_R2_OPERATION]: operation,\n [CLOUDFLARE_R2_BUCKET]: bindingName,\n ...(requestKey !== undefined && { [CLOUDFLARE_R2_REQUEST_KEY]: requestKey }),\n ...(isR2ListOptions(key) && key.prefix !== undefined && { [CLOUDFLARE_R2_REQUEST_PREFIX]: key.prefix }),\n ...(isR2ListOptions(key) && key.delimiter !== undefined && { [CLOUDFLARE_R2_REQUEST_DELIMITER]: key.delimiter }),\n [SENTRY_OP]: op,\n [SENTRY_ORIGIN]: ORIGIN,\n },\n };\n}\n\nfunction instrumentR2MultipartUpload(upload: R2MultipartUpload, bindingName: string): R2MultipartUpload {\n const { key } = upload;\n\n return new Proxy(upload, {\n get(target, prop, receiver) {\n if (prop === 'uploadPart') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2MultipartUpload['uploadPart']>) {\n const [partNumber] = args;\n const spanOptions = createSpanOptions(bindingName, 'uploadPart', key);\n\n return startSpan(\n {\n ...spanOptions,\n attributes: {\n ...spanOptions.attributes,\n [CLOUDFLARE_R2_REQUEST_PART_NUMBER]: partNumber,\n },\n },\n () => Reflect.apply(original, target, args),\n );\n };\n }\n\n if (prop === 'abort') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown) {\n return startSpan(createSpanOptions(bindingName, 'abortMultipartUpload', key), () =>\n Reflect.apply(original, target, []),\n );\n };\n }\n\n if (prop === 'complete') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2MultipartUpload['complete']>) {\n return startSpan(createSpanOptions(bindingName, 'completeMultipartUpload', key), () =>\n Reflect.apply(original, target, args),\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n\n/**\n * Wraps a Cloudflare R2 Bucket binding to create spans on bucket operations.\n *\n * Instrumented methods: get, head, put, delete, list, createMultipartUpload,\n * resumeMultipartUpload (and the resulting multipart upload operations).\n */\nexport function instrumentR2Bucket<T extends R2Bucket>(bucket: T, bindingName: string): T {\n return new Proxy(bucket, {\n get(target, prop, receiver) {\n if (prop === 'get' || prop === 'head' || prop === 'put' || prop === 'delete' || prop === 'list') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2Bucket[typeof prop]>) {\n const [key] = args;\n\n return startSpan(createSpanOptions(bindingName, prop, key), () => Reflect.apply(original, target, args));\n };\n }\n\n if (prop === 'createMultipartUpload') {\n const original = Reflect.get(target, prop, receiver) as R2Bucket['createMultipartUpload'];\n\n return function (this: unknown, ...args: Parameters<R2Bucket['createMultipartUpload']>) {\n const [key] = args;\n\n return startSpan(createSpanOptions(bindingName, 'createMultipartUpload', key), async () => {\n const upload = await Reflect.apply(original, target, args);\n return instrumentR2MultipartUpload(upload, bindingName);\n });\n };\n }\n\n if (prop === 'resumeMultipartUpload') {\n const original = Reflect.get(target, prop, receiver);\n\n return function (this: unknown, ...args: Parameters<R2Bucket['resumeMultipartUpload']>) {\n const upload = Reflect.apply(original, target, args);\n\n return instrumentR2MultipartUpload(upload, bindingName);\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n });\n}\n"],"names":["OBJECT_GET","OBJECT_HEAD","OBJECT_PUT","OBJECT_DELETE","OBJECT_LIST","OBJECT_UPLOAD_PART","OBJECT_MULTIPART_UPLOAD_ABORT","OBJECT_MULTIPART_UPLOAD_CREATE","OBJECT_MULTIPART_UPLOAD_COMPLETE","isObjectLike","CLOUDFLARE_R2_OPERATION","CLOUDFLARE_R2_BUCKET","CLOUDFLARE_R2_REQUEST_KEY","CLOUDFLARE_R2_REQUEST_PREFIX","CLOUDFLARE_R2_REQUEST_DELIMITER","SENTRY_OP","SENTRY_ORIGIN","startSpan","CLOUDFLARE_R2_REQUEST_PART_NUMBER"],"mappings":";;;;;;AAwBA,MAAM,MAAA,GAAS,yBAAA;AAEf,MAAM,aAAA,GAAgB;AAAA,EACpB,KAAK,EAAE,QAAA,EAAU,UAAU,EAAA,EAAIA,aAAA,EAAY,WAAW,WAAA,EAAY;AAAA,EAClE,MAAM,EAAE,QAAA,EAAU,WAAW,EAAA,EAAIC,cAAA,EAAa,WAAW,YAAA,EAAa;AAAA,EACtE,KAAK,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AA,GACD,CAAA;AACH;;;;"}
@@ -9,7 +9,7 @@ function getEnvVar(env, varName) {
9
9
  return core.isObjectLike(env) && varName in env && typeof env[varName] === "string" ? env[varName] : void 0;
10
10
  }
11
11
  function getFinalOptions(userOptions = {}, env) {
12
- if (typeof env !== "object" || env === null) {
12
+ if (!core.isObjectLike(env)) {
13
13
  return userOptions;
14
14
  }
15
15
  const release = "SENTRY_RELEASE" in env && typeof env.SENTRY_RELEASE === "string" ? env.SENTRY_RELEASE : "CF_VERSION_METADATA" in env && isVersionMetadata(env.CF_VERSION_METADATA) ? env.CF_VERSION_METADATA.id : void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sources":["../../../src/options.ts"],"sourcesContent":["import { isObjectLike, envToBool } from '@sentry/core';\nimport type { CloudflareOptions } from './client';\n\n/**\n * Cloudflare's version metadata binding structure.\n * @see https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata/\n */\ninterface CfVersionMetadata {\n id: string;\n tag?: string;\n timestamp?: string;\n}\n\n/**\n * Checks if the value is a valid CF_VERSION_METADATA binding.\n */\nfunction isVersionMetadata(value: unknown): value is CfVersionMetadata {\n return isObjectLike(value) && 'id' in value && typeof value.id === 'string';\n}\n\nfunction getEnvVar<T extends Record<string, unknown>>(env: unknown, varName: keyof T): string | undefined {\n return isObjectLike(env) && varName in env && typeof (env as T)[varName] === 'string'\n ? ((env as T)[varName] as string)\n : undefined;\n}\n\n/**\n * Merges the options passed in from the user with the options we read from\n * the Cloudflare `env` environment variable object.\n *\n * Release is determined with the following priority (highest to lowest):\n * 1. User-provided release option\n * 2. SENTRY_RELEASE environment variable\n * 3. CF_VERSION_METADATA.id binding (if configured in the wrangler config)\n *\n * @param userOptions - The options passed in from the user.\n * @param env - The environment variables.\n *\n * @returns The final options.\n */\nexport function getFinalOptions(userOptions: CloudflareOptions = {}, env: unknown): CloudflareOptions {\n if (typeof env !== 'object' || env === null) {\n return userOptions;\n }\n\n // Priority: userOptions.release > SENTRY_RELEASE > CF_VERSION_METADATA.id\n const release =\n 'SENTRY_RELEASE' in env && typeof env.SENTRY_RELEASE === 'string'\n ? env.SENTRY_RELEASE\n : 'CF_VERSION_METADATA' in env && isVersionMetadata(env.CF_VERSION_METADATA)\n ? env.CF_VERSION_METADATA.id\n : undefined;\n\n const tracesSampleRate =\n userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACES_SAMPLE_RATE') ?? '');\n\n // Spotlight precedence (mirrors node-core's getSpotlightConfig):\n // - false or explicit string from options: use as-is\n // - true: enable, but prefer a custom URL from the env var if set\n // - undefined: defer entirely to the env var (bool or URL)\n /*! rollup-include-development-only */\n const spotlight = getSpotlightFromEnv(userOptions.spotlight, getEnvVar(env, 'SENTRY_SPOTLIGHT'));\n /*! rollup-include-development-only-end */\n\n return {\n release,\n ...userOptions,\n dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),\n environment: userOptions.environment ?? getEnvVar(env, 'SENTRY_ENVIRONMENT'),\n tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,\n debug: userOptions.debug ?? envToBool(getEnvVar(env, 'SENTRY_DEBUG')),\n tunnel: userOptions.tunnel ?? getEnvVar(env, 'SENTRY_TUNNEL'),\n traceLifecycle: userOptions.traceLifecycle ?? getTraceLifecycleFromEnv(getEnvVar(env, 'SENTRY_TRACE_LIFECYCLE')),\n /*! rollup-include-development-only */\n spotlight,\n /*! rollup-include-development-only-end */\n };\n}\n\n/**\n * Resolve the spotlight option from a user-supplied value and an env binding string.\n * Mirrors node-core's `getSpotlightConfig` precedence:\n * - `false` or explicit string from options → use as-is\n * - `true` → enable, but prefer a custom URL from the env var if set\n * - `undefined` → defer entirely to the env var (bool or URL)\n */\nfunction getSpotlightFromEnv(\n optionsSpotlight: boolean | string | undefined,\n envVar: string | undefined,\n): boolean | string | undefined {\n if (optionsSpotlight === false) {\n return false;\n }\n if (typeof optionsSpotlight === 'string') {\n return optionsSpotlight;\n }\n\n // optionsSpotlight is true or undefined\n const envBool = envToBool(envVar, { strict: true });\n const envUrl = envBool === null && envVar ? envVar : undefined;\n\n return optionsSpotlight === true\n ? (envUrl ?? true) // true: use env URL if present, otherwise true\n : (envBool ?? envUrl); // undefined: use env var (bool or URL)\n}\n\nfunction getTraceLifecycleFromEnv(envVar: string | undefined): 'static' | 'stream' | undefined {\n return envVar === 'stream' || envVar === 'static' ? envVar : undefined;\n}\n"],"names":["isObjectLike","envToBool"],"mappings":";;;;AAgBA,SAAS,kBAAkB,KAAA,EAA4C;AACrE,EAAA,OAAOA,kBAAa,KAAK,CAAA,IAAK,QAAQ,KAAA,IAAS,OAAO,MAAM,EAAA,KAAO,QAAA;AACrE;AAEA,SAAS,SAAA,CAA6C,KAAc,OAAA,EAAsC;AACxG,EAAA,OAAOA,iBAAA,CAAa,GAAG,CAAA,IAAK,OAAA,IAAW,GAAA,IAAO,OAAQ,GAAA,CAAU,OAAO,CAAA,KAAM,QAAA,GACvE,GAAA,CAAU,OAAO,CAAA,GACnB,MAAA;AACN;AAgBO,SAAS,eAAA,CAAgB,WAAA,GAAiC,EAAC,EAAG,GAAA,EAAiC;AACpG,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,IAAA,EAAM;AAC3C,IAAA,OAAO,WAAA;AAAA,EACT;AAGA,EAAA,MAAM,UACJ,gBAAA,IAAoB,GAAA,IAAO,OAAO,GAAA,CAAI,mBAAmB,QAAA,GACrD,GAAA,CAAI,cAAA,GACJ,qBAAA,IAAyB,OAAO,iBAAA,CAAkB,GAAA,CAAI,mBAAmB,CAAA,GACvE,GAAA,CAAI,oBAAoB,EAAA,GACxB,MAAA;AAER,EAAA,MAAM,gBAAA,GACJ,YAAY,gBAAA,IAAoB,UAAA,CAAW,UAAU,GAAA,EAAK,2BAA2B,KAAK,EAAE,CAAA;AAM9F,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAG,WAAA;AAAA,IACH,GAAA,EAAK,WAAA,CAAY,GAAA,IAAO,SAAA,CAAU,KAAK,YAAY,CAAA;AAAA,IACnD,WAAA,EAAa,WAAA,CAAY,WAAA,IAAe,SAAA,CAAU,KAAK,oBAAoB,CAAA;AAAA,IAC3E,gBAAA,EAAkB,QAAA,CAAS,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,MAAA;AAAA,IAClE,OAAO,WAAA,CAAY,KAAA,IAASC,eAAU,SAAA,CAAU,GAAA,EAAK,cAAc,CAAC,CAAA;AAAA,IACpE,MAAA,EAAQ,WAAA,CAAY,MAAA,IAAU,SAAA,CAAU,KAAK,eAAe,CAAA;AAAA,IAC5D,gBAAgB,WAAA,CAAY,cAAA,IAAkB,yBAAyB,SAAA,CAAU,GAAA,EAAK,wBAAwB,CAAC;AAAA,GAC/G;AACJ;AA6BA,SAAS,yBAAyB,MAAA,EAA6D;AAC7F,EAAA,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,KAAW,QAAA,GAAW,MAAA,GAAS,MAAA;AAC/D;;;;"}
1
+ {"version":3,"file":"options.js","sources":["../../../src/options.ts"],"sourcesContent":["import { isObjectLike, envToBool } from '@sentry/core';\nimport type { CloudflareOptions } from './client';\n\n/**\n * Cloudflare's version metadata binding structure.\n * @see https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata/\n */\ninterface CfVersionMetadata {\n id: string;\n tag?: string;\n timestamp?: string;\n}\n\n/**\n * Checks if the value is a valid CF_VERSION_METADATA binding.\n */\nfunction isVersionMetadata(value: unknown): value is CfVersionMetadata {\n return isObjectLike(value) && 'id' in value && typeof value.id === 'string';\n}\n\nfunction getEnvVar<T extends Record<string, unknown>>(env: unknown, varName: keyof T): string | undefined {\n return isObjectLike(env) && varName in env && typeof (env as T)[varName] === 'string'\n ? ((env as T)[varName] as string)\n : undefined;\n}\n\n/**\n * Merges the options passed in from the user with the options we read from\n * the Cloudflare `env` environment variable object.\n *\n * Release is determined with the following priority (highest to lowest):\n * 1. User-provided release option\n * 2. SENTRY_RELEASE environment variable\n * 3. CF_VERSION_METADATA.id binding (if configured in the wrangler config)\n *\n * @param userOptions - The options passed in from the user.\n * @param env - The environment variables.\n *\n * @returns The final options.\n */\nexport function getFinalOptions(userOptions: CloudflareOptions = {}, env: unknown): CloudflareOptions {\n if (!isObjectLike(env)) {\n return userOptions;\n }\n\n // Priority: userOptions.release > SENTRY_RELEASE > CF_VERSION_METADATA.id\n const release =\n 'SENTRY_RELEASE' in env && typeof env.SENTRY_RELEASE === 'string'\n ? env.SENTRY_RELEASE\n : 'CF_VERSION_METADATA' in env && isVersionMetadata(env.CF_VERSION_METADATA)\n ? env.CF_VERSION_METADATA.id\n : undefined;\n\n const tracesSampleRate =\n userOptions.tracesSampleRate ?? parseFloat(getEnvVar(env, 'SENTRY_TRACES_SAMPLE_RATE') ?? '');\n\n // Spotlight precedence (mirrors node-core's getSpotlightConfig):\n // - false or explicit string from options: use as-is\n // - true: enable, but prefer a custom URL from the env var if set\n // - undefined: defer entirely to the env var (bool or URL)\n /*! rollup-include-development-only */\n const spotlight = getSpotlightFromEnv(userOptions.spotlight, getEnvVar(env, 'SENTRY_SPOTLIGHT'));\n /*! rollup-include-development-only-end */\n\n return {\n release,\n ...userOptions,\n dsn: userOptions.dsn ?? getEnvVar(env, 'SENTRY_DSN'),\n environment: userOptions.environment ?? getEnvVar(env, 'SENTRY_ENVIRONMENT'),\n tracesSampleRate: isFinite(tracesSampleRate) ? tracesSampleRate : undefined,\n debug: userOptions.debug ?? envToBool(getEnvVar(env, 'SENTRY_DEBUG')),\n tunnel: userOptions.tunnel ?? getEnvVar(env, 'SENTRY_TUNNEL'),\n traceLifecycle: userOptions.traceLifecycle ?? getTraceLifecycleFromEnv(getEnvVar(env, 'SENTRY_TRACE_LIFECYCLE')),\n /*! rollup-include-development-only */\n spotlight,\n /*! rollup-include-development-only-end */\n };\n}\n\n/**\n * Resolve the spotlight option from a user-supplied value and an env binding string.\n * Mirrors node-core's `getSpotlightConfig` precedence:\n * - `false` or explicit string from options → use as-is\n * - `true` → enable, but prefer a custom URL from the env var if set\n * - `undefined` → defer entirely to the env var (bool or URL)\n */\nfunction getSpotlightFromEnv(\n optionsSpotlight: boolean | string | undefined,\n envVar: string | undefined,\n): boolean | string | undefined {\n if (optionsSpotlight === false) {\n return false;\n }\n if (typeof optionsSpotlight === 'string') {\n return optionsSpotlight;\n }\n\n // optionsSpotlight is true or undefined\n const envBool = envToBool(envVar, { strict: true });\n const envUrl = envBool === null && envVar ? envVar : undefined;\n\n return optionsSpotlight === true\n ? (envUrl ?? true) // true: use env URL if present, otherwise true\n : (envBool ?? envUrl); // undefined: use env var (bool or URL)\n}\n\nfunction getTraceLifecycleFromEnv(envVar: string | undefined): 'static' | 'stream' | undefined {\n return envVar === 'stream' || envVar === 'static' ? envVar : undefined;\n}\n"],"names":["isObjectLike","envToBool"],"mappings":";;;;AAgBA,SAAS,kBAAkB,KAAA,EAA4C;AACrE,EAAA,OAAOA,kBAAa,KAAK,CAAA,IAAK,QAAQ,KAAA,IAAS,OAAO,MAAM,EAAA,KAAO,QAAA;AACrE;AAEA,SAAS,SAAA,CAA6C,KAAc,OAAA,EAAsC;AACxG,EAAA,OAAOA,iBAAA,CAAa,GAAG,CAAA,IAAK,OAAA,IAAW,GAAA,IAAO,OAAQ,GAAA,CAAU,OAAO,CAAA,KAAM,QAAA,GACvE,GAAA,CAAU,OAAO,CAAA,GACnB,MAAA;AACN;AAgBO,SAAS,eAAA,CAAgB,WAAA,GAAiC,EAAC,EAAG,GAAA,EAAiC;AACpG,EAAA,IAAI,CAACA,iBAAA,CAAa,GAAG,CAAA,EAAG;AACtB,IAAA,OAAO,WAAA;AAAA,EACT;AAGA,EAAA,MAAM,UACJ,gBAAA,IAAoB,GAAA,IAAO,OAAO,GAAA,CAAI,mBAAmB,QAAA,GACrD,GAAA,CAAI,cAAA,GACJ,qBAAA,IAAyB,OAAO,iBAAA,CAAkB,GAAA,CAAI,mBAAmB,CAAA,GACvE,GAAA,CAAI,oBAAoB,EAAA,GACxB,MAAA;AAER,EAAA,MAAM,gBAAA,GACJ,YAAY,gBAAA,IAAoB,UAAA,CAAW,UAAU,GAAA,EAAK,2BAA2B,KAAK,EAAE,CAAA;AAM9F,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,GAAG,WAAA;AAAA,IACH,GAAA,EAAK,WAAA,CAAY,GAAA,IAAO,SAAA,CAAU,KAAK,YAAY,CAAA;AAAA,IACnD,WAAA,EAAa,WAAA,CAAY,WAAA,IAAe,SAAA,CAAU,KAAK,oBAAoB,CAAA;AAAA,IAC3E,gBAAA,EAAkB,QAAA,CAAS,gBAAgB,CAAA,GAAI,gBAAA,GAAmB,MAAA;AAAA,IAClE,OAAO,WAAA,CAAY,KAAA,IAASC,eAAU,SAAA,CAAU,GAAA,EAAK,cAAc,CAAC,CAAA;AAAA,IACpE,MAAA,EAAQ,WAAA,CAAY,MAAA,IAAU,SAAA,CAAU,KAAK,eAAe,CAAA;AAAA,IAC5D,gBAAgB,WAAA,CAAY,cAAA,IAAkB,yBAAyB,SAAA,CAAU,GAAA,EAAK,wBAAwB,CAAC;AAAA,GAC/G;AACJ;AA6BA,SAAS,yBAAyB,MAAA,EAA6D;AAC7F,EAAA,OAAO,MAAA,KAAW,QAAA,IAAY,MAAA,KAAW,QAAA,GAAW,MAAA,GAAS,MAAA;AAC/D;;;;"}
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
5
+
6
+ function setAsyncLocalStorageAsyncContextStrategyForWorker() {
7
+ if (!core.getAsyncContextStrategy(core.getMainCarrier()).withActiveSpan) {
8
+ noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy();
9
+ }
10
+ }
11
+
12
+ exports.setAsyncLocalStorageAsyncContextStrategyForWorker = setAsyncLocalStorageAsyncContextStrategyForWorker;
13
+ //# sourceMappingURL=asyncContextStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContextStrategy.js","sources":["../../../../src/utils/asyncContextStrategy.ts"],"sourcesContent":["import { getAsyncContextStrategy, getMainCarrier } from '@sentry/core';\nimport { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\n\n/**\n * Installs the AsyncLocalStorage strategy unless an OpenTelemetry strategy is installed. Both use the same storage,\n * so a switch during a request breaks it (#24603).\n */\nexport function setAsyncLocalStorageAsyncContextStrategyForWorker(): void {\n if (!getAsyncContextStrategy(getMainCarrier()).withActiveSpan) {\n setAsyncLocalStorageAsyncContextStrategy();\n }\n}\n"],"names":["getAsyncContextStrategy","getMainCarrier","setAsyncLocalStorageAsyncContextStrategy"],"mappings":";;;;;AAOO,SAAS,iDAAA,GAA0D;AACxE,EAAA,IAAI,CAACA,4BAAA,CAAwBC,mBAAA,EAAgB,EAAE,cAAA,EAAgB;AAC7D,IAAAC,6DAAA,EAAyC;AAAA,EAC3C;AACF;;;;"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
3
+ const asyncContextStrategy = require('./utils/asyncContextStrategy.js');
4
4
  const instrumentEmail = require('./instrumentations/worker/instrumentEmail.js');
5
5
  const instrumentFetch = require('./instrumentations/worker/instrumentFetch.js');
6
6
  const instrumentQueue = require('./instrumentations/worker/instrumentQueue.js');
@@ -13,7 +13,7 @@ function withSentry(optionsCallback, handler) {
13
13
  if (isCloudflareClass.isCloudflareClass(handler, "WorkerEntrypoint")) {
14
14
  return instrumentWorkerEntrypoint.instrumentWorkerEntrypoint(optionsCallback, handler);
15
15
  }
16
- noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy();
16
+ asyncContextStrategy.setAsyncLocalStorageAsyncContextStrategyForWorker();
17
17
  try {
18
18
  instrumentFetch.instrumentExportedHandlerFetch(handler, optionsCallback);
19
19
  instrumentScheduled.instrumentExportedHandlerScheduled(handler, optionsCallback);
@@ -1 +1 @@
1
- {"version":3,"file":"withSentry.js","sources":["../../../src/withSentry.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';\nimport { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';\nimport { instrumentExportedHandlerQueue } from './instrumentations/worker/instrumentQueue';\nimport { instrumentExportedHandlerScheduled } from './instrumentations/worker/instrumentScheduled';\nimport { instrumentExportedHandlerTail } from './instrumentations/worker/instrumentTail';\nimport { isCloudflareClass } from './utils/isCloudflareClass';\nimport type { AnyExportedHandler, DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport {\n instrumentWorkerEntrypoint,\n type WorkerEntrypointConstructor,\n} from './instrumentations/instrumentWorkerEntrypoint';\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\nexport function withSentry<\n Env = DefaultEnv,\n QueueHandlerMessage = unknown,\n CfHostMetadata = unknown,\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends AnyExportedHandler | WorkerEntrypointConstructor<any, any> =\n | ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>\n | WorkerEntrypointConstructor<Env>,\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<T, Env>) => StrictCloudflareOptions<O> | undefined, handler: T): T {\n if (isCloudflareClass(handler, 'WorkerEntrypoint')) {\n // oxlint-disable-next-line typescript/no-explicit-any\n return instrumentWorkerEntrypoint(optionsCallback as any, handler);\n }\n\n setAsyncLocalStorageAsyncContextStrategy();\n\n try {\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerFetch(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerScheduled(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerEmail(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerQueue(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerTail(handler, optionsCallback as any);\n // This is here because Miniflare sometimes cannot get instrumented\n } catch {\n // Do not console anything here, we don't want to spam the console with errors\n }\n\n return handler;\n}\n"],"names":["isCloudflareClass","instrumentWorkerEntrypoint","setAsyncLocalStorageAsyncContextStrategy","instrumentExportedHandlerFetch","instrumentExportedHandlerScheduled","instrumentExportedHandlerEmail","instrumentExportedHandlerQueue","instrumentExportedHandlerTail"],"mappings":";;;;;;;;;;;AAwBO,SAAS,UAAA,CASd,iBAAsF,OAAA,EAAe;AACrG,EAAA,IAAIA,mCAAA,CAAkB,OAAA,EAAS,kBAAkB,CAAA,EAAG;AAElD,IAAA,OAAOC,qDAAA,CAA2B,iBAAwB,OAAO,CAAA;AAAA,EACnE;AAEA,EAAAC,6DAAA,EAAyC;AAEzC,EAAA,IAAI;AAEF,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,sDAAA,CAAmC,SAAS,eAAsB,CAAA;AAElE,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,4CAAA,CAA8B,SAAS,eAAsB,CAAA;AAAA,EAE/D,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
1
+ {"version":3,"file":"withSentry.js","sources":["../../../src/withSentry.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategyForWorker } from './utils/asyncContextStrategy';\nimport { instrumentExportedHandlerEmail } from './instrumentations/worker/instrumentEmail';\nimport { instrumentExportedHandlerFetch } from './instrumentations/worker/instrumentFetch';\nimport { instrumentExportedHandlerQueue } from './instrumentations/worker/instrumentQueue';\nimport { instrumentExportedHandlerScheduled } from './instrumentations/worker/instrumentScheduled';\nimport { instrumentExportedHandlerTail } from './instrumentations/worker/instrumentTail';\nimport { isCloudflareClass } from './utils/isCloudflareClass';\nimport type { AnyExportedHandler, DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport {\n instrumentWorkerEntrypoint,\n type WorkerEntrypointConstructor,\n} from './instrumentations/instrumentWorkerEntrypoint';\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\nexport function withSentry<\n Env = DefaultEnv,\n QueueHandlerMessage = unknown,\n CfHostMetadata = unknown,\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends AnyExportedHandler | WorkerEntrypointConstructor<any, any> =\n | ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>\n | WorkerEntrypointConstructor<Env>,\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<T, Env>) => StrictCloudflareOptions<O> | undefined, handler: T): T {\n if (isCloudflareClass(handler, 'WorkerEntrypoint')) {\n // oxlint-disable-next-line typescript/no-explicit-any\n return instrumentWorkerEntrypoint(optionsCallback as any, handler);\n }\n\n setAsyncLocalStorageAsyncContextStrategyForWorker();\n\n try {\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerFetch(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerScheduled(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerEmail(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerQueue(handler, optionsCallback as any);\n // oxlint-disable-next-line typescript/no-explicit-any\n instrumentExportedHandlerTail(handler, optionsCallback as any);\n // This is here because Miniflare sometimes cannot get instrumented\n } catch {\n // Do not console anything here, we don't want to spam the console with errors\n }\n\n return handler;\n}\n"],"names":["isCloudflareClass","instrumentWorkerEntrypoint","setAsyncLocalStorageAsyncContextStrategyForWorker","instrumentExportedHandlerFetch","instrumentExportedHandlerScheduled","instrumentExportedHandlerEmail","instrumentExportedHandlerQueue","instrumentExportedHandlerTail"],"mappings":";;;;;;;;;;;AAwBO,SAAS,UAAA,CASd,iBAAsF,OAAA,EAAe;AACrG,EAAA,IAAIA,mCAAA,CAAkB,OAAA,EAAS,kBAAkB,CAAA,EAAG;AAElD,IAAA,OAAOC,qDAAA,CAA2B,iBAAwB,OAAO,CAAA;AAAA,EACnE;AAEA,EAAAC,sEAAA,EAAkD;AAElD,EAAA,IAAI;AAEF,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,sDAAA,CAAmC,SAAS,eAAsB,CAAA;AAElE,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,8CAAA,CAA+B,SAAS,eAAsB,CAAA;AAE9D,IAAAC,4CAAA,CAA8B,SAAS,eAAsB,CAAA;AAAA,EAE/D,CAAA,CAAA,MAAQ;AAAA,EAER;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const attributes = require('@sentry/conventions/attributes');
4
4
  const op = require('@sentry/conventions/op');
5
5
  const core = require('@sentry/core');
6
- const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
6
+ const asyncContextStrategy = require('./utils/asyncContextStrategy.js');
7
7
  const flush = require('./flush.js');
8
8
  const instrument = require('./instrument.js');
9
9
  const instrumentEnv = require('./instrumentations/worker/instrumentEnv.js');
@@ -65,7 +65,7 @@ class WrappedWorkflowStep {
65
65
  "cloudflare.workflow.retries.delay": typeof config?.retries?.delay === "function" ? void 0 : config?.retries?.delay,
66
66
  "cloudflare.workflow.retries.limit": config?.retries?.limit,
67
67
  "cloudflare.workflow.attempt": attempt,
68
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.workflow",
68
+ [attributes.SENTRY_ORIGIN]: "auto.faas.cloudflare.workflow",
69
69
  [attributes.SENTRY_SEGMENT_NAME_SOURCE]: "task"
70
70
  }
71
71
  },
@@ -123,7 +123,7 @@ function instrumentWorkflowWithSentry(optionsCallback, WorkFlowClass) {
123
123
  get(obj, prop, receiver) {
124
124
  if (prop === "run") {
125
125
  return async function(event, step) {
126
- noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy();
126
+ asyncContextStrategy.setAsyncLocalStorageAsyncContextStrategyForWorker();
127
127
  return invocationScope.withInvocationIsolationScope(async (isolationScope) => {
128
128
  const waitUntil = flush.getOriginalWaitUntil(context).bind(context);
129
129
  const client = sdk.init({ ...options, ctx: context, enableDedupe: false });
@@ -1 +1 @@
1
- {"version":3,"file":"workflows.js","sources":["../../../src/workflows.ts"],"sourcesContent":["import { SENTRY_SEGMENT_NAME_SOURCE, CODE_FUNCTION_NAME, SENTRY_OP } from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport type { PropagationContext, Scope } from '@sentry/core';\nimport {\n captureException,\n flush,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type {\n WorkflowDelayDuration,\n WorkflowEntrypoint,\n WorkflowEvent,\n WorkflowSleepDuration,\n WorkflowStep,\n WorkflowStepConfig,\n WorkflowStepContext,\n WorkflowStepEvent,\n WorkflowStepRollbackOptions,\n WorkflowTimeoutDuration,\n} from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { markAsInstrumented } from './instrument';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { addCloudResourceContext } from './scope-utils';\nimport { init } from './sdk';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport { getInvocationState } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\n\nconst UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;\n\n/**\n * Hashes a string to a UUID using SHA-1.\n */\nexport async function deterministicTraceIdFromInstanceId(instanceId: string): Promise<string> {\n const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(instanceId));\n return (\n Array.from(new Uint8Array(buf))\n // We only need the first 16 bytes for the 32 characters\n .slice(0, 16)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n );\n}\n\nasync function propagationContextFromInstanceId(instanceId: string): Promise<PropagationContext> {\n const traceId = UUID_REGEX.test(instanceId)\n ? instanceId.replace(/-/g, '')\n : await deterministicTraceIdFromInstanceId(instanceId);\n\n // Derive sampleRand from last 4 characters of the random UUID\n //\n // We cannot store any state between workflow steps, so we derive the\n // sampleRand from the traceId itself. This ensures that the sampling is\n // consistent across all steps in the same workflow instance.\n const sampleRand = parseInt(traceId.slice(-4), 16) / 0xffff;\n\n return {\n traceId,\n sampleRand,\n };\n}\n\nclass WrappedWorkflowStep implements WorkflowStep {\n public constructor(\n private _instanceId: string,\n private _options: CloudflareOptions,\n private _step: WorkflowStep,\n private _waitUntil: ExecutionContext['waitUntil'],\n private _isolationScope: Scope,\n ) {}\n\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n callback: (ctx: WorkflowStepContext) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(\n name: string,\n config: C,\n callback: (\n ctx: WorkflowStepContext<C['retries'] extends { delay: infer D } ? D : WorkflowDelayDuration | number>,\n ) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n configOrCallback: WorkflowStepConfig | ((ctx: WorkflowStepContext) => Promise<T>),\n callbackOrRollback?: ((ctx: WorkflowStepContext) => Promise<T>) | WorkflowStepRollbackOptions<T>,\n maybeRollback?: WorkflowStepRollbackOptions<T>,\n ): Promise<T> {\n // Capture the current scope, so parent span (e.g., a startSpan surrounding step.do) is preserved\n const scopeForStep = getCurrentScope();\n\n const hasConfig = typeof configOrCallback !== 'function';\n const config = hasConfig ? configOrCallback : undefined;\n const userCallback = (hasConfig ? callbackOrRollback : configOrCallback) as (\n ctx: WorkflowStepContext,\n ) => Promise<T>;\n const rollbackOptions = (hasConfig ? maybeRollback : callbackOrRollback) as\n | WorkflowStepRollbackOptions<T>\n | undefined;\n\n const instrumentedCallback = async (...args: unknown[]): Promise<T> => {\n // Feature detection: Cloudflare Workflows (April 2026+) pass a step context\n // with `attempt` and `config.retries.limit`. When available, we only capture\n // errors on the final attempt to avoid duplicates during retries.\n const stepContext = args[0] as { attempt?: number; config?: { retries?: { limit?: number } } } | undefined;\n const attempt = stepContext?.attempt;\n const retryLimit = stepContext?.config?.retries?.limit;\n const hasStepContext = typeof attempt === 'number' && typeof retryLimit === 'number';\n\n // Only capture error on final attempt (attempt > retryLimit means no more retries left)\n // or when step context is unavailable (legacy behavior - capture all errors)\n const isFinalAttempt = !hasStepContext || attempt > retryLimit;\n\n // The engine invokes step callbacks outside the async context of `run`, so the\n // run's isolation scope (and with it the invocation state that ties eager sends\n // to this invocation's `waitUntil`) has to be restored explicitly.\n return withIsolationScope(this._isolationScope, () => {\n const invocationState = getInvocationState();\n\n if (invocationState) {\n invocationState.flushPointReached = false;\n }\n\n const stepResult = startSpan(\n {\n name,\n scope: scopeForStep,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n [CODE_FUNCTION_NAME]: name,\n 'workflow.step.name': name,\n 'cloudflare.workflow.timeout': config?.timeout,\n 'cloudflare.workflow.retries.backoff': config?.retries?.backoff,\n // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.\n 'cloudflare.workflow.retries.delay':\n typeof config?.retries?.delay === 'function' ? undefined : config?.retries?.delay,\n 'cloudflare.workflow.retries.limit': config?.retries?.limit,\n 'cloudflare.workflow.attempt': attempt,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.workflow',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async span => {\n try {\n const result = await (userCallback as (...args: unknown[]) => Promise<T>)(...args);\n span.setStatus({ code: 1 });\n return result;\n } catch (error) {\n if (isFinalAttempt) {\n captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });\n }\n throw error;\n }\n },\n );\n // Deliver after the step span has ended, so the span rides this flush instead of\n // starting an eager drain (same ordering as `wrapMethodWithSentry`'s teardown). The flush runs on the\n // step's scope: the engine calls the step callback outside of `run()`, so the current scope here has\n // neither the client nor the run's trace, and envelopes without a DSC are dropped by Relay.\n return stepResult.then(\n result => {\n this._waitUntil(withScope(scopeForStep, () => flush(2000)));\n return result;\n },\n error => {\n this._waitUntil(withScope(scopeForStep, () => flush(2000)));\n throw error;\n },\n );\n });\n };\n\n if (config) {\n return rollbackOptions\n ? this._step.do(name, config, instrumentedCallback, rollbackOptions)\n : this._step.do(name, config, instrumentedCallback);\n }\n\n return rollbackOptions\n ? this._step.do(name, instrumentedCallback, rollbackOptions)\n : this._step.do(name, instrumentedCallback);\n }\n\n public async sleep(name: string, duration: WorkflowSleepDuration): Promise<void> {\n return this._step.sleep(name, duration);\n }\n\n public async sleepUntil(name: string, timestamp: Date | number): Promise<void> {\n return this._step.sleepUntil(name, timestamp);\n }\n\n public async waitForEvent<T extends Rpc.Serializable<T>>(\n name: string,\n options: { type: string; timeout?: WorkflowTimeoutDuration | number },\n ): Promise<WorkflowStepEvent<T>> {\n return this._step.waitForEvent<T>(name, options);\n }\n}\n\n/**\n * Instruments a Cloudflare Workflow class with Sentry.\n *\n * @example\n * ```typescript\n * const InstrumentedWorkflow = instrumentWorkflowWithSentry(\n * (env) => ({ dsn: env.SENTRY_DSN }),\n * MyWorkflowClass\n * );\n *\n * export default InstrumentedWorkflow;\n * ```\n *\n * @param optionsCallback - Function that returns Sentry options to initialize Sentry\n * @param WorkflowClass - The workflow class to instrument\n * @returns Instrumented workflow class with the same interface\n */\nexport function instrumentWorkflowWithSentry<\n E = DefaultEnv, // Environment type\n P = unknown, // Payload type\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends WorkflowEntrypoint<any, any> = WorkflowEntrypoint<E, P>, // WorkflowEntrypoint type\n // The constraint must not route through `T`: workers-types defaults `WorkflowEntrypoint`'s\n // `Env` to `unknown` (unlike `WorkerEntrypoint`/`DurableObject`, which default to\n // `Cloudflare.Env`), so a bare subclass would be rejected in a `wrangler types` project.\n // The callback env is resolved from the inferred constructor via `ResolveEnv` instead.\n // oxlint-disable-next-line typescript/no-explicit-any\n C extends new (ctx: ExecutionContext, env: any) => WorkflowEntrypoint<any, any> = new (\n ctx: ExecutionContext,\n // oxlint-disable-next-line typescript/no-explicit-any\n env: any,\n ) => T, // Constructor type of the WorkflowEntrypoint class\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<C, E>) => StrictCloudflareOptions<O>, WorkFlowClass: C): C {\n const InstrumentedClass = new Proxy(WorkFlowClass, {\n // oxlint-disable-next-line typescript/no-explicit-any\n construct(target: C, args: [ctx: ExecutionContext, env: any], newTarget) {\n const [ctx, env] = args;\n const context = instrumentContext(ctx);\n const options = optionsCallback(env);\n args[0] = context;\n args[1] = instrumentEnv(env as Record<string, unknown>, options) as E;\n const instance = Reflect.construct(target, args, newTarget) as T;\n return new Proxy(instance, {\n get(obj, prop, receiver) {\n if (prop === 'run') {\n return async function (event: WorkflowEvent<P>, step: WorkflowStep): Promise<unknown> {\n setAsyncLocalStorageAsyncContextStrategy();\n\n return withInvocationIsolationScope(async isolationScope => {\n const waitUntil = getOriginalWaitUntil(context).bind(context);\n const client = init({ ...options, ctx: context, enableDedupe: false });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return withScope(async scope => {\n const propagationContext = await propagationContextFromInstanceId(event.instanceId);\n scope.setPropagationContext(propagationContext);\n\n try {\n return await obj.run.call(\n obj,\n event,\n new WrappedWorkflowStep(event.instanceId, options, step, waitUntil, isolationScope),\n );\n } finally {\n waitUntil(flushAndDispose(client));\n }\n });\n }, context);\n };\n }\n return Reflect.get(obj, prop, receiver);\n },\n });\n },\n });\n // Recognizable for `_INTERNAL_wrapUnlessInstrumented`, so auto-instrumentation never nests wrappers.\n markAsInstrumented(InstrumentedClass);\n return InstrumentedClass;\n}\n"],"names":["getCurrentScope","withIsolationScope","getInvocationState","startSpan","SENTRY_OP","FUNCTION","CODE_FUNCTION_NAME","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SENTRY_SEGMENT_NAME_SOURCE","captureException","withScope","flush","instrumentContext","instrumentEnv","setAsyncLocalStorageAsyncContextStrategy","withInvocationIsolationScope","getOriginalWaitUntil","init","addCloudResourceContext","flushAndDispose","markAsInstrumented"],"mappings":";;;;;;;;;;;;;;;AAoCA,MAAM,UAAA,GAAa,qEAAA;AAKnB,eAAsB,mCAAmC,UAAA,EAAqC;AAC5F,EAAA,MAAM,GAAA,GAAM,MAAM,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,OAAA,EAAS,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,UAAU,CAAC,CAAA;AACpF,EAAA,OACE,KAAA,CAAM,KAAK,IAAI,UAAA,CAAW,GAAG,CAAC,CAAA,CAE3B,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,CACX,IAAI,CAAA,CAAA,KAAK,CAAA,C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,CAAE,KAAK,OAAO,CAAA;AAC5D,gBAAA,MAAM,MAAA,GAASC,SAAK,EAAE,GAAG,SAAS,GAAA,EAAK,OAAA,EAAS,YAAA,EAAc,KAAA,EAAO,CAAA;AACrE,gBAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,gBAAAC,kCAAA,CAAwB,cAAc,CAAA;AAEtC,gBAAA,OAAOR,cAAA,CAAU,OAAM,KAAA,KAAS;AAC9B,kBAAA,MAAM,kBAAA,GAAqB,MAAM,gCAAA,CAAiC,KAAA,CAAM,UAAU,CAAA;AAClF,kBAAA,KAAA,CAAM,sBAAsB,kBAAkB,CAAA;AAE9C,kBAAA,IAAI;AACF,oBAAA,OAAO,MAAM,IAAI,GAAA,CAAI,IAAA;AAAA,sBACnB,GAAA;AAAA,sBACA,KAAA;AAAA,sBACA,IAAI,mBAAA,CAAoB,KAAA,CAAM,YAAY,OAAA,EAAS,IAAA,EAAM,WAAW,cAAc;AAAA,qBACpF;AAAA,kBACF,CAAA,SAAE;AACA,oBAAA,SAAA,CAAUS,qBAAA,CAAgB,MAAM,CAAC,CAAA;AAAA,kBACnC;AAAA,gBACF,CAAC,CAAA;AAAA,cACH,GAAG,OAAO,CAAA;AAAA,YACZ,CAAA;AAAA,UACF;AACA,UAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,IAAA,EAAM,QAAQ,CAAA;AAAA,QACxC;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AAED,EAAAC,6BAAA,CAAmB,iBAAiB,CAAA;AACpC,EAAA,OAAO,iBAAA;AACT;;;;;"}
1
+ {"version":3,"file":"workflows.js","sources":["../../../src/workflows.ts"],"sourcesContent":["import {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport type { PropagationContext, Scope } from '@sentry/core';\nimport { captureException, flush, getCurrentScope, startSpan, withIsolationScope, withScope } from '@sentry/core';\nimport type {\n WorkflowDelayDuration,\n WorkflowEntrypoint,\n WorkflowEvent,\n WorkflowSleepDuration,\n WorkflowStep,\n WorkflowStepConfig,\n WorkflowStepContext,\n WorkflowStepEvent,\n WorkflowStepRollbackOptions,\n WorkflowTimeoutDuration,\n} from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategyForWorker } from './utils/asyncContextStrategy';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { markAsInstrumented } from './instrument';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { addCloudResourceContext } from './scope-utils';\nimport { init } from './sdk';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { DefaultEnv, ResolveEnv, StrictCloudflareOptions } from './types';\nimport { getInvocationState } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\n\nconst UUID_REGEX = /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i;\n\n/**\n * Hashes a string to a UUID using SHA-1.\n */\nexport async function deterministicTraceIdFromInstanceId(instanceId: string): Promise<string> {\n const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(instanceId));\n return (\n Array.from(new Uint8Array(buf))\n // We only need the first 16 bytes for the 32 characters\n .slice(0, 16)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n );\n}\n\nasync function propagationContextFromInstanceId(instanceId: string): Promise<PropagationContext> {\n const traceId = UUID_REGEX.test(instanceId)\n ? instanceId.replace(/-/g, '')\n : await deterministicTraceIdFromInstanceId(instanceId);\n\n // Derive sampleRand from last 4 characters of the random UUID\n //\n // We cannot store any state between workflow steps, so we derive the\n // sampleRand from the traceId itself. This ensures that the sampling is\n // consistent across all steps in the same workflow instance.\n const sampleRand = parseInt(traceId.slice(-4), 16) / 0xffff;\n\n return {\n traceId,\n sampleRand,\n };\n}\n\nclass WrappedWorkflowStep implements WorkflowStep {\n public constructor(\n private _instanceId: string,\n private _options: CloudflareOptions,\n private _step: WorkflowStep,\n private _waitUntil: ExecutionContext['waitUntil'],\n private _isolationScope: Scope,\n ) {}\n\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n callback: (ctx: WorkflowStepContext) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(\n name: string,\n config: C,\n callback: (\n ctx: WorkflowStepContext<C['retries'] extends { delay: infer D } ? D : WorkflowDelayDuration | number>,\n ) => Promise<T>,\n rollbackOptions?: WorkflowStepRollbackOptions<T>,\n ): Promise<T>;\n public async do<T extends Rpc.Serializable<T>>(\n name: string,\n configOrCallback: WorkflowStepConfig | ((ctx: WorkflowStepContext) => Promise<T>),\n callbackOrRollback?: ((ctx: WorkflowStepContext) => Promise<T>) | WorkflowStepRollbackOptions<T>,\n maybeRollback?: WorkflowStepRollbackOptions<T>,\n ): Promise<T> {\n // Capture the current scope, so parent span (e.g., a startSpan surrounding step.do) is preserved\n const scopeForStep = getCurrentScope();\n\n const hasConfig = typeof configOrCallback !== 'function';\n const config = hasConfig ? configOrCallback : undefined;\n const userCallback = (hasConfig ? callbackOrRollback : configOrCallback) as (\n ctx: WorkflowStepContext,\n ) => Promise<T>;\n const rollbackOptions = (hasConfig ? maybeRollback : callbackOrRollback) as\n | WorkflowStepRollbackOptions<T>\n | undefined;\n\n const instrumentedCallback = async (...args: unknown[]): Promise<T> => {\n // Feature detection: Cloudflare Workflows (April 2026+) pass a step context\n // with `attempt` and `config.retries.limit`. When available, we only capture\n // errors on the final attempt to avoid duplicates during retries.\n const stepContext = args[0] as { attempt?: number; config?: { retries?: { limit?: number } } } | undefined;\n const attempt = stepContext?.attempt;\n const retryLimit = stepContext?.config?.retries?.limit;\n const hasStepContext = typeof attempt === 'number' && typeof retryLimit === 'number';\n\n // Only capture error on final attempt (attempt > retryLimit means no more retries left)\n // or when step context is unavailable (legacy behavior - capture all errors)\n const isFinalAttempt = !hasStepContext || attempt > retryLimit;\n\n // The engine invokes step callbacks outside the async context of `run`, so the\n // run's isolation scope (and with it the invocation state that ties eager sends\n // to this invocation's `waitUntil`) has to be restored explicitly.\n return withIsolationScope(this._isolationScope, () => {\n const invocationState = getInvocationState();\n\n if (invocationState) {\n invocationState.flushPointReached = false;\n }\n\n const stepResult = startSpan(\n {\n name,\n scope: scopeForStep,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n [CODE_FUNCTION_NAME]: name,\n 'workflow.step.name': name,\n 'cloudflare.workflow.timeout': config?.timeout,\n 'cloudflare.workflow.retries.backoff': config?.retries?.backoff,\n // In workers-types v5, `delay` may be a `WorkflowDelayFunction`, which isn't a valid span attribute value.\n 'cloudflare.workflow.retries.delay':\n typeof config?.retries?.delay === 'function' ? undefined : config?.retries?.delay,\n 'cloudflare.workflow.retries.limit': config?.retries?.limit,\n 'cloudflare.workflow.attempt': attempt,\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.workflow',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async span => {\n try {\n const result = await (userCallback as (...args: unknown[]) => Promise<T>)(...args);\n span.setStatus({ code: 1 });\n return result;\n } catch (error) {\n if (isFinalAttempt) {\n captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });\n }\n throw error;\n }\n },\n );\n // Deliver after the step span has ended, so the span rides this flush instead of\n // starting an eager drain (same ordering as `wrapMethodWithSentry`'s teardown). The flush runs on the\n // step's scope: the engine calls the step callback outside of `run()`, so the current scope here has\n // neither the client nor the run's trace, and envelopes without a DSC are dropped by Relay.\n return stepResult.then(\n result => {\n this._waitUntil(withScope(scopeForStep, () => flush(2000)));\n return result;\n },\n error => {\n this._waitUntil(withScope(scopeForStep, () => flush(2000)));\n throw error;\n },\n );\n });\n };\n\n if (config) {\n return rollbackOptions\n ? this._step.do(name, config, instrumentedCallback, rollbackOptions)\n : this._step.do(name, config, instrumentedCallback);\n }\n\n return rollbackOptions\n ? this._step.do(name, instrumentedCallback, rollbackOptions)\n : this._step.do(name, instrumentedCallback);\n }\n\n public async sleep(name: string, duration: WorkflowSleepDuration): Promise<void> {\n return this._step.sleep(name, duration);\n }\n\n public async sleepUntil(name: string, timestamp: Date | number): Promise<void> {\n return this._step.sleepUntil(name, timestamp);\n }\n\n public async waitForEvent<T extends Rpc.Serializable<T>>(\n name: string,\n options: { type: string; timeout?: WorkflowTimeoutDuration | number },\n ): Promise<WorkflowStepEvent<T>> {\n return this._step.waitForEvent<T>(name, options);\n }\n}\n\n/**\n * Instruments a Cloudflare Workflow class with Sentry.\n *\n * @example\n * ```typescript\n * const InstrumentedWorkflow = instrumentWorkflowWithSentry(\n * (env) => ({ dsn: env.SENTRY_DSN }),\n * MyWorkflowClass\n * );\n *\n * export default InstrumentedWorkflow;\n * ```\n *\n * @param optionsCallback - Function that returns Sentry options to initialize Sentry\n * @param WorkflowClass - The workflow class to instrument\n * @returns Instrumented workflow class with the same interface\n */\nexport function instrumentWorkflowWithSentry<\n E = DefaultEnv, // Environment type\n P = unknown, // Payload type\n // oxlint-disable-next-line typescript/no-explicit-any\n T extends WorkflowEntrypoint<any, any> = WorkflowEntrypoint<E, P>, // WorkflowEntrypoint type\n // The constraint must not route through `T`: workers-types defaults `WorkflowEntrypoint`'s\n // `Env` to `unknown` (unlike `WorkerEntrypoint`/`DurableObject`, which default to\n // `Cloudflare.Env`), so a bare subclass would be rejected in a `wrangler types` project.\n // The callback env is resolved from the inferred constructor via `ResolveEnv` instead.\n // oxlint-disable-next-line typescript/no-explicit-any\n C extends new (ctx: ExecutionContext, env: any) => WorkflowEntrypoint<any, any> = new (\n ctx: ExecutionContext,\n // oxlint-disable-next-line typescript/no-explicit-any\n env: any,\n ) => T, // Constructor type of the WorkflowEntrypoint class\n O = unknown,\n>(optionsCallback: (env: ResolveEnv<C, E>) => StrictCloudflareOptions<O>, WorkFlowClass: C): C {\n const InstrumentedClass = new Proxy(WorkFlowClass, {\n // oxlint-disable-next-line typescript/no-explicit-any\n construct(target: C, args: [ctx: ExecutionContext, env: any], newTarget) {\n const [ctx, env] = args;\n const context = instrumentContext(ctx);\n const options = optionsCallback(env);\n args[0] = context;\n args[1] = instrumentEnv(env as Record<string, unknown>, options) as E;\n const instance = Reflect.construct(target, args, newTarget) as T;\n return new Proxy(instance, {\n get(obj, prop, receiver) {\n if (prop === 'run') {\n return async function (event: WorkflowEvent<P>, step: WorkflowStep): Promise<unknown> {\n setAsyncLocalStorageAsyncContextStrategyForWorker();\n\n return withInvocationIsolationScope(async isolationScope => {\n const waitUntil = getOriginalWaitUntil(context).bind(context);\n const client = init({ ...options, ctx: context, enableDedupe: false });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return withScope(async scope => {\n const propagationContext = await propagationContextFromInstanceId(event.instanceId);\n scope.setPropagationContext(propagationContext);\n\n try {\n return await obj.run.call(\n obj,\n event,\n new WrappedWorkflowStep(event.instanceId, options, step, waitUntil, isolationScope),\n );\n } finally {\n waitUntil(flushAndDispose(client));\n }\n });\n }, context);\n };\n }\n return Reflect.get(obj, prop, receiver);\n },\n });\n },\n });\n // Recognizable for `_INTERNAL_wrapUnlessInstrumented`, so auto-instrumentation never nests wrappers.\n markAsInstrumented(InstrumentedClass);\n return InstrumentedClass;\n}\n"],"names":["getCurrentScope","withIsolationScope","getInvocationState","startSpan","SENTRY_OP","FUNCTION","CODE_FUNCTION_NAME","SENTRY_ORIGIN","SENTRY_SEGMENT_NAME_SOURCE","captureException","withScope","flush","instrumentContext","instrumentEnv","setAsyncLocalStorageAsyncContextStrategyForWorker","withInvocationIsolationScope","getOriginalWaitUntil","init","addCloudResourceContext","flushAndDispose","markAsInstrumented"],"mappings":";;;;;;;;;;;;;;;AAiCA,MAAM,UAAA,GAAa,qEAAA;AAKnB,eAAsB,mCAAmC,UAAA,EAAqC;AAC5F,EAAA,MAAM,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C,EAAA,OAAO,iBAAA;AACT;;;;;"}
@@ -3,13 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const attributes = require('@sentry/conventions/attributes');
4
4
  const op = require('@sentry/conventions/op');
5
5
  const core = require('@sentry/core');
6
+ const server = require('@sentry/core/server');
6
7
  const httpServer = require('./integrations/httpServer.js');
7
8
  const orchestrionDeferredChannels = require('./orchestrion-deferred-channels.js');
8
9
  const flush = require('./flush.js');
9
10
  const scopeUtils = require('./scope-utils.js');
10
11
  const invocationContext = require('./utils/invocationContext.js');
11
12
  const invocationScope = require('./utils/invocationScope.js');
12
- const streaming = require('./utils/streaming.js');
13
13
 
14
14
  function getRequestErrorMechanismType(context) {
15
15
  return context && "storage" in context ? "auto.faas.cloudflare.durable_object" : "auto.http.cloudflare";
@@ -90,7 +90,7 @@ function wrapRequestHandlerWithInit(wrapperOptions, handler, initSdk) {
90
90
  waitUntil?.(flush.flushAndDispose(client));
91
91
  throw e;
92
92
  }
93
- const classification = streaming.classifyResponseStreaming(res);
93
+ const classification = server.classifyResponseStreaming(res);
94
94
  if (classification.isStreaming && res.body) {
95
95
  try {
96
96
  let ended = false;
@@ -1 +1 @@
1
- {"version":3,"file":"wrapRequestHandlerWithInit.js","sources":["../../../src/wrapRequestHandlerWithInit.ts"],"sourcesContent":["import type { CfProperties, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport {\n NETWORK_PROTOCOL_NAME,\n NETWORK_PROTOCOL_VERSION,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport {\n captureException,\n continueTrace,\n getHttpSpanDetailsFromUrlObject,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n setHttpStatus,\n startSpanManual,\n winterCGHeadersToDict,\n} from '@sentry/core';\nimport { captureIncomingRequestBody } from './integrations/httpServer';\nimport { flushDeferredChannelEvents } from './orchestrion-deferred-channels';\nimport type { CloudflareClient, CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { addCloudResourceContext, addCultureContext, addRequest } from './scope-utils';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\nimport { classifyResponseStreaming } from './utils/streaming';\n\nfunction getRequestErrorMechanismType(context: ExecutionContextCompat | undefined): string {\n // Durable Object fetch handlers use DO state as context (see instrumentDurableObjectWithSentry)\n return context && 'storage' in context ? 'auto.faas.cloudflare.durable_object' : 'auto.http.cloudflare';\n}\n\nexport interface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown> | CfProperties<unknown>>;\n context: ExecutionContextCompat | undefined;\n /**\n * If true, errors will be captured, rethrown and sent to Sentry.\n * Otherwise, errors are rethrown but not captured.\n *\n * You most likely don't want to set this to `false`, if you use `wrapRequestHandler` directly.\n * This is primarily meant as an escape hatch for higher-level SDKs relying on additional error\n * capturing mechanisms where this wrapper captures errors too early or too generally.\n *\n * @default true\n */\n captureErrors?: boolean;\n}\n\ntype InitSdk = (options: CloudflareOptions) => CloudflareClient | undefined;\n\n/**\n * Same as {@link wrapRequestHandler}, but with the SDK initialization injected.\n *\n * Wrappers that are only reachable from the main entry point — where `nodejs_compat` is a\n * requirement anyway — pass `init` from `sdk.ts` to get the full default integrations.\n *\n * @internal\n */\nexport function wrapRequestHandlerWithInit(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n initSdk: InitSdk,\n): Promise<Response> {\n return withInvocationIsolationScope(async isolationScope => {\n const { options, request, captureErrors = true } = wrapperOptions;\n const context = wrapperOptions.context;\n\n // The un-instrumented waitUntil, so flushAndDispose cannot deadlock on the flush\n // lock's own wrapper. Resolved once per invocation and cached on its state; reading\n // `ctx.waitUntil` on a native context is a runtime getter call.\n const invocationState = getInvocationState();\n const waitUntil = invocationState\n ? getInvocationWaitUntil(invocationState)\n : context\n ? getOriginalWaitUntil(context).bind(context)\n : undefined;\n const errorMechanismType = getRequestErrorMechanismType(context);\n\n const client = initSdk({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n // Emit any orchestrion channel events deferred at module scope (e.g. a top-level\n // `const app = new Hono()` wrapped by build-time instrumentation): we're now in a\n // request, where workerd allows publish, and init() above has registered subscribers.\n flushDeferredChannelEvents();\n\n const urlObject = parseStringToURLObject(request.url);\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n 'auto.http.cloudflare',\n request,\n undefined,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !client || !hasSpanStreamingEnabled(client)\n ? rawName\n : request.method?.toUpperCase() || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes['http.request.body.size'] = parseInt(contentLength, 10);\n }\n\n const userAgentHeader = request.headers.get('user-agent');\n if (userAgentHeader) {\n attributes['user_agent.original'] = userAgentHeader;\n }\n\n if (client) {\n Object.assign(\n attributes,\n httpHeadersToSpanAttributes(winterCGHeadersToDict(request.headers), client.getDataCollectionOptions()),\n );\n }\n\n attributes[SENTRY_OP] = HTTP_SERVER;\n\n addCloudResourceContext(isolationScope);\n addRequest(isolationScope, request);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n\n if (typeof request.cf.httpProtocol === 'string') {\n const [protocolName, protocolVersion] = request.cf.httpProtocol.toLowerCase().split('/');\n attributes[NETWORK_PROTOCOL_NAME] = protocolName;\n attributes[NETWORK_PROTOCOL_VERSION] = protocolVersion;\n }\n }\n\n // Do not capture spans for OPTIONS and HEAD requests\n if (request.method === 'OPTIONS' || request.method === 'HEAD') {\n try {\n return await handler();\n } catch (e) {\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n throw e;\n } finally {\n waitUntil?.(flushAndDispose(client));\n }\n }\n\n if (client) {\n await captureIncomingRequestBody(client, request);\n }\n\n return continueTrace(\n { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },\n () => {\n // Note: This span will not have a duration unless I/O happens in the handler. This is\n // because of how the cloudflare workers runtime works.\n // See: https://developers.cloudflare.com/workers/runtime-apis/performance/\n\n // Use startSpanManual to control when span ends (needed for streaming responses)\n return startSpanManual({ name, attributes }, async span => {\n let res: Response;\n\n try {\n res = await handler();\n setHttpStatus(span, res.status);\n\n // After the handler runs, the span name might have been updated by nested instrumentation\n // (e.g., Remix parameterizing routes). The span should already have the correct name\n // from that instrumentation, so we don't need to do anything here.\n } catch (e) {\n span.end();\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n waitUntil?.(flushAndDispose(client));\n throw e;\n }\n\n // Classify response to detect actual streaming\n const classification = classifyResponseStreaming(res);\n\n if (classification.isStreaming && res.body) {\n try {\n let ended = false;\n\n const endSpanOnce = (): void => {\n if (ended) return;\n\n ended = true;\n span.end();\n waitUntil?.(flushAndDispose(client));\n };\n\n const transform = new TransformStream({\n flush() {\n // Source stream completed normally.\n endSpanOnce();\n },\n cancel() {\n // Client disconnected (or downstream cancelled). The `cancel`\n // is being called while the response is still considered\n // active, so this is a safe place to end the span.\n endSpanOnce();\n },\n });\n\n return new Response(res.body.pipeThrough(transform), {\n status: res.status,\n statusText: res.statusText,\n headers: res.headers,\n });\n } catch {\n span.end();\n waitUntil?.(flushAndDispose(client));\n return res;\n }\n }\n\n // Non-streaming response - end span immediately and return original\n span.end();\n\n // Don't dispose for protocol upgrades (101 Switching Protocols) - the connection stays alive.\n // This includes WebSocket upgrades where webSocketMessage/webSocketClose handlers\n // will still be called and may need the client to capture errors.\n if (res.status === 101) {\n waitUntil?.(client?.flush(2000));\n } else {\n waitUntil?.(flushAndDispose(client));\n }\n return res;\n });\n },\n );\n }, wrapperOptions.context);\n}\n"],"names":["withInvocationIsolationScope","getInvocationState","getInvocationWaitUntil","getOriginalWaitUntil","flushDeferredChannelEvents","parseStringToURLObject","attributes","getHttpSpanDetailsFromUrlObject","SENTRY_SEGMENT_NAME_SOURCE","hasSpanStreamingEnabled","HTTP_SPAN_NAME_FALLBACK","httpHeadersToSpanAttributes","winterCGHeadersToDict","SENTRY_OP","HTTP_SERVER","addCloudResourceContext","addRequest","addCultureContext","NETWORK_PROTOCOL_NAME","NETWORK_PROTOCOL_VERSION","captureException","flushAndDispose","captureIncomingRequestBody","continueTrace","startSpanManual","setHttpStatus","classifyResponseStreaming"],"mappings":";;;;;;;;;;;;;AA8BA,SAAS,6BAA6B,OAAA,EAAqD;AAEzF,EAAA,OAAO,OAAA,IAAW,SAAA,IAAa,OAAA,GAAU,qCAAA,GAAwC,sBAAA;AACnF;AA6BO,SAAS,0BAAA,CACd,cAAA,EACA,OAAA,EACA,OAAA,EACmB;AACnB,EAAA,OAAOA,4CAAA,CAA6B,OAAM,cAAA,KAAkB;AAC1D,IAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,aAAA,GAAgB,MAAK,GAAI,cAAA;AACnD,IAAA,MAAM,UAAU,cAAA,CAAe,OAAA;AAK/B,IAAA,MAAM,kBAAkBC,oCAAA,EAAmB;AAC3C,IAAA,MAAM,SAAA,GAAY,eAAA,GACdC,wCAAA,CAAuB,eAAe,CAAA,GACtC,OAAA,GACEC,0BAAA,CAAqB,OAAO,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA,GAC1C,MAAA;AACN,IAAA,MAAM,kBAAA,GAAqB,6BAA6B,OAAO,CAAA;AAE/D,IAAA,MAAM,SAAS,OAAA,CAAQ,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AACnD,IAAA,cAAA,CAAe,UAAU,MAAM,CA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AAI;AAAA,eACd,CAAA;AAAA,YACH,CAAA,CAAA,MAAQ;AACN,cAAA,IAAA,CAAK,GAAA,EAAI;AACT,cAAA,SAAA,GAAYA,qBAAA,CAAgB,MAAM,CAAC,CAAA;AACnC,cAAA,OAAO,GAAA;AAAA,YACT;AAAA,UACF;AAGA,UAAA,IAAA,CAAK,GAAA,EAAI;AAKT,UAAA,IAAI,GAAA,CAAI,WAAW,GAAA,EAAK;AACtB,YAAA,SAAA,GAAY,MAAA,EAAQ,KAAA,CAAM,GAAI,CAAC,CAAA;AAAA,UACjC,CAAA,MAAO;AACL,YAAA,SAAA,GAAYA,qBAAA,CAAgB,MAAM,CAAC,CAAA;AAAA,UACrC;AACA,UAAA,OAAO,GAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH;AAAA,KACF;AAAA,EACF,CAAA,EAAG,eAAe,OAAO,CAAA;AAC3B;;;;"}
1
+ {"version":3,"file":"wrapRequestHandlerWithInit.js","sources":["../../../src/wrapRequestHandlerWithInit.ts"],"sourcesContent":["import type { CfProperties, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport {\n NETWORK_PROTOCOL_NAME,\n NETWORK_PROTOCOL_VERSION,\n SENTRY_OP,\n SENTRY_SEGMENT_NAME_SOURCE,\n} from '@sentry/conventions/attributes';\nimport { HTTP_SERVER } from '@sentry/conventions/op';\nimport {\n captureException,\n continueTrace,\n getHttpSpanDetailsFromUrlObject,\n hasSpanStreamingEnabled,\n httpHeadersToSpanAttributes,\n HTTP_SPAN_NAME_FALLBACK,\n parseStringToURLObject,\n setHttpStatus,\n startSpanManual,\n winterCGHeadersToDict,\n} from '@sentry/core';\nimport { classifyResponseStreaming } from '@sentry/core/server';\nimport { captureIncomingRequestBody } from './integrations/httpServer';\nimport { flushDeferredChannelEvents } from './orchestrion-deferred-channels';\nimport type { CloudflareClient, CloudflareOptions } from './client';\nimport type { ExecutionContextCompat } from './executionContext';\nimport { flushAndDispose, getOriginalWaitUntil } from './flush';\nimport { addCloudResourceContext, addCultureContext, addRequest } from './scope-utils';\nimport { getInvocationState, getInvocationWaitUntil } from './utils/invocationContext';\nimport { withInvocationIsolationScope } from './utils/invocationScope';\n\nfunction getRequestErrorMechanismType(context: ExecutionContextCompat | undefined): string {\n // Durable Object fetch handlers use DO state as context (see instrumentDurableObjectWithSentry)\n return context && 'storage' in context ? 'auto.faas.cloudflare.durable_object' : 'auto.http.cloudflare';\n}\n\nexport interface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown> | CfProperties<unknown>>;\n context: ExecutionContextCompat | undefined;\n /**\n * If true, errors will be captured, rethrown and sent to Sentry.\n * Otherwise, errors are rethrown but not captured.\n *\n * You most likely don't want to set this to `false`, if you use `wrapRequestHandler` directly.\n * This is primarily meant as an escape hatch for higher-level SDKs relying on additional error\n * capturing mechanisms where this wrapper captures errors too early or too generally.\n *\n * @default true\n */\n captureErrors?: boolean;\n}\n\ntype InitSdk = (options: CloudflareOptions) => CloudflareClient | undefined;\n\n/**\n * Same as {@link wrapRequestHandler}, but with the SDK initialization injected.\n *\n * Wrappers that are only reachable from the main entry point — where `nodejs_compat` is a\n * requirement anyway — pass `init` from `sdk.ts` to get the full default integrations.\n *\n * @internal\n */\nexport function wrapRequestHandlerWithInit(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n initSdk: InitSdk,\n): Promise<Response> {\n return withInvocationIsolationScope(async isolationScope => {\n const { options, request, captureErrors = true } = wrapperOptions;\n const context = wrapperOptions.context;\n\n // The un-instrumented waitUntil, so flushAndDispose cannot deadlock on the flush\n // lock's own wrapper. Resolved once per invocation and cached on its state; reading\n // `ctx.waitUntil` on a native context is a runtime getter call.\n const invocationState = getInvocationState();\n const waitUntil = invocationState\n ? getInvocationWaitUntil(invocationState)\n : context\n ? getOriginalWaitUntil(context).bind(context)\n : undefined;\n const errorMechanismType = getRequestErrorMechanismType(context);\n\n const client = initSdk({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n // Emit any orchestrion channel events deferred at module scope (e.g. a top-level\n // `const app = new Hono()` wrapped by build-time instrumentation): we're now in a\n // request, where workerd allows publish, and init() above has registered subscribers.\n flushDeferredChannelEvents();\n\n const urlObject = parseStringToURLObject(request.url);\n const [rawName, attributes] = getHttpSpanDetailsFromUrlObject(\n urlObject,\n 'server',\n 'auto.http.cloudflare',\n request,\n undefined,\n client,\n );\n // With span streaming, span names have to be low cardinality, so we can't fall back to the URL.\n // A `route` source means the name already is (e.g. the `/` path), so it is kept as-is.\n const name =\n attributes[SENTRY_SEGMENT_NAME_SOURCE] === 'route' || !client || !hasSpanStreamingEnabled(client)\n ? rawName\n : request.method?.toUpperCase() || HTTP_SPAN_NAME_FALLBACK;\n\n const contentLength = request.headers.get('content-length');\n if (contentLength) {\n attributes['http.request.body.size'] = parseInt(contentLength, 10);\n }\n\n const userAgentHeader = request.headers.get('user-agent');\n if (userAgentHeader) {\n attributes['user_agent.original'] = userAgentHeader;\n }\n\n if (client) {\n Object.assign(\n attributes,\n httpHeadersToSpanAttributes(winterCGHeadersToDict(request.headers), client.getDataCollectionOptions()),\n );\n }\n\n attributes[SENTRY_OP] = HTTP_SERVER;\n\n addCloudResourceContext(isolationScope);\n addRequest(isolationScope, request);\n if (request.cf) {\n addCultureContext(isolationScope, request.cf);\n\n if (typeof request.cf.httpProtocol === 'string') {\n const [protocolName, protocolVersion] = request.cf.httpProtocol.toLowerCase().split('/');\n attributes[NETWORK_PROTOCOL_NAME] = protocolName;\n attributes[NETWORK_PROTOCOL_VERSION] = protocolVersion;\n }\n }\n\n // Do not capture spans for OPTIONS and HEAD requests\n if (request.method === 'OPTIONS' || request.method === 'HEAD') {\n try {\n return await handler();\n } catch (e) {\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n throw e;\n } finally {\n waitUntil?.(flushAndDispose(client));\n }\n }\n\n if (client) {\n await captureIncomingRequestBody(client, request);\n }\n\n return continueTrace(\n { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },\n () => {\n // Note: This span will not have a duration unless I/O happens in the handler. This is\n // because of how the cloudflare workers runtime works.\n // See: https://developers.cloudflare.com/workers/runtime-apis/performance/\n\n // Use startSpanManual to control when span ends (needed for streaming responses)\n return startSpanManual({ name, attributes }, async span => {\n let res: Response;\n\n try {\n res = await handler();\n setHttpStatus(span, res.status);\n\n // After the handler runs, the span name might have been updated by nested instrumentation\n // (e.g., Remix parameterizing routes). The span should already have the correct name\n // from that instrumentation, so we don't need to do anything here.\n } catch (e) {\n span.end();\n if (captureErrors) {\n captureException(e, { mechanism: { handled: false, type: errorMechanismType } });\n }\n waitUntil?.(flushAndDispose(client));\n throw e;\n }\n\n // Classify response to detect actual streaming\n const classification = classifyResponseStreaming(res);\n\n if (classification.isStreaming && res.body) {\n try {\n let ended = false;\n\n const endSpanOnce = (): void => {\n if (ended) return;\n\n ended = true;\n span.end();\n waitUntil?.(flushAndDispose(client));\n };\n\n const transform = new TransformStream({\n flush() {\n // Source stream completed normally.\n endSpanOnce();\n },\n cancel() {\n // Client disconnected (or downstream cancelled). The `cancel`\n // is being called while the response is still considered\n // active, so this is a safe place to end the span.\n endSpanOnce();\n },\n });\n\n return new Response(res.body.pipeThrough(transform), {\n status: res.status,\n statusText: res.statusText,\n headers: res.headers,\n });\n } catch {\n span.end();\n waitUntil?.(flushAndDispose(client));\n return res;\n }\n }\n\n // Non-streaming response - end span immediately and return original\n span.end();\n\n // Don't dispose for protocol upgrades (101 Switching Protocols) - the connection stays alive.\n // This includes WebSocket upgrades where webSocketMessage/webSocketClose handlers\n // will still be called and may need the client to capture errors.\n if (res.status === 101) {\n waitUntil?.(client?.flush(2000));\n } else {\n waitUntil?.(flushAndDispose(client));\n }\n return res;\n });\n },\n );\n }, wrapperOptions.context);\n}\n"],"names":["withInvocationIsolationScope","getInvocationState","getInvocationWaitUntil","getOriginalWaitUntil","flushDeferredChannelEvents","parseStringToURLObject","attributes","getHttpSpanDetailsFromUrlObject","SENTRY_SEGMENT_NAME_SOURCE","hasSpanStreamingEnabled","HTTP_SPAN_NAME_FALLBACK","httpHeadersToSpanAttributes","winterCGHeadersToDict","SENTRY_OP","HTTP_SERVER","addCloudResourceContext","addRequest","addCultureContext","NETWORK_PROTOCOL_NAME","NETWORK_PROTOCOL_VERSION","captureException","flushAndDispose","captureIncomingRequestBody","continueTrace","startSpanManual","setHttpStatus","classifyResponseStreaming"],"mappings":";;;;;;;;;;;;;AA8BA,SAAS,6BAA6B,OAAA,EAAqD;AAEzF,EAAA,OAAO,OAAA,IAAW,SAAA,IAAa,OAAA,GAAU,qCAAA,GAAwC,sBAAA;AACnF;AA6BO,SAAS,0BAAA,CACd,cAAA,EACA,OAAA,EACA,OAAA,EACmB;AACnB,EAAA,OAAOA,4CAAA,CAA6B,OAAM,cAAA,KAAkB;AAC1D,IAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,aAAA,GAAgB,MAAK,GAAI,cAAA;AACnD,IAAA,MAAM,UAAU,cAAA,CAAe,OAAA;AAK/B,IAAA,MAAM,kBAAkBC,oCAAA,EAAmB;AAC3C,IAAA,MAAM,SAAA,GAAY,eAAA,GACdC,wCAAA,CAAuB,eAAe,CAAA,GACtC,OAAA,GACEC,0BAAA,CAAqB,OAAO,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA,GAC1C,MAAA;AACN,IAAA,MAAM,kBAAA,GAAqB,6BAA6B,OAAO,CAAA;AAE/D,IAAA,MAAM,SAAS,OAAA,CAAQ,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AACnD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAK/B,IAAAC,sDAAA,EAA2B;AAE3B,IAAA,MAAM,SAAA,GAAYC,2BAAA,CAAuB,OAAA,CAAQ,GAAG,CAAA;AACpD,IAAA,MAAM,CAAC,OAAA,EAASC,YAAU,CAAA,GAAIC,oCAAA;AAAA,MAC5B,SAAA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ACF;AAGA,UAAA,IAAA,CAAK,GAAA,EAAI;AAKT,UAAA,IAAI,GAAA,CAAI,WAAW,GAAA,EAAK;AACtB,YAAA,SAAA,GAAY,MAAA,EAAQ,KAAA,CAAM,GAAI,CAAC,CAAA;AAAA,UACjC,CAAA,MAAO;AACL,YAAA,SAAA,GAAYA,qBAAA,CAAgB,MAAM,CAAC,CAAA;AAAA,UACrC;AACA,UAAA,OAAO,GAAA;AAAA,QACT,CAAC,CAAA;AAAA,MACH;AAAA,KACF;AAAA,EACF,CAAA,EAAG,eAAe,OAAO,CAAA;AAC3B;;;;"}
@@ -1,4 +1,4 @@
1
- import { dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, conversationIdIntegration, linkedErrorsIntegration, requestDataIntegration, consoleIntegration, GLOBAL_OBJ, debug, getCurrentScope, setCurrentClient, getIntegrationsToSetup, stackParserFromStackParserOptions, initAndBind } from '@sentry/core';
1
+ import { dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, conversationIdIntegration, linkedErrorsIntegration, requestDataIntegration, consoleIntegration, GLOBAL_OBJ, _INTERNAL_isClientClosed, debug, getCurrentScope, setCurrentClient, getIntegrationsToSetup, stackParserFromStackParserOptions, initAndBind } from '@sentry/core';
2
2
  import { CloudflareClient } from './client.js';
3
3
  import { makeFlushLock } from './flush.js';
4
4
  import { getCachedClient, cacheClient } from './clientCache.js';
@@ -38,7 +38,7 @@ function getBaseDefaultIntegrations(options) {
38
38
  function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
39
39
  const cached = getCachedClient();
40
40
  const cacheEnabled = options.cacheClient !== false;
41
- if (cacheEnabled && cached) {
41
+ if (cacheEnabled && cached && !_INTERNAL_isClientClosed(cached)) {
42
42
  if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {
43
43
  debug.warn(
44
44
  "[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options."
@@ -71,6 +71,9 @@ function initWithDefaultIntegrations(options, getDefaultIntegrationsImpl) {
71
71
  );
72
72
  }
73
73
  /*! rollup-include-development-only-end */
74
+ if (!cacheEnabled) {
75
+ getCurrentScope().setClient(void 0);
76
+ }
74
77
  const client = initAndBind(CloudflareClient, clientOptions);
75
78
  if (cacheEnabled && client) {
76
79
  cacheClient(client);
@@ -1 +1 @@
1
- {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { debug, getCurrentScope, setCurrentClient } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { cacheClient, getCachedClient } from './clientCache';\nimport { DEBUG_BUILD } from './debug-build';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n *\n * The client is cached and reused across invocations within the same isolate,\n * unless `cacheClient: false` is passed. This avoids the\n * per-invocation cost of constructing a new client, and it is what makes\n * Durable Object telemetry reliable: a per-invocation client is disposed at\n * the end of the handler, and in a Durable Object there is no `waitUntil`\n * boundary that reliably extends execution, so spans/events that end after\n * disposal would otherwise be lost.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n const cached = getCachedClient();\n const cacheEnabled = options.cacheClient !== false;\n\n if (cacheEnabled && cached) {\n if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {\n debug.warn(\n '[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options.',\n );\n }\n getCurrentScope().update(options.initialScope);\n setCurrentClient(cached);\n return cached;\n }\n\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n // A cached client outlives any single invocation, so binding it to one\n // invocation's flush lock would make later flushes wait on that invocation's\n // waitUntil work forever. Eager delivery replaces the flush lock's purpose.\n const invocationContext = options.ctx;\n const flushLock = !cacheEnabled && invocationContext ? makeFlushLock(invocationContext) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n cacheClient: cacheEnabled,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n if (cacheEnabled && client) {\n cacheClient(client);\n }\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {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A,EAAc,IAAI,UAAU,CAAA;AAC/E,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,MAAA,CAAO,cAAA,CAAe,SAAS,CAAA;AAAA,IACjC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;AAOO,SAAS,YAAY,OAAA,EAA0D;AACpF,EAAA,OAAO,2BAAA,CAA4B,SAAS,0BAA0B,CAAA;AACxE;;;;"}
1
+ {"version":3,"file":"baseSdk.js","sources":["../../../src/baseSdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { _INTERNAL_isClientClosed, debug, getCurrentScope, setCurrentClient } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n eventFiltersIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n GLOBAL_OBJ,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { cacheClient, getCachedClient } from './clientCache';\nimport { DEBUG_BUILD } from './debug-build';\nimport { fetchIntegration } from './integrations/fetch';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { INTEGRATION_NAME as SPOTLIGHT_INTEGRATION_NAME, spotlightIntegration } from './integrations/spotlight';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/**\n * Instantiate the channel-subscriber factories the `@sentry/cloudflare/vite`\n * plugin registered on the global marker. The plugin splices a small snippet\n * into each instrumented module that `.set`s its factory here (keyed by module\n * name), so the marker holds one factory per package actually bundled.\n *\n * The marker is read directly instead of importing the factories, so a worker\n * built without the plugin — where the channels never fire — ships none of this\n * code.\n */\nfunction getRegisteredChannelIntegrations(): Integration[] {\n const registered = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations;\n\n return registered ? [...registered.values()].map(factory => factory()) : [];\n}\n\n/**\n * Get the default integrations that run on any Workers-compatible runtime, i.e. without the\n * `nodejs_compat` compatibility flag.\n *\n * `getDefaultIntegrations` in `sdk.ts` extends this set with the integrations that do depend on\n * Node.js APIs. Keeping the two apart is what allows `wrapRequestHandler` to stay usable on runtimes\n * that cannot enable `nodejs_compat`, such as Shopify Oxygen.\n */\nexport function getBaseDefaultIntegrations(options: CloudflareOptions): Integration[] {\n return [\n // The Dedupe integration should not be used in workflows because we want to\n // capture all step failures, even if they are the same error.\n ...(options.enableDedupe === false ? [] : [dedupeIntegration()]),\n eventFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n httpServerIntegration(),\n requestDataIntegration(),\n consoleIntegration(),\n // The orchestrion diagnostics-channel subscribers (mysql, pg, …). The\n // `@sentry/cloudflare/vite` plugin injects the channels at build time and,\n // next to each, a snippet that registers the matching subscriber factory on\n // the global marker. Read from there instead of importing them so bundles\n // built without the plugin — where the channels would never fire — don't\n // ship the code.\n ...getRegisteredChannelIntegrations(),\n ];\n}\n\n/**\n * Initializes the Cloudflare SDK with the passed default integrations.\n *\n * The default integrations are injected rather than imported so that this module stays free of\n * Node.js-only code. `request.ts` — which backs both `wrapRequestHandler` and the\n * `@sentry/cloudflare/request` entry point, and therefore has to work on runtimes without the\n * `nodejs_compat` compatibility flag — creates its client from here instead of from `sdk.ts`.\n *\n * The client is cached and reused across invocations within the same isolate,\n * unless `cacheClient: false` is passed. This avoids the\n * per-invocation cost of constructing a new client, and it is what makes\n * Durable Object telemetry reliable: a per-invocation client is disposed at\n * the end of the handler, and in a Durable Object there is no `waitUntil`\n * boundary that reliably extends execution, so spans/events that end after\n * disposal would otherwise be lost.\n */\nexport function initWithDefaultIntegrations(\n options: CloudflareOptions,\n getDefaultIntegrationsImpl: (options: CloudflareOptions) => Integration[],\n): CloudflareClient | undefined {\n const cached = getCachedClient();\n const cacheEnabled = options.cacheClient !== false;\n\n // A closed client drops all data. `close()` marks the client before it\n // flushes, so this also skips a client that is still closing.\n if (cacheEnabled && cached && !_INTERNAL_isClientClosed(cached)) {\n if (DEBUG_BUILD && cached.getOptions().dsn !== options.dsn) {\n debug.warn(\n '[Sentry] init() was called with a different DSN than the cached client of this isolate; the cached client keeps its DSN. Pass `cacheClient: false` for per-invocation options.',\n );\n }\n getCurrentScope().update(options.initialScope);\n setCurrentClient(cached);\n return cached;\n }\n\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrationsImpl(options);\n }\n\n // A cached client outlives any single invocation, so binding it to one\n // invocation's flush lock would make later flushes wait on that invocation's\n // waitUntil work forever. Eager delivery replaces the flush lock's purpose.\n const invocationContext = options.ctx;\n const flushLock = !cacheEnabled && invocationContext ? makeFlushLock(invocationContext) : undefined;\n delete options.ctx;\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n cacheClient: cacheEnabled,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: getIntegrationsToSetup(options),\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /*! rollup-include-development-only */\n if (options.spotlight && !clientOptions.integrations.some(({ name }) => name === SPOTLIGHT_INTEGRATION_NAME)) {\n clientOptions.integrations.push(\n spotlightIntegration({\n sidecarUrl: typeof options.spotlight === 'string' ? options.spotlight : undefined,\n }),\n );\n }\n /*! rollup-include-development-only-end */\n\n if (!cacheEnabled) {\n // `cacheClient: false` asks for a new client on each call, so replacing\n // the bound client is expected here and must not warn.\n getCurrentScope().setClient(undefined);\n }\n\n const client = initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n\n if (cacheEnabled && client) {\n cacheClient(client);\n }\n\n // An instrumented module that first evaluates AFTER this init (e.g. a driver\n // lazily required on first use) stores its subscriber factory on the global\n // marker too late for the default-integrations snapshot above. Its injected\n // snippet emits this event right after storing the factory, so install the\n // integration on the live client here. `addIntegration` dedupes by\n // integration name, so already-installed integrations are no-ops.\n client.on('orchestrion.module-injected', moduleName => {\n const factory = GLOBAL_OBJ.__SENTRY_ORCHESTRION__?.integrations?.get(moduleName);\n if (factory) {\n client.addIntegration(factory());\n }\n });\n\n return client;\n}\n\n/**\n * Initializes the Cloudflare SDK with only the default integrations from\n * {@link getBaseDefaultIntegrations}, i.e. those that work without the `nodejs_compat`\n * compatibility flag.\n */\nexport function initBaseSdk(options: CloudflareOptions): CloudflareClient | undefined {\n return initWithDefaultIntegrations(options, getBaseDefaultIntegrations);\n}\n"],"names":["SPOTLIGHT_INTEGRATION_NAME"],"mappings":";;;;;;;;;;;AAoCA,SAAS,gCAAA,GAAkD;AACzD,EAAA,MAAM,UAAA,GAAa,WAAW,sBAAA,EAAwB,YAAA;AAEtD,EAAA,OAAO,UAAA,GAAa,CAAC,GAAG,UAAA,CAAW,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,CAAA,OAAA,KAAW,OAAA,EAAS,CAAA,GAAI,EAAC;AAC5E;AAUO,SAAS,2BAA2B,OAAA,EAA2C;AACpF,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAAC,mBAAmB,CAAA;AAAA,IAC9D,uBAAA,EAAwB;AAAA,IACxB,2BAAA,EAA4B;AAAA,IAC5B,yBAAA,EAA0B;AAAA,IAC1B,uBAAA,EAAwB;AAAA,IACxB,gBAAA,EAAiB;AAAA,IACjB,qBAAA,EAAsB;AAAA,IACtB,sBAAA,EAAuB;AAAA,IACvB,kBAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnB,GAAG,gCAAA;AAAiC,GACtC;AACF;AAkBO,SAAS,2BAAA,CACd,SACA,0BAAA,EAC8B;AAC9B,EAAA,MAAM,SAAS,eAAA,EAAgB;AAC/B,EAAA,MAAM,YAAA,GAAe,QAAQ,WAAA,KAAgB,KAAA;AAI7C,EAAA,IAAI,YAAA,IAAgB,MAAA,IAAU,CAAC,wBAAA,CAAyB,MAAM,CAA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A;AAGA,EAAA,IAAI,CAAC,YAAA,EAAc;AAGjB,IAAA,eAAA,EAAgB,CAAE,UAAU,MAAS,CAAA;AAAA,EACvC;AAEA,EAAA,MAAM,MAAA,GAAS,WAAA,CAAY,gBAAA,EAAkB,aAAa,CAAA;AAE1D,EAAA,IAAI,gBAAgB,MAAA,EAAQ;AAC1B,IAAA,WAAA,CAAY,MAAM,CAAA;AAAA,EACpB;AAQA,EAAA,MAAA,CAAO,EAAA,CAAG,+BAA+B,CAAA,UAAA,KAAc;AACrD,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,sBAAA,EAAwB,YAAA,EAAc,IAAI,UAAU,CAAA;AAC/E,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,MAAA,CAAO,cAAA,CAAe,SAAS,CAAA;AAAA,IACjC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;AAOO,SAAS,YAAY,OAAA,EAA0D;AACpF,EAAA,OAAO,2BAAA,CAA4B,SAAS,0BAA0B,CAAA;AACxE;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { RPC } from '@sentry/conventions/op';
2
2
  import { getIsolationScope, getDefaultIsolationScope, isObjectLike, startNewTrace } from '@sentry/core';
3
- import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
3
+ import { setAsyncLocalStorageAsyncContextStrategyForWorker } from './utils/asyncContextStrategy.js';
4
4
  import { markAsInstrumented, getInstrumented } from './instrument.js';
5
5
  import { instrumentDurableObjectHandlers } from './instrumentations/instrumentDurableObjectHandlers.js';
6
6
  import { instrumentEnv } from './instrumentations/worker/instrumentEnv.js';
@@ -12,7 +12,7 @@ import { instrumentCloudflareAgent } from './instrumentations/agents/index.js';
12
12
  import { wrapMethodWithSentry } from './wrapMethodWithSentry.js';
13
13
 
14
14
  function constructInstrumentedDurableObject(target, ctx, env, newTarget, optionsCallback) {
15
- setAsyncLocalStorageAsyncContextStrategy();
15
+ setAsyncLocalStorageAsyncContextStrategyForWorker();
16
16
  const options = getFinalOptions(optionsCallback(env), env);
17
17
  const context = instrumentContext(ctx);
18
18
  const instrumentedEnv = instrumentEnv(env, options);