@sentry/cloudflare 10.53.1 → 10.54.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 (166) hide show
  1. package/build/cjs/async.js +4 -30
  2. package/build/cjs/async.js.map +1 -1
  3. package/build/cjs/client.js +31 -58
  4. package/build/cjs/client.js.map +1 -1
  5. package/build/cjs/d1.js +26 -80
  6. package/build/cjs/d1.js.map +1 -1
  7. package/build/cjs/debug-build.js +0 -5
  8. package/build/cjs/debug-build.js.map +1 -1
  9. package/build/cjs/durableobject.js +44 -131
  10. package/build/cjs/durableobject.js.map +1 -1
  11. package/build/cjs/flush.js +47 -34
  12. package/build/cjs/flush.js.map +1 -1
  13. package/build/cjs/instrument.js +7 -48
  14. package/build/cjs/instrument.js.map +1 -1
  15. package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js +9 -34
  16. package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  17. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js +20 -54
  18. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  19. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js +12 -66
  20. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  21. package/build/cjs/instrumentations/worker/instrumentEmail.js +21 -43
  22. package/build/cjs/instrumentations/worker/instrumentEmail.js.map +1 -1
  23. package/build/cjs/instrumentations/worker/instrumentEnv.js +12 -42
  24. package/build/cjs/instrumentations/worker/instrumentEnv.js.map +1 -1
  25. package/build/cjs/instrumentations/worker/instrumentFetch.js +20 -34
  26. package/build/cjs/instrumentations/worker/instrumentFetch.js.map +1 -1
  27. package/build/cjs/instrumentations/worker/instrumentFetcher.js +5 -19
  28. package/build/cjs/instrumentations/worker/instrumentFetcher.js.map +1 -1
  29. package/build/cjs/instrumentations/worker/instrumentQueue.js +30 -62
  30. package/build/cjs/instrumentations/worker/instrumentQueue.js.map +1 -1
  31. package/build/cjs/instrumentations/worker/instrumentQueueProducer.js +31 -57
  32. package/build/cjs/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  33. package/build/cjs/instrumentations/worker/instrumentScheduled.js +25 -54
  34. package/build/cjs/instrumentations/worker/instrumentScheduled.js.map +1 -1
  35. package/build/cjs/instrumentations/worker/instrumentTail.js +16 -43
  36. package/build/cjs/instrumentations/worker/instrumentTail.js.map +1 -1
  37. package/build/cjs/integrations/fetch.js +24 -56
  38. package/build/cjs/integrations/fetch.js.map +1 -1
  39. package/build/cjs/integrations/hono.js +7 -38
  40. package/build/cjs/integrations/hono.js.map +1 -1
  41. package/build/cjs/integrations/httpServer.js +6 -39
  42. package/build/cjs/integrations/httpServer.js.map +1 -1
  43. package/build/cjs/integrations/tracing/vercelai.js +3 -31
  44. package/build/cjs/integrations/tracing/vercelai.js.map +1 -1
  45. package/build/cjs/opentelemetry/tracer.js +17 -45
  46. package/build/cjs/opentelemetry/tracer.js.map +1 -1
  47. package/build/cjs/options.js +10 -46
  48. package/build/cjs/options.js.map +1 -1
  49. package/build/cjs/pages-plugin.js +9 -42
  50. package/build/cjs/pages-plugin.js.map +1 -1
  51. package/build/cjs/request.js +21 -67
  52. package/build/cjs/request.js.map +1 -1
  53. package/build/cjs/scope-utils.js +4 -15
  54. package/build/cjs/scope-utils.js.map +1 -1
  55. package/build/cjs/sdk.js +8 -25
  56. package/build/cjs/sdk.js.map +1 -1
  57. package/build/cjs/transport.js +14 -48
  58. package/build/cjs/transport.js.map +1 -1
  59. package/build/cjs/utils/instrumentContext.js +16 -52
  60. package/build/cjs/utils/instrumentContext.js.map +1 -1
  61. package/build/cjs/utils/isBinding.js +3 -23
  62. package/build/cjs/utils/isBinding.js.map +1 -1
  63. package/build/cjs/utils/isCloudflareClass.js +2 -8
  64. package/build/cjs/utils/isCloudflareClass.js.map +1 -1
  65. package/build/cjs/utils/rpcMeta.js +8 -32
  66. package/build/cjs/utils/rpcMeta.js.map +1 -1
  67. package/build/cjs/utils/rpcOptions.js +9 -32
  68. package/build/cjs/utils/rpcOptions.js.map +1 -1
  69. package/build/cjs/utils/streaming.js +3 -29
  70. package/build/cjs/utils/streaming.js.map +1 -1
  71. package/build/cjs/utils/traceLinks.js +8 -33
  72. package/build/cjs/utils/traceLinks.js.map +1 -1
  73. package/build/cjs/vendor/stacktrace.js +6 -27
  74. package/build/cjs/vendor/stacktrace.js.map +1 -1
  75. package/build/cjs/withSentry.js +16 -47
  76. package/build/cjs/withSentry.js.map +1 -1
  77. package/build/cjs/workflows.js +40 -100
  78. package/build/cjs/workflows.js.map +1 -1
  79. package/build/cjs/wrapMethodWithSentry.js +110 -167
  80. package/build/cjs/wrapMethodWithSentry.js.map +1 -1
  81. package/build/esm/async.js +4 -30
  82. package/build/esm/async.js.map +1 -1
  83. package/build/esm/client.js +31 -58
  84. package/build/esm/client.js.map +1 -1
  85. package/build/esm/d1.js +26 -80
  86. package/build/esm/d1.js.map +1 -1
  87. package/build/esm/debug-build.js +0 -5
  88. package/build/esm/debug-build.js.map +1 -1
  89. package/build/esm/durableobject.js +44 -131
  90. package/build/esm/durableobject.js.map +1 -1
  91. package/build/esm/flush.js +47 -34
  92. package/build/esm/flush.js.map +1 -1
  93. package/build/esm/instrument.js +7 -48
  94. package/build/esm/instrument.js.map +1 -1
  95. package/build/esm/instrumentations/instrumentDurableObjectNamespace.js +9 -34
  96. package/build/esm/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  97. package/build/esm/instrumentations/instrumentDurableObjectStorage.js +20 -54
  98. package/build/esm/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  99. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js +12 -66
  100. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  101. package/build/esm/instrumentations/worker/instrumentEmail.js +21 -43
  102. package/build/esm/instrumentations/worker/instrumentEmail.js.map +1 -1
  103. package/build/esm/instrumentations/worker/instrumentEnv.js +12 -42
  104. package/build/esm/instrumentations/worker/instrumentEnv.js.map +1 -1
  105. package/build/esm/instrumentations/worker/instrumentFetch.js +20 -34
  106. package/build/esm/instrumentations/worker/instrumentFetch.js.map +1 -1
  107. package/build/esm/instrumentations/worker/instrumentFetcher.js +5 -19
  108. package/build/esm/instrumentations/worker/instrumentFetcher.js.map +1 -1
  109. package/build/esm/instrumentations/worker/instrumentQueue.js +30 -62
  110. package/build/esm/instrumentations/worker/instrumentQueue.js.map +1 -1
  111. package/build/esm/instrumentations/worker/instrumentQueueProducer.js +31 -57
  112. package/build/esm/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  113. package/build/esm/instrumentations/worker/instrumentScheduled.js +25 -54
  114. package/build/esm/instrumentations/worker/instrumentScheduled.js.map +1 -1
  115. package/build/esm/instrumentations/worker/instrumentTail.js +16 -43
  116. package/build/esm/instrumentations/worker/instrumentTail.js.map +1 -1
  117. package/build/esm/integrations/fetch.js +24 -56
  118. package/build/esm/integrations/fetch.js.map +1 -1
  119. package/build/esm/integrations/hono.js +7 -38
  120. package/build/esm/integrations/hono.js.map +1 -1
  121. package/build/esm/integrations/httpServer.js +6 -39
  122. package/build/esm/integrations/httpServer.js.map +1 -1
  123. package/build/esm/integrations/tracing/vercelai.js +3 -31
  124. package/build/esm/integrations/tracing/vercelai.js.map +1 -1
  125. package/build/esm/opentelemetry/tracer.js +17 -45
  126. package/build/esm/opentelemetry/tracer.js.map +1 -1
  127. package/build/esm/options.js +10 -46
  128. package/build/esm/options.js.map +1 -1
  129. package/build/esm/package.json +1 -1
  130. package/build/esm/pages-plugin.js +9 -42
  131. package/build/esm/pages-plugin.js.map +1 -1
  132. package/build/esm/request.js +21 -67
  133. package/build/esm/request.js.map +1 -1
  134. package/build/esm/scope-utils.js +4 -15
  135. package/build/esm/scope-utils.js.map +1 -1
  136. package/build/esm/sdk.js +8 -25
  137. package/build/esm/sdk.js.map +1 -1
  138. package/build/esm/transport.js +14 -48
  139. package/build/esm/transport.js.map +1 -1
  140. package/build/esm/utils/instrumentContext.js +16 -52
  141. package/build/esm/utils/instrumentContext.js.map +1 -1
  142. package/build/esm/utils/isBinding.js +3 -23
  143. package/build/esm/utils/isBinding.js.map +1 -1
  144. package/build/esm/utils/isCloudflareClass.js +2 -8
  145. package/build/esm/utils/isCloudflareClass.js.map +1 -1
  146. package/build/esm/utils/rpcMeta.js +8 -32
  147. package/build/esm/utils/rpcMeta.js.map +1 -1
  148. package/build/esm/utils/rpcOptions.js +9 -32
  149. package/build/esm/utils/rpcOptions.js.map +1 -1
  150. package/build/esm/utils/streaming.js +3 -29
  151. package/build/esm/utils/streaming.js.map +1 -1
  152. package/build/esm/utils/traceLinks.js +8 -33
  153. package/build/esm/utils/traceLinks.js.map +1 -1
  154. package/build/esm/vendor/stacktrace.js +6 -27
  155. package/build/esm/vendor/stacktrace.js.map +1 -1
  156. package/build/esm/withSentry.js +16 -47
  157. package/build/esm/withSentry.js.map +1 -1
  158. package/build/esm/workflows.js +40 -100
  159. package/build/esm/workflows.js.map +1 -1
  160. package/build/esm/wrapMethodWithSentry.js +110 -167
  161. package/build/esm/wrapMethodWithSentry.js.map +1 -1
  162. package/build/types/client.d.ts.map +1 -1
  163. package/build/types/flush.d.ts.map +1 -1
  164. package/build/types/instrumentations/worker/instrumentFetch.d.ts.map +1 -1
  165. package/build/types/pages-plugin.d.ts.map +1 -1
  166. package/package.json +2 -2
