@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.
- package/build/cjs/async.js +4 -30
- package/build/cjs/async.js.map +1 -1
- package/build/cjs/client.js +31 -58
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/d1.js +26 -80
- package/build/cjs/d1.js.map +1 -1
- package/build/cjs/debug-build.js +0 -5
- package/build/cjs/debug-build.js.map +1 -1
- package/build/cjs/durableobject.js +44 -131
- package/build/cjs/durableobject.js.map +1 -1
- package/build/cjs/flush.js +47 -34
- package/build/cjs/flush.js.map +1 -1
- package/build/cjs/instrument.js +7 -48
- package/build/cjs/instrument.js.map +1 -1
- package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js +9 -34
- package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
- package/build/cjs/instrumentations/instrumentDurableObjectStorage.js +20 -54
- package/build/cjs/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
- package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js +12 -66
- package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentEmail.js +21 -43
- package/build/cjs/instrumentations/worker/instrumentEmail.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentEnv.js +12 -42
- package/build/cjs/instrumentations/worker/instrumentEnv.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentFetch.js +20 -34
- package/build/cjs/instrumentations/worker/instrumentFetch.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentFetcher.js +5 -19
- package/build/cjs/instrumentations/worker/instrumentFetcher.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentQueue.js +30 -62
- package/build/cjs/instrumentations/worker/instrumentQueue.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentQueueProducer.js +31 -57
- package/build/cjs/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentScheduled.js +25 -54
- package/build/cjs/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/cjs/instrumentations/worker/instrumentTail.js +16 -43
- package/build/cjs/instrumentations/worker/instrumentTail.js.map +1 -1
- package/build/cjs/integrations/fetch.js +24 -56
- package/build/cjs/integrations/fetch.js.map +1 -1
- package/build/cjs/integrations/hono.js +7 -38
- package/build/cjs/integrations/hono.js.map +1 -1
- package/build/cjs/integrations/httpServer.js +6 -39
- package/build/cjs/integrations/httpServer.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai.js +3 -31
- package/build/cjs/integrations/tracing/vercelai.js.map +1 -1
- package/build/cjs/opentelemetry/tracer.js +17 -45
- package/build/cjs/opentelemetry/tracer.js.map +1 -1
- package/build/cjs/options.js +10 -46
- package/build/cjs/options.js.map +1 -1
- package/build/cjs/pages-plugin.js +9 -42
- package/build/cjs/pages-plugin.js.map +1 -1
- package/build/cjs/request.js +21 -67
- package/build/cjs/request.js.map +1 -1
- package/build/cjs/scope-utils.js +4 -15
- package/build/cjs/scope-utils.js.map +1 -1
- package/build/cjs/sdk.js +8 -25
- package/build/cjs/sdk.js.map +1 -1
- package/build/cjs/transport.js +14 -48
- package/build/cjs/transport.js.map +1 -1
- package/build/cjs/utils/instrumentContext.js +16 -52
- package/build/cjs/utils/instrumentContext.js.map +1 -1
- package/build/cjs/utils/isBinding.js +3 -23
- package/build/cjs/utils/isBinding.js.map +1 -1
- package/build/cjs/utils/isCloudflareClass.js +2 -8
- package/build/cjs/utils/isCloudflareClass.js.map +1 -1
- package/build/cjs/utils/rpcMeta.js +8 -32
- package/build/cjs/utils/rpcMeta.js.map +1 -1
- package/build/cjs/utils/rpcOptions.js +9 -32
- package/build/cjs/utils/rpcOptions.js.map +1 -1
- package/build/cjs/utils/streaming.js +3 -29
- package/build/cjs/utils/streaming.js.map +1 -1
- package/build/cjs/utils/traceLinks.js +8 -33
- package/build/cjs/utils/traceLinks.js.map +1 -1
- package/build/cjs/vendor/stacktrace.js +6 -27
- package/build/cjs/vendor/stacktrace.js.map +1 -1
- package/build/cjs/withSentry.js +16 -47
- package/build/cjs/withSentry.js.map +1 -1
- package/build/cjs/workflows.js +40 -100
- package/build/cjs/workflows.js.map +1 -1
- package/build/cjs/wrapMethodWithSentry.js +110 -167
- package/build/cjs/wrapMethodWithSentry.js.map +1 -1
- package/build/esm/async.js +4 -30
- package/build/esm/async.js.map +1 -1
- package/build/esm/client.js +31 -58
- package/build/esm/client.js.map +1 -1
- package/build/esm/d1.js +26 -80
- package/build/esm/d1.js.map +1 -1
- package/build/esm/debug-build.js +0 -5
- package/build/esm/debug-build.js.map +1 -1
- package/build/esm/durableobject.js +44 -131
- package/build/esm/durableobject.js.map +1 -1
- package/build/esm/flush.js +47 -34
- package/build/esm/flush.js.map +1 -1
- package/build/esm/instrument.js +7 -48
- package/build/esm/instrument.js.map +1 -1
- package/build/esm/instrumentations/instrumentDurableObjectNamespace.js +9 -34
- package/build/esm/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
- package/build/esm/instrumentations/instrumentDurableObjectStorage.js +20 -54
- package/build/esm/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
- package/build/esm/instrumentations/instrumentWorkerEntrypoint.js +12 -66
- package/build/esm/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentEmail.js +21 -43
- package/build/esm/instrumentations/worker/instrumentEmail.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentEnv.js +12 -42
- package/build/esm/instrumentations/worker/instrumentEnv.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentFetch.js +20 -34
- package/build/esm/instrumentations/worker/instrumentFetch.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentFetcher.js +5 -19
- package/build/esm/instrumentations/worker/instrumentFetcher.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentQueue.js +30 -62
- package/build/esm/instrumentations/worker/instrumentQueue.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentQueueProducer.js +31 -57
- package/build/esm/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentScheduled.js +25 -54
- package/build/esm/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/esm/instrumentations/worker/instrumentTail.js +16 -43
- package/build/esm/instrumentations/worker/instrumentTail.js.map +1 -1
- package/build/esm/integrations/fetch.js +24 -56
- package/build/esm/integrations/fetch.js.map +1 -1
- package/build/esm/integrations/hono.js +7 -38
- package/build/esm/integrations/hono.js.map +1 -1
- package/build/esm/integrations/httpServer.js +6 -39
- package/build/esm/integrations/httpServer.js.map +1 -1
- package/build/esm/integrations/tracing/vercelai.js +3 -31
- package/build/esm/integrations/tracing/vercelai.js.map +1 -1
- package/build/esm/opentelemetry/tracer.js +17 -45
- package/build/esm/opentelemetry/tracer.js.map +1 -1
- package/build/esm/options.js +10 -46
- package/build/esm/options.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/pages-plugin.js +9 -42
- package/build/esm/pages-plugin.js.map +1 -1
- package/build/esm/request.js +21 -67
- package/build/esm/request.js.map +1 -1
- package/build/esm/scope-utils.js +4 -15
- package/build/esm/scope-utils.js.map +1 -1
- package/build/esm/sdk.js +8 -25
- package/build/esm/sdk.js.map +1 -1
- package/build/esm/transport.js +14 -48
- package/build/esm/transport.js.map +1 -1
- package/build/esm/utils/instrumentContext.js +16 -52
- package/build/esm/utils/instrumentContext.js.map +1 -1
- package/build/esm/utils/isBinding.js +3 -23
- package/build/esm/utils/isBinding.js.map +1 -1
- package/build/esm/utils/isCloudflareClass.js +2 -8
- package/build/esm/utils/isCloudflareClass.js.map +1 -1
- package/build/esm/utils/rpcMeta.js +8 -32
- package/build/esm/utils/rpcMeta.js.map +1 -1
- package/build/esm/utils/rpcOptions.js +9 -32
- package/build/esm/utils/rpcOptions.js.map +1 -1
- package/build/esm/utils/streaming.js +3 -29
- package/build/esm/utils/streaming.js.map +1 -1
- package/build/esm/utils/traceLinks.js +8 -33
- package/build/esm/utils/traceLinks.js.map +1 -1
- package/build/esm/vendor/stacktrace.js +6 -27
- package/build/esm/vendor/stacktrace.js.map +1 -1
- package/build/esm/withSentry.js +16 -47
- package/build/esm/withSentry.js.map +1 -1
- package/build/esm/workflows.js +40 -100
- package/build/esm/workflows.js.map +1 -1
- package/build/esm/wrapMethodWithSentry.js +110 -167
- package/build/esm/wrapMethodWithSentry.js.map +1 -1
- package/build/types/client.d.ts.map +1 -1
- package/build/types/flush.d.ts.map +1 -1
- package/build/types/instrumentations/worker/instrumentFetch.d.ts.map +1 -1
- package/build/types/pages-plugin.d.ts.map +1 -1
- package/package.json +2 -2
package/build/cjs/request.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
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[
|
|
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[
|
|
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
|
-
|
|
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:
|
|
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(
|
|
59
|
+
{ sentryTrace: request.headers.get("sentry-trace") || "", baggage: request.headers.get("baggage") },
|
|
79
60
|
() => {
|
|
80
|
-
|
|
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:
|
|
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(
|
|
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
|
}
|
package/build/cjs/request.js.map
CHANGED
|
@@ -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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O;AACpC,eAAe,CAAC;AAChB,YAAY,EAAE,MAAM;AACpB,cAAc,IAAI,CAAC,GAAG,EAAE;AACxB,cAAc,SAAS,GAAGA,qBAAe,CAAC,MAAM,CAAC,CAAC;AAClD,cAAc,OAAO,GAAG;AACxB,YAAY;AACZ,UAAU;;AAEV;AACA,UAAU,IAAI,CAAC,GAAG,EAAE;;AAEpB;AACA;AACA;AACA,UAAU,IAAI,GAAG,CAAC,MAAA,KAAW,GAAG,EAAE;AAClC,YAAY,SAAS,GAAG,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,UAAU,OAAO;AACjB,YAAY,SAAS,GAAGA,qBAAe,CAAC,MAAM,CAAC,CAAC;AAChD,UAAU;AACV,UAAU,OAAO,GAAG;AACpB,QAAQ,CAAC,CAAC;AACV,MAAM,CAAC;AACP,KAAK;AACL,EAAE,CAAC,CAAC;AACJ;;;;"}
|
|
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":";;;;;;;;;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,UAAU,CAAA,GAAIC,qCAAgC,SAAA,EAAW,QAAA,EAAU,wBAAwB,OAAO,CAAA;AAE/G,IAAA,MAAM,aAAA,GAAgB,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,gBAAgB,CAAA;AAC1D,IAAA,IAAI,aAAA,EAAe;AACjB,MAAA,UAAA,CAAW,wBAAwB,CAAA,GAAI,QAAA,CAAS,aAAA,EAAe,EAAE,CAAA;AAAA,IACnE;AAEA,IAAA,MAAM,eAAA,GAAkB,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,YAAY,CAAA;AACxD,IAAA,IAAI,eAAA,EAAiB;AACnB,MAAA,UAAA,CAAW,qBAAqB,CAAA,GAAI,eAAA;AAAA,IACtC;AAEA,IAAA,MAAA,CAAO,MAAA;AAAA,MACL,UAAA;AAAA,MACAC,gCAAA;AAAA,QACEC,0BAAA,CAAsB,QAAQ,OAAO,CAAA;AAAA,QACrCC,cAAA,EAAU,E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,GAAA,CAAI,MAAA;AAAA,gBACZ,YAAY,GAAA,CAAI,UAAA;AAAA,gBAChB,SAAS,GAAA,CAAI;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,CAAC,CAAA;AACH;;;;"}
|
package/build/cjs/scope-utils.js
CHANGED
|
@@ -2,27 +2,16 @@ 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(
|
|
10
|
-
|
|
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(
|
|
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":";;;;
|
|
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
|
-
...
|
|
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 ?
|
|
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 ===
|
|
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 ===
|
|
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;
|
package/build/cjs/sdk.js.map
CHANGED
|
@@ -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":";;;;;;;;;;;;
|
|
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;;;;;"}
|
package/build/cjs/transport.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
55
|
-
taskProducer().then(null, () => {
|
|
56
|
-
|
|
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:
|
|
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
|
-
|
|
97
|
-
|
|
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,
|
|
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,CAAe,KAAK,YAAY,CAAA;AACrC,IAAA,OAAO,OAAA,CAAQ,OAAA,CAAQ,EAAE,C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