@@ -7,132 +7,92 @@ const scopeUtils = require('./scope-utils.js');
7
7
  const sdk = require('./sdk.js');
8
8
  const streaming = require('./utils/streaming.js');
9
9
 
10
- /**
11
- * Wraps a cloudflare request handler in Sentry instrumentation
12
- */
13
- function wrapRequestHandler(
14
- wrapperOptions,
15
- handler,
16
- ) {
17
- return core.withIsolationScope(async isolationScope => {
10
+ function wrapRequestHandler(wrapperOptions, handler) {
11
+ return core.withIsolationScope(async (isolationScope) => {
18
12
  const { options, request, captureErrors = true } = wrapperOptions;
19
13
  const context = wrapperOptions.context;
20
-
21
14
  const waitUntil = context?.waitUntil?.bind?.(context);
22
-
23
15
  const client = sdk.init({ ...options, ctx: context });
24
16
  isolationScope.setClient(client);
25
-
26
17
  const urlObject = core.parseStringToURLObject(request.url);
27
- const [name, attributes] = core.getHttpSpanDetailsFromUrlObject(urlObject, 'server', 'auto.http.cloudflare', request);
28
-
29
- const contentLength = request.headers.get('content-length');
18
+ const [name, attributes] = core.getHttpSpanDetailsFromUrlObject(urlObject, "server", "auto.http.cloudflare", request);
19
+ const contentLength = request.headers.get("content-length");
30
20
  if (contentLength) {
31
- attributes['http.request.body.size'] = parseInt(contentLength, 10);
21
+ attributes["http.request.body.size"] = parseInt(contentLength, 10);
32
22
  }
33
-
34
- const userAgentHeader = request.headers.get('user-agent');
23
+ const userAgentHeader = request.headers.get("user-agent");
35
24
  if (userAgentHeader) {
36
- attributes['user_agent.original'] = userAgentHeader;
25
+ attributes["user_agent.original"] = userAgentHeader;
37
26
  }
38
-
39
27
  Object.assign(
40
28
  attributes,
41
29
  core.httpHeadersToSpanAttributes(
42
30
  core.winterCGHeadersToDict(request.headers),
43
- core.getClient()?.getOptions().sendDefaultPii ?? false,
44
- ),
31
+ core.getClient()?.getOptions().sendDefaultPii ?? false
32
+ )
45
33
  );
46
-
47
- attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';
48
-
34
+ attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = "http.server";
49
35
  scopeUtils.addCloudResourceContext(isolationScope);
50
36
  scopeUtils.addRequest(isolationScope, request);
51
37
  if (request.cf) {
52
38
  scopeUtils.addCultureContext(isolationScope, request.cf);
53
-
54
- if (typeof request.cf.httpProtocol === 'string') {
55
- attributes['network.protocol.name'] = request.cf.httpProtocol;
39
+ if (typeof request.cf.httpProtocol === "string") {
40
+ attributes["network.protocol.name"] = request.cf.httpProtocol;
56
41
  }
57
42
  }
58
-
59
- // Do not capture spans for OPTIONS and HEAD requests
60
- if (request.method === 'OPTIONS' || request.method === 'HEAD') {
43
+ if (request.method === "OPTIONS" || request.method === "HEAD") {
61
44
  try {
62
45
  return await handler();
63
46
  } catch (e) {
64
47
  if (captureErrors) {
65
- core.captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
48
+ core.captureException(e, { mechanism: { handled: false, type: "auto.http.cloudflare" } });
66
49
  }
67
50
  throw e;
68
51
  } finally {
69
52
  waitUntil?.(flush.flushAndDispose(client));
70
53
  }
71
54
  }
72
-
73
55
  if (client) {
74
56
  await httpServer.captureIncomingRequestBody(client, request);
75
57
  }
76
-
77
58
  return core.continueTrace(
78
- { sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
59
+ { sentryTrace: request.headers.get("sentry-trace") || "", baggage: request.headers.get("baggage") },
79
60
  () => {
80
- // Note: This span will not have a duration unless I/O happens in the handler. This is
81
- // because of how the cloudflare workers runtime works.
82
- // See: https://developers.cloudflare.com/workers/runtime-apis/performance/
83
-
84
- // Use startSpanManual to control when span ends (needed for streaming responses)
85
- return core.startSpanManual({ name, attributes }, async span => {
61
+ return core.startSpanManual({ name, attributes }, async (span) => {
86
62
  let res;
87
-
88
63
  try {
89
64
  res = await handler();
90
65
  core.setHttpStatus(span, res.status);
91
-
92
- // After the handler runs, the span name might have been updated by nested instrumentation
93
- // (e.g., Remix parameterizing routes). The span should already have the correct name
94
- // from that instrumentation, so we don't need to do anything here.
95
66
  } catch (e) {
96
67
  span.end();
97
68
  if (captureErrors) {
98
- core.captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
69
+ core.captureException(e, { mechanism: { handled: false, type: "auto.http.cloudflare" } });
99
70
  }
100
71
  waitUntil?.(flush.flushAndDispose(client));
101
72
  throw e;
102
73
  }
103
-
104
- // Classify response to detect actual streaming
105
74
  const classification = streaming.classifyResponseStreaming(res);
106
-
107
75
  if (classification.isStreaming && res.body) {
108
76
  try {
109
77
  let ended = false;
110
-
111
78
  const endSpanOnce = () => {
112
79
  if (ended) return;
113
-
114
80
  ended = true;
115
81
  span.end();
116
82
  waitUntil?.(flush.flushAndDispose(client));
117
83
  };
118
-
119
84
  const transform = new TransformStream({
120
85
  flush() {
121
- // Source stream completed normally.
122
86
  endSpanOnce();
123
87
  },
124
88
  cancel() {
125
- // Client disconnected (or downstream cancelled). The `cancel`
126
- // is being called while the response is still considered
127
- // active, so this is a safe place to end the span.
128
89
  endSpanOnce();
129
- },
90
+ }
130
91
  });
131
-
132
92
  return new Response(res.body.pipeThrough(transform), {
133
93
  status: res.status,
134
94
  statusText: res.statusText,
135
- headers: res.headers,
95
+ headers: res.headers
136
96
  });
137
97
  } catch {
138
98
  span.end();
@@ -140,21 +100,15 @@ function wrapRequestHandler(
140
100
  return res;
141
101
  }
142
102
  }
143
-
144
- // Non-streaming response - end span immediately and return original
145
103
  span.end();
146
-
147
- // Don't dispose for protocol upgrades (101 Switching Protocols) - the connection stays alive.
148
- // This includes WebSocket upgrades where webSocketMessage/webSocketClose handlers
149
- // will still be called and may need the client to capture errors.
150
104
  if (res.status === 101) {
151
- waitUntil?.(client?.flush(2000));
105
+ waitUntil?.(client?.flush(2e3));
152
106
  } else {
153
107
  waitUntil?.(flush.flushAndDispose(client));
154
108
  }
155
109
  return res;
156
110
  });
157
- },
111
+ }
158
112
  );
159
113
  });
160
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sources":["../../src/request.ts"],"sourcesContent":["import type { CfProperties, ExecutionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport {\n captureException,\n continueTrace,\n getClient,\n getHttpSpanDetailsFromUrlObject,\n httpHeadersToSpanAttributes,\n parseStringToURLObject,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n setHttpStatus,\n startSpanManual,\n winterCGHeadersToDict,\n withIsolationScope,\n} from '@sentry/core';\nimport { captureIncomingRequestBody } from './integrations/httpServer';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose } from './flush';\nimport { addCloudResourceContext, addCultureContext, addRequest } from './scope-utils';\nimport { init } from './sdk';\nimport { classifyResponseStreaming } from './utils/streaming';\n\ninterface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown> | CfProperties<unknown>>;\n context: ExecutionContext | 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\n/**\n * Wraps a cloudflare request handler in Sentry instrumentation\n */\nexport function wrapRequestHandler(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n): Promise<Response> {\n return withIsolationScope(async isolationScope => {\n const { options, request, captureErrors = true } = wrapperOptions;\n const context = wrapperOptions.context;\n\n const waitUntil = context?.waitUntil?.bind?.(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n const urlObject = parseStringToURLObject(request.url);\n const [name, attributes] = getHttpSpanDetailsFromUrlObject(urlObject, 'server', 'auto.http.cloudflare', request);\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 Object.assign(\n attributes,\n httpHeadersToSpanAttributes(\n winterCGHeadersToDict(request.headers),\n getClient()?.getOptions().sendDefaultPii ?? false,\n ),\n );\n\n attributes[SEMANTIC_ATTRIBUTE_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 attributes['network.protocol.name'] = request.cf.httpProtocol;\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: 'auto.http.cloudflare' } });\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: 'auto.http.cloudflare' } });\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 });\n}\n"],"names":["withIsolationScope","init","parseStringToURLObject","getHttpSpanDetailsFromUrlObject","httpHeadersToSpanAttributes","winterCGHeadersToDict","getClient","SEMANTIC_ATTRIBUTE_SENTRY_OP","addCloudResourceContext","addRequest","addCultureContext","captureException","flushAndDispose","captureIncomingRequestBody","continueTrace","startSpanManual","setHttpStatus","classifyResponseStreaming"],"mappings":";;;;;;;;;AAsCA;AACA;AACA;AACO,SAAS,kBAAkB;AAClC,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAqB;AACrB,EAAE,OAAOA,uBAAkB,CAAC,MAAM,kBAAkB;AACpD,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAA,GAAgB,IAAA,EAAK,GAAI,cAAc;AACrE,IAAI,MAAM,OAAA,GAAU,cAAc,CAAC,OAAO;;AAE1C,IAAI,MAAM,SAAA,GAAY,OAAO,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC;;AAEzD,IAAI,MAAM,MAAA,GAASC,QAAI,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,OAAA,EAAS,CAAC;AACrD,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC;;AAEpC,IAAI,MAAM,YAAYC,2BAAsB,CAAC,OAAO,CAAC,GAAG,CAAC;AACzD,IAAI,MAAM,CAAC,IAAI,EAAE,UAAU,IAAIC,oCAA+B,CAAC,SAAS,EAAE,QAAQ,EAAE,sBAAsB,EAAE,OAAO,CAAC;;AAEpH,IAAI,MAAM,aAAA,GAAgB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;AAC/D,IAAI,IAAI,aAAa,EAAE;AACvB,MAAM,UAAU,CAAC,wBAAwB,CAAA,GAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;AACxE,IAAI;;AAEJ,IAAI,MAAM,eAAA,GAAkB,OAAO,C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utionContext, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport {\n captureException,\n continueTrace,\n getClient,\n getHttpSpanDetailsFromUrlObject,\n httpHeadersToSpanAttributes,\n parseStringToURLObject,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n setHttpStatus,\n startSpanManual,\n winterCGHeadersToDict,\n withIsolationScope,\n} from '@sentry/core';\nimport { captureIncomingRequestBody } from './integrations/httpServer';\nimport type { CloudflareOptions } from './client';\nimport { flushAndDispose } from './flush';\nimport { addCloudResourceContext, addCultureContext, addRequest } from './scope-utils';\nimport { init } from './sdk';\nimport { classifyResponseStreaming } from './utils/streaming';\n\ninterface RequestHandlerWrapperOptions {\n options: CloudflareOptions;\n request: Request<unknown, IncomingRequestCfProperties<unknown> | CfProperties<unknown>>;\n context: ExecutionContext | 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\n/**\n * Wraps a cloudflare request handler in Sentry instrumentation\n */\nexport function wrapRequestHandler(\n wrapperOptions: RequestHandlerWrapperOptions,\n handler: (...args: unknown[]) => Response | Promise<Response>,\n): Promise<Response> {\n return withIsolationScope(async isolationScope => {\n const { options, request, captureErrors = true } = wrapperOptions;\n const context = wrapperOptions.context;\n\n const waitUntil = context?.waitUntil?.bind?.(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n const urlObject = parseStringToURLObject(request.url);\n const [name, attributes] = getHttpSpanDetailsFromUrlObject(urlObject, 'server', 'auto.http.cloudflare', request);\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 Object.assign(\n attributes,\n httpHeadersToSpanAttributes(\n winterCGHeadersToDict(request.headers),\n getClient()?.getOptions().sendDefaultPii ?? false,\n ),\n );\n\n attributes[SEMANTIC_ATTRIBUTE_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 attributes['network.protocol.name'] = request.cf.httpProtocol;\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: 'auto.http.cloudflare' } });\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: 'auto.http.cloudflare' } });\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 });\n}\n"],"names":["withIsolationScope","init","parseStringToURLObject","getHttpSpanDetailsFromUrlObject","httpHeadersToSpanAttributes","winterCGHeadersToDict","getClient","SEMANTIC_ATTRIBUTE_SENTRY_OP","addCloudResourceContext","addRequest","addCultureContext","captureException","flushAndDispose","captureIncomingRequestBody","continueTrace","startSpanManual","setHttpStatus","classifyResponseStreaming"],"mappings":";;;;;;;;;AAyCO,SAAS,kBAAA,CACd,gBACA,OAAA,EACmB;AACnB,EAAA,OAAOA,uBAAA,CAAmB,OAAM,cAAA,KAAkB;AAChD,IAAA,MAAM,EAAE,OAAA,EAAS,OAAA,EAAS,aAAA,GAAgB,MAAK,GAAI,cAAA;AACnD,IAAA,MAAM,UAAU,cAAA,CAAe,OAAA;AAE/B,IAAA,MAAM,SAAA,GAAY,OAAA,EAAS,SAAA,EAAW,IAAA,GAAO,OAAO,CAAA;AAEpD,IAAA,MAAM,SAASC,QAAA,CAAK,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AAChD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAA,MAAM,SAAA,GAAYC,2BAAA,CAAuB,OAAA,CAAQ,GAAG,CAAA;AACpD,IAAA,MAAM,CAAC,MAAM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@@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const core = require('@sentry/core');
4
4
 
5
- /**
6
- * Set cloud resource context on scope.
7
- */
8
5
  function addCloudResourceContext(scope) {
9
- scope.setContext('cloud_resource', {
10
- 'cloud.provider': 'cloudflare',
6
+ scope.setContext("cloud_resource", {
7
+ "cloud.provider": "cloudflare"
11
8
  });
12
9
  }
13
-
14
- /**
15
- * Set culture context on scope
16
- */
17
10
  function addCultureContext(scope, cf) {
18
- scope.setContext('culture', {
19
- timezone: cf.timezone,
11
+ scope.setContext("culture", {
12
+ timezone: cf.timezone
20
13
  });
21
14
  }
22
-
23
- /**
24
- * Set request data on scope
25
- */
26
15
  function addRequest(scope, request) {
27
16
  scope.setSDKProcessingMetadata({ normalizedRequest: core.winterCGRequestToRequestData(request) });
28
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scope-utils.js","sources":["../../src/scope-utils.ts"],"sourcesContent":["import type { CfProperties, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport type { Scope } from '@sentry/core';\nimport { winterCGRequestToRequestData } from '@sentry/core';\n\n/**\n * Set cloud resource context on scope.\n */\nexport function addCloudResourceContext(scope: Scope): void {\n scope.setContext('cloud_resource', {\n 'cloud.provider': 'cloudflare',\n });\n}\n\n/**\n * Set culture context on scope\n */\nexport function addCultureContext(scope: Scope, cf: IncomingRequestCfProperties | CfProperties): void {\n scope.setContext('culture', {\n timezone: cf.timezone,\n });\n}\n\n/**\n * Set request data on scope\n */\nexport function addRequest(scope: Scope, request: Request): void {\n scope.setSDKProcessingMetadata({ normalizedRequest: winterCGRequestToRequestData(request) });\n}\n"],"names":["winterCGRequestToRequestData"],"mappings":";;;;AAIA;AACA;AACA;AACO,SAAS,uBAAuB,CAAC,KAAK,EAAe;AAC5D,EAAE,KAAK,CAAC,UAAU,CAAC,gBAAgB,EAAE;AACrC,IAAI,gBAAgB,EAAE,YAAY;AAClC,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAS,EAAE,EAAoD;AACtG,EAAE,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE;AAC9B,IAAI,QAAQ,EAAE,EAAE,CAAC,QAAQ;AACzB,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACO,SAAS,UAAU,CAAC,KAAK,EAAS,OAAO,EAAiB;AACjE,EAAE,KAAK,CAAC,wBAAwB,CAAC,EAAE,iBAAiB,EAAEA,iCAA4B,CAAC,OAAO,CAAA,EAAG,CAAC;AAC9F;;;;;;"}
1
+ {"version":3,"file":"scope-utils.js","sources":["../../src/scope-utils.ts"],"sourcesContent":["import type { CfProperties, IncomingRequestCfProperties } from '@cloudflare/workers-types';\nimport type { Scope } from '@sentry/core';\nimport { winterCGRequestToRequestData } from '@sentry/core';\n\n/**\n * Set cloud resource context on scope.\n */\nexport function addCloudResourceContext(scope: Scope): void {\n scope.setContext('cloud_resource', {\n 'cloud.provider': 'cloudflare',\n });\n}\n\n/**\n * Set culture context on scope\n */\nexport function addCultureContext(scope: Scope, cf: IncomingRequestCfProperties | CfProperties): void {\n scope.setContext('culture', {\n timezone: cf.timezone,\n });\n}\n\n/**\n * Set request data on scope\n */\nexport function addRequest(scope: Scope, request: Request): void {\n scope.setSDKProcessingMetadata({ normalizedRequest: winterCGRequestToRequestData(request) });\n}\n"],"names":["winterCGRequestToRequestData"],"mappings":";;;;AAOO,SAAS,wBAAwB,KAAA,EAAoB;AAC1D,EAAA,KAAA,CAAM,WAAW,gBAAA,EAAkB;AAAA,IACjC,gBAAA,EAAkB;AAAA,GACnB,CAAA;AACH;AAKO,SAAS,iBAAA,CAAkB,OAAc,EAAA,EAAsD;AACpG,EAAA,KAAA,CAAM,WAAW,SAAA,EAAW;AAAA,IAC1B,UAAU,EAAA,CAAG;AAAA,GACd,CAAA;AACH;AAKO,SAAS,UAAA,CAAW,OAAc,OAAA,EAAwB;AAC/D,EAAA,KAAA,CAAM,yBAAyB,EAAE,iBAAA,EAAmBA,iCAAA,CAA6B,OAAO,GAAG,CAAA;AAC7F;;;;;;"}
package/build/cjs/sdk.js CHANGED
@@ -10,13 +10,12 @@ const tracer = require('./opentelemetry/tracer.js');
10
10
  const transport = require('./transport.js');
11
11
  const stacktrace = require('./vendor/stacktrace.js');
12
12
 
13
- /** Get the default integrations for the Cloudflare SDK. */
14
13
  function getDefaultIntegrations(options) {
15
14
  const sendDefaultPii = options.sendDefaultPii ?? false;
16
15
  return [
17
16
  // The Dedupe integration should not be used in workflows because we want to
18
17
  // capture all step failures, even if they are the same error.
19
- ...(options.enableDedupe === false ? [] : [core.dedupeIntegration()]),
18
+ ...options.enableDedupe === false ? [] : [core.dedupeIntegration()],
20
19
  // TODO(v11): Replace with `eventFiltersIntegration` once we remove the deprecated `inboundFiltersIntegration`
21
20
  // eslint-disable-next-line deprecation/deprecation
22
21
  core.inboundFiltersIntegration(),
@@ -27,47 +26,31 @@ function getDefaultIntegrations(options) {
27
26
  hono.honoIntegration(),
28
27
  httpServer.httpServerIntegration(),
29
28
  // TODO(v11): the `include` object should be defined directly in the integration based on `sendDefaultPii`
30
- core.requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),
31
- core.consoleIntegration(),
29
+ core.requestDataIntegration(sendDefaultPii ? void 0 : { include: { cookies: false } }),
30
+ core.consoleIntegration()
32
31
  ];
33
32
  }
34
-
35
- /**
36
- * Initializes the cloudflare SDK.
37
- */
38
33
  function init(options) {
39
- if (options.defaultIntegrations === undefined) {
34
+ if (options.defaultIntegrations === void 0) {
40
35
  options.defaultIntegrations = getDefaultIntegrations(options);
41
36
  }
42
-
43
- const flushLock = options.ctx ? flush.makeFlushLock(options.ctx) : undefined;
37
+ const flushLock = options.ctx ? flush.makeFlushLock(options.ctx) : void 0;
44
38
  delete options.ctx;
45
-
46
39
  const resolvedIntegrations = core.getIntegrationsToSetup(options);
47
- if (options.traceLifecycle === 'stream' && !resolvedIntegrations.some(i => i.name === 'SpanStreaming')) {
40
+ if (options.traceLifecycle === "stream" && !resolvedIntegrations.some((i) => i.name === "SpanStreaming")) {
48
41
  resolvedIntegrations.push(core.spanStreamingIntegration());
49
42
  }
50
-
51
43
  const clientOptions = {
52
44
  ...options,
53
45
  stackParser: core.stackParserFromStackParserOptions(options.stackParser || stacktrace.defaultStackParser),
54
46
  integrations: resolvedIntegrations,
55
47
  transport: options.transport || transport.makeCloudflareTransport,
56
- flushLock,
48
+ flushLock
57
49
  };
58
-
59
- /**
60
- * The Cloudflare SDK is not OpenTelemetry native, however, we set up some OpenTelemetry compatibility
61
- * via a custom trace provider.
62
- * This ensures that any spans emitted via `@opentelemetry/api` will be captured by Sentry.
63
- * HOWEVER, big caveat: This does not handle custom context handling, it will always work off the current scope.
64
- * This should be good enough for many, but not all integrations.
65
- */
66
50
  if (!options.skipOpenTelemetrySetup) {
67
51
  tracer.setupOpenTelemetryTracer();
68
52
  }
69
-
70
- return core.initAndBind(client.CloudflareClient, clientOptions) ;
53
+ return core.initAndBind(client.CloudflareClient, clientOptions);
71
54
  }
72
55
 
73
56
  exports.getDefaultIntegrations = getDefaultIntegrations;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n spanStreamingIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { fetchIntegration } from './integrations/fetch';\nimport { honoIntegration } from './integrations/hono';\nimport { setupOpenTelemetryTracer } from './opentelemetry/tracer';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(options: CloudflareOptions): Integration[] {\n const sendDefaultPii = options.sendDefaultPii ?? false;\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 // TODO(v11): Replace with `eventFiltersIntegration` once we remove the deprecated `inboundFiltersIntegration`\n // eslint-disable-next-line deprecation/deprecation\n inboundFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n honoIntegration(),\n httpServerIntegration(),\n // TODO(v11): the `include` object should be defined directly in the integration based on `sendDefaultPii`\n requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),\n consoleIntegration(),\n ];\n}\n\n/**\n * Initializes the cloudflare SDK.\n */\nexport function init(options: CloudflareOptions): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrations(options);\n }\n\n const flushLock = options.ctx ? makeFlushLock(options.ctx) : undefined;\n delete options.ctx;\n\n const resolvedIntegrations = getIntegrationsToSetup(options);\n if (options.traceLifecycle === 'stream' && !resolvedIntegrations.some(i => i.name === 'SpanStreaming')) {\n resolvedIntegrations.push(spanStreamingIntegration());\n }\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: resolvedIntegrations,\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /**\n * The Cloudflare SDK is not OpenTelemetry native, however, we set up some OpenTelemetry compatibility\n * via a custom trace provider.\n * This ensures that any spans emitted via `@opentelemetry/api` will be captured by Sentry.\n * HOWEVER, big caveat: This does not handle custom context handling, it will always work off the current scope.\n * This should be good enough for many, but not all integrations.\n */\n if (!options.skipOpenTelemetrySetup) {\n setupOpenTelemetryTracer();\n }\n\n return initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n}\n"],"names":["dedupeIntegration","inboundFiltersIntegration","functionToStringIntegration","conversationIdIntegration","linkedErrorsIntegration","fetchIntegration","honoIntegration","httpServerIntegration","requestDataIntegration","consoleIntegration","makeFlushLock","getIntegrationsToSetup","spanStreamingIntegration","stackParserFromStackParserOptions","defaultStackParser","makeCloudflareTransport","setupOpenTelemetryTracer","initAndBind","CloudflareClient"],"mappings":";;;;;;;;;;;;AAwBA;AACO,SAAS,sBAAsB,CAAC,OAAO,EAAoC;AAClF,EAAE,MAAM,cAAA,GAAiB,OAAO,CAAC,cAAA,IAAkB,KAAK;AACxD,EAAE,OAAO;AACT;AACA;AACA,IAAI,IAAI,OAAO,CAAC,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAACA,sBAAiB,EAAE,CAAC,CAAC;AACpE;AACA;AACA,IAAIC,8BAAyB,EAAE;AAC/B,IAAIC,gCAA2B,EAAE;AACjC,IAAIC,8BAAyB,EAAE;AAC/B,IAAIC,4BAAuB,EAAE;AAC7B,IAAIC,sBAAgB,EAAE;AACtB,IAAIC,oBAAe,EAAE;AACrB,IAAIC,gCAAqB,EAAE;AAC3B;AACA,IAAIC,2BAAsB,CAAC,cAAA,GAAiB,YAAY,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,KAAA,EAAM,EAAG,CAAC;AACxF,IAAIC,uBAAkB,EAAE;AACxB,GAAG;AACH;;AAEA;AACA;AACA;AACO,SAAS,IAAI,CAAC,OAAO,EAAmD;AAC/E,EAAE,IAAI,OAAO,CAAC,mBAAA,KAAwB,SAAS,EAAE;AACjD,IAAI,OAAO,CAAC,mBAAA,GAAsB,sBAAsB,CAAC,OAAO,CAAC;AACjE,EAAE;;AAEF,EAAE,MAAM,SAAA,GAAY,OAAO,CAAC,GAAA,GAAMC,mBAAa,CAAC,OAAO,CAAC,GAAG,CAAA,GAAI,SAAS;AACxE,EAAE,OAAO,OAAO,CAAC,GAAG;;AAEpB,EAAE,MAAM,oBAAA,GAAuBC,2BAAsB,CAAC,OAAO,CAAC;AAC9D,EAAE,IAAI,OAAO,CAAC,mBAAmB,QAAA,IAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAA,KAAS,eAAe,CAAC,EAAE;AAC1G,IAAI,oBAAoB,CAAC,IAAI,CAACC,6BAAwB,EAAE,CAAC;AACzD,EAAE;;AAEF,EAAE,MAAM,aAAa,GAA4B;AACjD,IAAI,GAAG,OAAO;AACd,IAAI,WAAW,EAAEC,sCAAiC,CAAC,OAAO,CAAC,WAAA,IAAeC,6BAAkB,CAAC;AAC7F,IAAI,YAAY,EAAE,oBAAoB;AACtC,IAAI,SAAS,EAAE,OAAO,CAAC,SAAA,IAAaC,iCAAuB;AAC3D,IAAI,SAAS;AACb,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,OAAO,CAAC,sBAAsB,EAAE;AACvC,IAAIC,+BAAwB,EAAE;AAC9B,EAAE;;AAEF,EAAE,OAAOC,gBAAW,CAACC,uBAAgB,EAAE,aAAa,CAAA;AACpD;;;;;"}
1
+ {"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport {\n consoleIntegration,\n conversationIdIntegration,\n dedupeIntegration,\n functionToStringIntegration,\n getIntegrationsToSetup,\n inboundFiltersIntegration,\n initAndBind,\n linkedErrorsIntegration,\n requestDataIntegration,\n spanStreamingIntegration,\n stackParserFromStackParserOptions,\n} from '@sentry/core';\nimport type { CloudflareClientOptions, CloudflareOptions } from './client';\nimport { CloudflareClient } from './client';\nimport { makeFlushLock } from './flush';\nimport { httpServerIntegration } from './integrations/httpServer';\nimport { fetchIntegration } from './integrations/fetch';\nimport { honoIntegration } from './integrations/hono';\nimport { setupOpenTelemetryTracer } from './opentelemetry/tracer';\nimport { makeCloudflareTransport } from './transport';\nimport { defaultStackParser } from './vendor/stacktrace';\n\n/** Get the default integrations for the Cloudflare SDK. */\nexport function getDefaultIntegrations(options: CloudflareOptions): Integration[] {\n const sendDefaultPii = options.sendDefaultPii ?? false;\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 // TODO(v11): Replace with `eventFiltersIntegration` once we remove the deprecated `inboundFiltersIntegration`\n // eslint-disable-next-line deprecation/deprecation\n inboundFiltersIntegration(),\n functionToStringIntegration(),\n conversationIdIntegration(),\n linkedErrorsIntegration(),\n fetchIntegration(),\n honoIntegration(),\n httpServerIntegration(),\n // TODO(v11): the `include` object should be defined directly in the integration based on `sendDefaultPii`\n requestDataIntegration(sendDefaultPii ? undefined : { include: { cookies: false } }),\n consoleIntegration(),\n ];\n}\n\n/**\n * Initializes the cloudflare SDK.\n */\nexport function init(options: CloudflareOptions): CloudflareClient | undefined {\n if (options.defaultIntegrations === undefined) {\n options.defaultIntegrations = getDefaultIntegrations(options);\n }\n\n const flushLock = options.ctx ? makeFlushLock(options.ctx) : undefined;\n delete options.ctx;\n\n const resolvedIntegrations = getIntegrationsToSetup(options);\n if (options.traceLifecycle === 'stream' && !resolvedIntegrations.some(i => i.name === 'SpanStreaming')) {\n resolvedIntegrations.push(spanStreamingIntegration());\n }\n\n const clientOptions: CloudflareClientOptions = {\n ...options,\n stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),\n integrations: resolvedIntegrations,\n transport: options.transport || makeCloudflareTransport,\n flushLock,\n };\n\n /**\n * The Cloudflare SDK is not OpenTelemetry native, however, we set up some OpenTelemetry compatibility\n * via a custom trace provider.\n * This ensures that any spans emitted via `@opentelemetry/api` will be captured by Sentry.\n * HOWEVER, big caveat: This does not handle custom context handling, it will always work off the current scope.\n * This should be good enough for many, but not all integrations.\n */\n if (!options.skipOpenTelemetrySetup) {\n setupOpenTelemetryTracer();\n }\n\n return initAndBind(CloudflareClient, clientOptions) as CloudflareClient;\n}\n"],"names":["dedupeIntegration","inboundFiltersIntegration","functionToStringIntegration","conversationIdIntegration","linkedErrorsIntegration","fetchIntegration","honoIntegration","httpServerIntegration","requestDataIntegration","consoleIntegration","makeFlushLock","getIntegrationsToSetup","spanStreamingIntegration","stackParserFromStackParserOptions","defaultStackParser","makeCloudflareTransport","setupOpenTelemetryTracer","initAndBind","CloudflareClient"],"mappings":";;;;;;;;;;;;AAyBO,SAAS,uBAAuB,OAAA,EAA2C;AAChF,EAAA,MAAM,cAAA,GAAiB,QAAQ,cAAA,IAAkB,KAAA;AACjD,EAAA,OAAO;AAAA;AAAA;AAAA,IAGL,GAAI,QAAQ,YAAA,KAAiB,KAAA,GAAQ,EAAC,GAAI,CAACA,wBAAmB,CAAA;AAAA;AAAA;AAAA,IAG9DC,8BAAA,EAA0B;AAAA,IAC1BC,gCAAA,EAA4B;AAAA,IAC5BC,8BAAA,EAA0B;AAAA,IAC1BC,4BAAA,EAAwB;AAAA,IACxBC,sBAAA,EAAiB;AAAA,IACjBC,oBAAA,EAAgB;AAAA,IAChBC,gCAAA,EAAsB;AAAA;AAAA,IAEtBC,2BAAA,CAAuB,iBAAiB,MAAA,GAAY,EAAE,SAAS,EAAE,OAAA,EAAS,KAAA,EAAM,EAAG,CAAA;AAAA,IACnFC,uBAAA;AAAmB,GACrB;AACF;AAKO,SAAS,KAAK,OAAA,EAA0D;AAC7E,EAAA,IAAI,OAAA,CAAQ,wBAAwB,MAAA,EAAW;AAC7C,IAAA,OAAA,CAAQ,mBAAA,GAAsB,uBAAuB,OAAO,CAAA;AAAA,EAC9D;AAEA,EAAA,MAAM,YAAY,OAAA,CAAQ,GAAA,GAAMC,mBAAA,CAAc,OAAA,CAAQ,GAAG,CAAA,GAAI,MAAA;AAC7D,EAAA,OAAO,OAAA,CAAQ,GAAA;AAEf,EAAA,MAAM,oBAAA,GAAuBC,4BAAuB,OAAO,CAAA;AAC3D,EAAA,IAAI,OAAA,CAAQ,cAAA,KAAmB,QAAA,IAAY,CAAC,oBAAA,CAAqB,KAAK,CAAA,CAAA,KAAK,CAAA,CAAE,IAAA,KAAS,eAAe,CAAA,EAAG;AACtG,IAAA,oBAAA,CAAqB,IAAA,CAAKC,+BAA0B,CAAA;AAAA,EACtD;AAEA,EAAA,MAAM,aAAA,GAAyC;AAAA,IAC7C,GAAG,OAAA;AAAA,IACH,WAAA,EAAaC,sCAAA,CAAkC,OAAA,CAAQ,WAAA,IAAeC,6BAAkB,CAAA;AAAA,IACxF,YAAA,EAAc,oBAAA;AAAA,IACd,SAAA,EAAW,QAAQ,SAAA,IAAaC,iCAAA;AAAA,IAChC;AAAA,GACF;AASA,EAAA,IAAI,CAAC,QAAQ,sBAAA,EAAwB;AACnC,IAAAC,+BAAA,EAAyB;AAAA,EAC3B;AAEA,EAAA,OAAOC,gBAAA,CAAYC,yBAAkB,aAAa,CAAA;AACpD;;;;;"}
@@ -3,104 +3,70 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const core = require('@sentry/core');
4
4
 
5
5
  const DEFAULT_TRANSPORT_BUFFER_SIZE = 30;
6
-
7
- /**
8
- * This is a modified promise buffer that collects tasks until drain is called.
9
- * We need this in the edge runtime because edge function invocations may not share I/O objects, like fetch requests
10
- * and responses, and the normal PromiseBuffer inherently buffers stuff inbetween incoming requests.
11
- *
12
- * A limitation we need to be aware of is that DEFAULT_TRANSPORT_BUFFER_SIZE is the maximum amount of payloads the
13
- * SDK can send for a given edge function invocation.
14
- */
15
6
  class IsolatedPromiseBuffer {
16
- // We just have this field because the promise buffer interface requires it.
17
- // If we ever remove it from the interface we should also remove it here.
18
-
19
- constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) {
7
+ constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) {
20
8
  this.$ = [];
21
9
  this._taskProducers = [];
22
10
  this._bufferSize = _bufferSize;
23
11
  }
24
-
25
12
  /**
26
13
  * @inheritdoc
27
14
  */
28
- add(taskProducer) {
15
+ add(taskProducer) {
29
16
  if (this._taskProducers.length >= this._bufferSize) {
30
17
  return Promise.reject(core.SENTRY_BUFFER_FULL_ERROR);
31
18
  }
32
-
33
19
  this._taskProducers.push(taskProducer);
34
20
  return Promise.resolve({});
35
21
  }
36
-
37
22
  /**
38
23
  * @inheritdoc
39
24
  */
40
- drain(timeout) {
25
+ drain(timeout) {
41
26
  const oldTaskProducers = [...this._taskProducers];
42
27
  this._taskProducers = [];
43
-
44
- return new Promise(resolve => {
28
+ return new Promise((resolve) => {
45
29
  const timer = setTimeout(() => {
46
30
  if (timeout && timeout > 0) {
47
31
  resolve(false);
48
32
  }
49
33
  }, timeout);
50
-
51
- // This cannot reject
52
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
53
34
  Promise.all(
54
- oldTaskProducers.map(taskProducer =>
55
- taskProducer().then(null, () => {
56
- // catch all failed requests
57
- }),
58
- ),
35
+ oldTaskProducers.map(
36
+ (taskProducer) => taskProducer().then(null, () => {
37
+ })
38
+ )
59
39
  ).then(() => {
60
- // resolve to true if all fetch requests settled
61
40
  clearTimeout(timer);
62
41
  resolve(true);
63
42
  });
64
43
  });
65
44
  }
66
45
  }
67
-
68
- /**
69
- * Creates a Transport that uses the native fetch API to send events to Sentry.
70
- */
71
46
  function makeCloudflareTransport(options) {
72
47
  function makeRequest(request) {
73
48
  const requestOptions = {
74
49
  body: request.body,
75
- method: 'POST',
50
+ method: "POST",
76
51
  headers: options.headers,
77
- ...options.fetchOptions,
52
+ ...options.fetchOptions
78
53
  };
79
-
80
54
  return core.suppressTracing(() => {
81
- return (options.fetch ?? fetch)(options.url, requestOptions).then(async response => {
82
- // Consume the response body to satisfy Cloudflare Workers' fetch requirements.
83
- // The runtime requires all fetch response bodies to be read or explicitly canceled
84
- // to prevent connection stalls and potential deadlocks. We read the body as text
85
- // even though we don't use the content, as Sentry's response information is in the headers.
86
- // See: https://github.com/getsentry/sentry-javascript/issues/18534
55
+ return (options.fetch ?? fetch)(options.url, requestOptions).then(async (response) => {
87
56
  try {
88
57
  await response.text();
89
58
  } catch {
90
- // no-op
91
59
  }
92
-
93
60
  return {
94
61
  statusCode: response.status,
95
62
  headers: {
96
- 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
97
- 'retry-after': response.headers.get('Retry-After'),
98
- },
63
+ "x-sentry-rate-limits": response.headers.get("X-Sentry-Rate-Limits"),
64
+ "retry-after": response.headers.get("Retry-After")
65
+ }
99
66
  };
100
67
  });
101
68
  });
102
69
  }
103
-
104
70
  return core.createTransport(options, makeRequest, new IsolatedPromiseBuffer(options.bufferSize));
105
71
  }
106
72
 
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sources":["../../src/transport.ts"],"sourcesContent":["import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/core';\nimport { createTransport, SENTRY_BUFFER_FULL_ERROR, suppressTracing } from '@sentry/core';\n\nexport interface CloudflareTransportOptions extends BaseTransportOptions {\n /** Custom fetch function to use. This allows usage of things like Workers VPC */\n fetch?: typeof fetch;\n /** Fetch API init parameters. */\n fetchOptions?: RequestInit;\n}\n\nconst DEFAULT_TRANSPORT_BUFFER_SIZE = 30;\n\n/**\n * This is a modified promise buffer that collects tasks until drain is called.\n * We need this in the edge runtime because edge function invocations may not share I/O objects, like fetch requests\n * and responses, and the normal PromiseBuffer inherently buffers stuff inbetween incoming requests.\n *\n * A limitation we need to be aware of is that DEFAULT_TRANSPORT_BUFFER_SIZE is the maximum amount of payloads the\n * SDK can send for a given edge function invocation.\n */\nexport class IsolatedPromiseBuffer {\n // We just have this field because the promise buffer interface requires it.\n // If we ever remove it from the interface we should also remove it here.\n public $: Array<PromiseLike<TransportMakeRequestResponse>>;\n\n private _taskProducers: (() => PromiseLike<TransportMakeRequestResponse>)[];\n\n private readonly _bufferSize: number;\n\n public constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) {\n this.$ = [];\n this._taskProducers = [];\n this._bufferSize = _bufferSize;\n }\n\n /**\n * @inheritdoc\n */\n public add(taskProducer: () => PromiseLike<TransportMakeRequestResponse>): PromiseLike<TransportMakeRequestResponse> {\n if (this._taskProducers.length >= this._bufferSize) {\n return Promise.reject(SENTRY_BUFFER_FULL_ERROR);\n }\n\n this._taskProducers.push(taskProducer);\n return Promise.resolve({});\n }\n\n /**\n * @inheritdoc\n */\n public drain(timeout?: number): PromiseLike<boolean> {\n const oldTaskProducers = [...this._taskProducers];\n this._taskProducers = [];\n\n return new Promise(resolve => {\n const timer = setTimeout(() => {\n if (timeout && timeout > 0) {\n resolve(false);\n }\n }, timeout);\n\n // This cannot reject\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.all(\n oldTaskProducers.map(taskProducer =>\n taskProducer().then(null, () => {\n // catch all failed requests\n }),\n ),\n ).then(() => {\n // resolve to true if all fetch requests settled\n clearTimeout(timer);\n resolve(true);\n });\n });\n }\n}\n\n/**\n * Creates a Transport that uses the native fetch API to send events to Sentry.\n */\nexport function makeCloudflareTransport(options: CloudflareTransportOptions): Transport {\n function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {\n const requestOptions: RequestInit = {\n body: request.body,\n method: 'POST',\n headers: options.headers,\n ...options.fetchOptions,\n };\n\n return suppressTracing(() => {\n return (options.fetch ?? fetch)(options.url, requestOptions).then(async response => {\n // Consume the response body to satisfy Cloudflare Workers' fetch requirements.\n // The runtime requires all fetch response bodies to be read or explicitly canceled\n // to prevent connection stalls and potential deadlocks. We read the body as text\n // even though we don't use the content, as Sentry's response information is in the headers.\n // See: https://github.com/getsentry/sentry-javascript/issues/18534\n try {\n await response.text();\n } catch {\n // no-op\n }\n\n return {\n statusCode: response.status,\n headers: {\n 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),\n 'retry-after': response.headers.get('Retry-After'),\n },\n };\n });\n });\n }\n\n return createTransport(options, makeRequest, new IsolatedPromiseBuffer(options.bufferSize));\n}\n"],"names":["SENTRY_BUFFER_FULL_ERROR","suppressTracing","createTransport"],"mappings":";;;;AAUA,MAAM,6BAAA,GAAgC,EAAE;;AAExC;AACA;AACA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KAAK,CAAC;AAC3B,QAAQ,OAAO,CAAC,IAAI,CAAC;AACrB,MAAM,CAAC,CAAC;AACR,IAAI,CAAC,CAAC;AACN,EAAE;AACF;;AAEA;AACA;AACA;AACO,SAAS,uBAAuB,CAAC,OAAO,EAAyC;AACxF,EAAE,SAAS,WAAW,CAAC,OAAO,EAA+D;AAC7F,IAAI,MAAM,cAAc,GAAgB;AACxC,MAAM,IAAI,EAAE,OAAO,CAAC,IAAI;AACxB,MAAM,MAAM,EAAE,MAAM;AACpB,MAAM,OAAO,EAAE,OAAO,CAAC,OAAO;AAC9B,MAAM,GAAG,OAAO,CAAC,YAAY;AAC7B,KAAK;;AAEL,IAAI,OAAOC,oBAAe,CAAC,MAAM;AACjC,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,YAAY;AAC1F;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI;AACZ,UAAU,MAAM,QAAQ,CAAC,IAAI,EAAE;AAC/B,QAAQ,EAAE,MAAM;AAChB;AACA,QAAQ;;AAER,QAAQ,OAAO;AACf,UAAU,UAAU,EAAE,QAAQ,CAAC,MAAM;AACrC,UAAU,OAAO,EAAE;AACnB,YAAY,sBAAsB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;AAChF,YAAY,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC9D,WAAW;AACX,SAAS;AACT,MAAM,CAAC,CAAC;AACR,IAAI,CAAC,CAAC;AACN,EAAE;;AAEF,EAAE,OAAOC,oBAAe,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC7F;;;;;"}
1
+ {"version":3,"file":"transport.js","sources":["../../src/transport.ts"],"sourcesContent":["import type { BaseTransportOptions, Transport, TransportMakeRequestResponse, TransportRequest } from '@sentry/core';\nimport { createTransport, SENTRY_BUFFER_FULL_ERROR, suppressTracing } from '@sentry/core';\n\nexport interface CloudflareTransportOptions extends BaseTransportOptions {\n /** Custom fetch function to use. This allows usage of things like Workers VPC */\n fetch?: typeof fetch;\n /** Fetch API init parameters. */\n fetchOptions?: RequestInit;\n}\n\nconst DEFAULT_TRANSPORT_BUFFER_SIZE = 30;\n\n/**\n * This is a modified promise buffer that collects tasks until drain is called.\n * We need this in the edge runtime because edge function invocations may not share I/O objects, like fetch requests\n * and responses, and the normal PromiseBuffer inherently buffers stuff inbetween incoming requests.\n *\n * A limitation we need to be aware of is that DEFAULT_TRANSPORT_BUFFER_SIZE is the maximum amount of payloads the\n * SDK can send for a given edge function invocation.\n */\nexport class IsolatedPromiseBuffer {\n // We just have this field because the promise buffer interface requires it.\n // If we ever remove it from the interface we should also remove it here.\n public $: Array<PromiseLike<TransportMakeRequestResponse>>;\n\n private _taskProducers: (() => PromiseLike<TransportMakeRequestResponse>)[];\n\n private readonly _bufferSize: number;\n\n public constructor(_bufferSize = DEFAULT_TRANSPORT_BUFFER_SIZE) {\n this.$ = [];\n this._taskProducers = [];\n this._bufferSize = _bufferSize;\n }\n\n /**\n * @inheritdoc\n */\n public add(taskProducer: () => PromiseLike<TransportMakeRequestResponse>): PromiseLike<TransportMakeRequestResponse> {\n if (this._taskProducers.length >= this._bufferSize) {\n return Promise.reject(SENTRY_BUFFER_FULL_ERROR);\n }\n\n this._taskProducers.push(taskProducer);\n return Promise.resolve({});\n }\n\n /**\n * @inheritdoc\n */\n public drain(timeout?: number): PromiseLike<boolean> {\n const oldTaskProducers = [...this._taskProducers];\n this._taskProducers = [];\n\n return new Promise(resolve => {\n const timer = setTimeout(() => {\n if (timeout && timeout > 0) {\n resolve(false);\n }\n }, timeout);\n\n // This cannot reject\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.all(\n oldTaskProducers.map(taskProducer =>\n taskProducer().then(null, () => {\n // catch all failed requests\n }),\n ),\n ).then(() => {\n // resolve to true if all fetch requests settled\n clearTimeout(timer);\n resolve(true);\n });\n });\n }\n}\n\n/**\n * Creates a Transport that uses the native fetch API to send events to Sentry.\n */\nexport function makeCloudflareTransport(options: CloudflareTransportOptions): Transport {\n function makeRequest(request: TransportRequest): PromiseLike<TransportMakeRequestResponse> {\n const requestOptions: RequestInit = {\n body: request.body,\n method: 'POST',\n headers: options.headers,\n ...options.fetchOptions,\n };\n\n return suppressTracing(() => {\n return (options.fetch ?? fetch)(options.url, requestOptions).then(async response => {\n // Consume the response body to satisfy Cloudflare Workers' fetch requirements.\n // The runtime requires all fetch response bodies to be read or explicitly canceled\n // to prevent connection stalls and potential deadlocks. We read the body as text\n // even though we don't use the content, as Sentry's response information is in the headers.\n // See: https://github.com/getsentry/sentry-javascript/issues/18534\n try {\n await response.text();\n } catch {\n // no-op\n }\n\n return {\n statusCode: response.status,\n headers: {\n 'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),\n 'retry-after': response.headers.get('Retry-After'),\n },\n };\n });\n });\n }\n\n return createTransport(options, makeRequest, new IsolatedPromiseBuffer(options.bufferSize));\n}\n"],"names":["SENTRY_BUFFER_FULL_ERROR","suppressTracing","createTransport"],"mappings":";;;;AAUA,MAAM,6BAAA,GAAgC,EAAA;AAU/B,MAAM,qBAAA,CAAsB;AAAA,EAS1B,WAAA,CAAY,cAAc,6BAAA,EAA+B;AAC9D,IAAA,IAAA,CAAK,IAAI,EAAC;AACV,IAAA,IAAA,CAAK,iBAAiB,EAAC;AACvB,IAAA,IAAA,CAAK,WAAA,GAAc,WAAA;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKO,IAAI,YAAA,EAA0G;AACnH,IAAA,IAAI,IAAA,CAAK,cAAA,CAAe,MAAA,IAAU,IAAA,CAAK,WAAA,EAAa;AAClD,MAAA,OAAO,OAAA,CAAQ,OAAOA,6BAAwB,CAAA;AAAA,IAChD;AAEA,IAAA,IAAA,CAAK,cAAA,CAA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