@sentry/cloudflare 9.14.0 → 9.16.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 -1
- package/build/cjs/async.js.map +1 -1
- package/build/cjs/client.js.map +1 -1
- package/build/cjs/d1.js.map +1 -1
- package/build/cjs/durableobject.js +213 -0
- package/build/cjs/durableobject.js.map +1 -0
- package/build/cjs/handler.js +56 -66
- package/build/cjs/handler.js.map +1 -1
- package/build/cjs/index.js +6 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/instrument.js +27 -0
- package/build/cjs/instrument.js.map +1 -0
- package/build/cjs/integrations/fetch.js.map +1 -1
- package/build/cjs/logs/exports.js +213 -0
- package/build/cjs/logs/exports.js.map +1 -0
- package/build/cjs/options.js +23 -0
- package/build/cjs/options.js.map +1 -0
- package/build/cjs/request.js +12 -0
- package/build/cjs/request.js.map +1 -1
- package/build/cjs/scope-utils.js.map +1 -1
- package/build/cjs/sdk.js +1 -0
- package/build/cjs/sdk.js.map +1 -1
- package/build/cjs/transport.js.map +1 -1
- package/build/cjs/vendor/stacktrace.js +0 -4
- package/build/cjs/vendor/stacktrace.js.map +1 -1
- package/build/esm/async.js +4 -1
- package/build/esm/async.js.map +1 -1
- package/build/esm/client.js.map +1 -1
- package/build/esm/d1.js.map +1 -1
- package/build/esm/durableobject.js +211 -0
- package/build/esm/durableobject.js.map +1 -0
- package/build/esm/handler.js +56 -66
- package/build/esm/handler.js.map +1 -1
- package/build/esm/index.js +4 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/instrument.js +24 -0
- package/build/esm/instrument.js.map +1 -0
- package/build/esm/integrations/fetch.js.map +1 -1
- package/build/esm/logs/exports.js +206 -0
- package/build/esm/logs/exports.js.map +1 -0
- package/build/esm/options.js +21 -0
- package/build/esm/options.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/request.js +13 -1
- package/build/esm/request.js.map +1 -1
- package/build/esm/scope-utils.js.map +1 -1
- package/build/esm/sdk.js +1 -0
- package/build/esm/sdk.js.map +1 -1
- package/build/esm/transport.js.map +1 -1
- package/build/esm/vendor/stacktrace.js +0 -4
- package/build/esm/vendor/stacktrace.js.map +1 -1
- package/build/types/async.d.ts.map +1 -1
- package/build/types/client.d.ts.map +1 -1
- package/build/types/durableobject.d.ts +38 -0
- package/build/types/durableobject.d.ts.map +1 -0
- package/build/types/handler.d.ts +2 -7
- package/build/types/handler.d.ts.map +1 -1
- package/build/types/index.d.ts +3 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrument.d.ts +9 -0
- package/build/types/instrument.d.ts.map +1 -0
- package/build/types/logs/exports.d.ts +169 -0
- package/build/types/logs/exports.d.ts.map +1 -0
- package/build/types/options.d.ts +12 -0
- package/build/types/options.d.ts.map +1 -0
- package/build/types/request.d.ts.map +1 -1
- package/build/types/scope-utils.d.ts.map +1 -1
- package/build/types/sdk.d.ts.map +1 -1
- package/build/types/vendor/stacktrace.d.ts.map +1 -1
- package/build/types-ts3.8/durableobject.d.ts +38 -0
- package/build/types-ts3.8/handler.d.ts +2 -7
- package/build/types-ts3.8/index.d.ts +4 -1
- package/build/types-ts3.8/instrument.d.ts +9 -0
- package/build/types-ts3.8/logs/exports.d.ts +169 -0
- package/build/types-ts3.8/options.d.ts +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { getClient, withScope, withIsolationScope, captureException, flush, SEMANTIC_ATTRIBUTE_SENTRY_OP, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
|
|
2
|
+
import { setAsyncLocalStorageAsyncContextStrategy } from './async.js';
|
|
3
|
+
import { isInstrumented, markAsInstrumented } from './instrument.js';
|
|
4
|
+
import { getFinalOptions } from './options.js';
|
|
5
|
+
import { wrapRequestHandler } from './request.js';
|
|
6
|
+
import { init } from './sdk.js';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
function wrapMethodWithSentry(
|
|
12
|
+
wrapperOptions,
|
|
13
|
+
handler,
|
|
14
|
+
callback,
|
|
15
|
+
) {
|
|
16
|
+
if (isInstrumented(handler)) {
|
|
17
|
+
return handler;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
markAsInstrumented(handler);
|
|
21
|
+
|
|
22
|
+
return new Proxy(handler, {
|
|
23
|
+
apply(target, thisArg, args) {
|
|
24
|
+
const currentClient = getClient();
|
|
25
|
+
// if a client is already set, use withScope, otherwise use withIsolationScope
|
|
26
|
+
const sentryWithScope = currentClient ? withScope : withIsolationScope;
|
|
27
|
+
return sentryWithScope(async scope => {
|
|
28
|
+
// In certain situations, the passed context can become undefined.
|
|
29
|
+
// For example, for Astro while prerendering pages at build time.
|
|
30
|
+
// see: https://github.com/getsentry/sentry-javascript/issues/13217
|
|
31
|
+
const context = wrapperOptions.context ;
|
|
32
|
+
|
|
33
|
+
const currentClient = scope.getClient();
|
|
34
|
+
if (!currentClient) {
|
|
35
|
+
const client = init(wrapperOptions.options);
|
|
36
|
+
scope.setClient(client);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!wrapperOptions.spanName) {
|
|
40
|
+
try {
|
|
41
|
+
if (callback) {
|
|
42
|
+
callback(...args);
|
|
43
|
+
}
|
|
44
|
+
return await Reflect.apply(target, thisArg, args);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
captureException(e, {
|
|
47
|
+
mechanism: {
|
|
48
|
+
type: 'cloudflare_durableobject',
|
|
49
|
+
handled: false,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
throw e;
|
|
53
|
+
} finally {
|
|
54
|
+
context?.waitUntil(flush(2000));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const attributes = wrapperOptions.spanOp
|
|
59
|
+
? {
|
|
60
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,
|
|
61
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare_durableobjects',
|
|
62
|
+
}
|
|
63
|
+
: {};
|
|
64
|
+
|
|
65
|
+
// Only create these spans if they have a parent span.
|
|
66
|
+
return startSpan({ name: wrapperOptions.spanName, attributes, onlyIfParent: true }, async () => {
|
|
67
|
+
try {
|
|
68
|
+
return await Reflect.apply(target, thisArg, args);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
captureException(e, {
|
|
71
|
+
mechanism: {
|
|
72
|
+
type: 'cloudflare_durableobject',
|
|
73
|
+
handled: false,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
throw e;
|
|
77
|
+
} finally {
|
|
78
|
+
context?.waitUntil(flush(2000));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Instruments a Durable Object class to capture errors and performance data.
|
|
88
|
+
*
|
|
89
|
+
* Instruments the following methods:
|
|
90
|
+
* - fetch
|
|
91
|
+
* - alarm
|
|
92
|
+
* - webSocketMessage
|
|
93
|
+
* - webSocketClose
|
|
94
|
+
* - webSocketError
|
|
95
|
+
*
|
|
96
|
+
* as well as any other public RPC methods on the Durable Object instance.
|
|
97
|
+
*
|
|
98
|
+
* @param optionsCallback Function that returns the options for the SDK initialization.
|
|
99
|
+
* @param DurableObjectClass The Durable Object class to instrument.
|
|
100
|
+
* @returns The instrumented Durable Object class.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* class MyDurableObjectBase extends DurableObject {
|
|
105
|
+
* constructor(ctx: DurableObjectState, env: Env) {
|
|
106
|
+
* super(ctx, env);
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* export const MyDurableObject = instrumentDurableObjectWithSentry(
|
|
111
|
+
* env => ({
|
|
112
|
+
* dsn: env.SENTRY_DSN,
|
|
113
|
+
* tracesSampleRate: 1.0,
|
|
114
|
+
* }),
|
|
115
|
+
* MyDurableObjectBase,
|
|
116
|
+
* );
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function instrumentDurableObjectWithSentry(
|
|
120
|
+
optionsCallback,
|
|
121
|
+
DurableObjectClass,
|
|
122
|
+
) {
|
|
123
|
+
return new Proxy(DurableObjectClass, {
|
|
124
|
+
construct(target, [context, env]) {
|
|
125
|
+
setAsyncLocalStorageAsyncContextStrategy();
|
|
126
|
+
|
|
127
|
+
const options = getFinalOptions(optionsCallback(env), env);
|
|
128
|
+
|
|
129
|
+
const obj = new target(context, env);
|
|
130
|
+
|
|
131
|
+
// These are the methods that are available on a Durable Object
|
|
132
|
+
// ref: https://developers.cloudflare.com/durable-objects/api/base/
|
|
133
|
+
// obj.alarm
|
|
134
|
+
// obj.fetch
|
|
135
|
+
// obj.webSocketError
|
|
136
|
+
// obj.webSocketClose
|
|
137
|
+
// obj.webSocketMessage
|
|
138
|
+
|
|
139
|
+
// Any other public methods on the Durable Object instance are RPC calls.
|
|
140
|
+
|
|
141
|
+
if (obj.fetch && typeof obj.fetch === 'function' && !isInstrumented(obj.fetch)) {
|
|
142
|
+
obj.fetch = new Proxy(obj.fetch, {
|
|
143
|
+
apply(target, thisArg, args) {
|
|
144
|
+
return wrapRequestHandler({ options, request: args[0], context }, () =>
|
|
145
|
+
Reflect.apply(target, thisArg, args),
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
markAsInstrumented(obj.fetch);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (obj.alarm && typeof obj.alarm === 'function') {
|
|
154
|
+
obj.alarm = wrapMethodWithSentry({ options, context, spanName: 'alarm' }, obj.alarm);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {
|
|
158
|
+
obj.webSocketMessage = wrapMethodWithSentry(
|
|
159
|
+
{ options, context, spanName: 'webSocketMessage' },
|
|
160
|
+
obj.webSocketMessage,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {
|
|
165
|
+
obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (obj.webSocketError && typeof obj.webSocketError === 'function') {
|
|
169
|
+
obj.webSocketError = wrapMethodWithSentry(
|
|
170
|
+
{ options, context, spanName: 'webSocketError' },
|
|
171
|
+
obj.webSocketError,
|
|
172
|
+
(_, error) =>
|
|
173
|
+
captureException(error, {
|
|
174
|
+
mechanism: {
|
|
175
|
+
type: 'cloudflare_durableobject_websocket',
|
|
176
|
+
handled: false,
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
for (const method of Object.getOwnPropertyNames(obj)) {
|
|
183
|
+
if (
|
|
184
|
+
method === 'fetch' ||
|
|
185
|
+
method === 'alarm' ||
|
|
186
|
+
method === 'webSocketError' ||
|
|
187
|
+
method === 'webSocketClose' ||
|
|
188
|
+
method === 'webSocketMessage'
|
|
189
|
+
) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
194
|
+
const value = (obj )[method] ;
|
|
195
|
+
if (typeof value === 'function') {
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
197
|
+
(obj )[method] = wrapMethodWithSentry(
|
|
198
|
+
{ options, context, spanName: method, spanOp: 'rpc' },
|
|
199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
+
value ,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return obj;
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { instrumentDurableObjectWithSentry };
|
|
211
|
+
//# sourceMappingURL=durableobject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durableobject.js","sources":["../../src/durableobject.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\nimport {\n captureException,\n flush,\n getClient,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n startSpan,\n withIsolationScope,\n withScope,\n} from '@sentry/core';\nimport type { DurableObject } from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { isInstrumented, markAsInstrumented } from './instrument';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { init } from './sdk';\n\ntype MethodWrapperOptions = {\n spanName?: string;\n spanOp?: string;\n options: CloudflareOptions;\n context: ExecutionContext | DurableObjectState;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapMethodWithSentry<T extends (...args: any[]) => any>(\n wrapperOptions: MethodWrapperOptions,\n handler: T,\n callback?: (...args: Parameters<T>) => void,\n): T {\n if (isInstrumented(handler)) {\n return handler;\n }\n\n markAsInstrumented(handler);\n\n return new Proxy(handler, {\n apply(target, thisArg, args: Parameters<T>) {\n const currentClient = getClient();\n // if a client is already set, use withScope, otherwise use withIsolationScope\n const sentryWithScope = currentClient ? withScope : withIsolationScope;\n return sentryWithScope(async scope => {\n // In certain situations, the passed context can become undefined.\n // For example, for Astro while prerendering pages at build time.\n // see: https://github.com/getsentry/sentry-javascript/issues/13217\n const context = wrapperOptions.context as ExecutionContext | undefined;\n\n const currentClient = scope.getClient();\n if (!currentClient) {\n const client = init(wrapperOptions.options);\n scope.setClient(client);\n }\n\n if (!wrapperOptions.spanName) {\n try {\n if (callback) {\n callback(...args);\n }\n return await Reflect.apply(target, thisArg, args);\n } catch (e) {\n captureException(e, {\n mechanism: {\n type: 'cloudflare_durableobject',\n handled: false,\n },\n });\n throw e;\n } finally {\n context?.waitUntil(flush(2000));\n }\n }\n\n const attributes = wrapperOptions.spanOp\n ? {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare_durableobjects',\n }\n : {};\n\n // Only create these spans if they have a parent span.\n return startSpan({ name: wrapperOptions.spanName, attributes, onlyIfParent: true }, async () => {\n try {\n return await Reflect.apply(target, thisArg, args);\n } catch (e) {\n captureException(e, {\n mechanism: {\n type: 'cloudflare_durableobject',\n handled: false,\n },\n });\n throw e;\n } finally {\n context?.waitUntil(flush(2000));\n }\n });\n });\n },\n });\n}\n\n/**\n * Instruments a Durable Object class to capture errors and performance data.\n *\n * Instruments the following methods:\n * - fetch\n * - alarm\n * - webSocketMessage\n * - webSocketClose\n * - webSocketError\n *\n * as well as any other public RPC methods on the Durable Object instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param DurableObjectClass The Durable Object class to instrument.\n * @returns The instrumented Durable Object class.\n *\n * @example\n * ```ts\n * class MyDurableObjectBase extends DurableObject {\n * constructor(ctx: DurableObjectState, env: Env) {\n * super(ctx, env);\n * }\n * }\n *\n * export const MyDurableObject = instrumentDurableObjectWithSentry(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyDurableObjectBase,\n * );\n * ```\n */\nexport function instrumentDurableObjectWithSentry<E, T extends DurableObject<E>>(\n optionsCallback: (env: E) => CloudflareOptions,\n DurableObjectClass: new (state: DurableObjectState, env: E) => T,\n): new (state: DurableObjectState, env: E) => T {\n return new Proxy(DurableObjectClass, {\n construct(target, [context, env]) {\n setAsyncLocalStorageAsyncContextStrategy();\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n const obj = new target(context, env);\n\n // These are the methods that are available on a Durable Object\n // ref: https://developers.cloudflare.com/durable-objects/api/base/\n // obj.alarm\n // obj.fetch\n // obj.webSocketError\n // obj.webSocketClose\n // obj.webSocketMessage\n\n // Any other public methods on the Durable Object instance are RPC calls.\n\n if (obj.fetch && typeof obj.fetch === 'function' && !isInstrumented(obj.fetch)) {\n obj.fetch = new Proxy(obj.fetch, {\n apply(target, thisArg, args) {\n return wrapRequestHandler({ options, request: args[0], context }, () =>\n Reflect.apply(target, thisArg, args),\n );\n },\n });\n\n markAsInstrumented(obj.fetch);\n }\n\n if (obj.alarm && typeof obj.alarm === 'function') {\n obj.alarm = wrapMethodWithSentry({ options, context, spanName: 'alarm' }, obj.alarm);\n }\n\n if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {\n obj.webSocketMessage = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketMessage' },\n obj.webSocketMessage,\n );\n }\n\n if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {\n obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose);\n }\n\n if (obj.webSocketError && typeof obj.webSocketError === 'function') {\n obj.webSocketError = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketError' },\n obj.webSocketError,\n (_, error) =>\n captureException(error, {\n mechanism: {\n type: 'cloudflare_durableobject_websocket',\n handled: false,\n },\n }),\n );\n }\n\n for (const method of Object.getOwnPropertyNames(obj)) {\n if (\n method === 'fetch' ||\n method === 'alarm' ||\n method === 'webSocketError' ||\n method === 'webSocketClose' ||\n method === 'webSocketMessage'\n ) {\n continue;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const value = (obj as any)[method] as unknown;\n if (typeof value === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (obj as any)[method] = wrapMethodWithSentry(\n { options, context, spanName: method, spanOp: 'rpc' },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value as (...args: any[]) => any,\n );\n }\n }\n\n return obj;\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;AAAA;;AA0BA;AACA,SAAS,oBAAoB;AAC7B,EAAE,cAAc;AAChB,EAAE,OAAO;AACT,EAAE,QAAQ;AACV,EAAK;AACL,EAAE,IAAI,cAAc,CAAC,OAAO,CAAC,EAAE;AAC/B,IAAI,OAAO,OAAO;AAClB;;AAEA,EAAE,kBAAkB,CAAC,OAAO,CAAC;;AAE7B,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;AAC5B,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAiB;AAChD,MAAM,MAAM,aAAA,GAAgB,SAAS,EAAE;AACvC;AACA,MAAM,MAAM,eAAgB,GAAE,gBAAgB,SAAA,GAAY,kBAAkB;AAC5E,MAAM,OAAO,eAAe,CAAC,MAAM,SAAS;AAC5C;AACA;AACA;AACA,QAAQ,MAAM,OAAA,GAAU,cAAc,CAAC,OAAQ;;AAE/C,QAAQ,MAAM,aAAc,GAAE,KAAK,CAAC,SAAS,EAAE;AAC/C,QAAQ,IAAI,CAAC,aAAa,EAAE;AAC5B,UAAU,MAAM,SAAS,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;AACrD,UAAU,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;AACjC;;AAEA,QAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE;AACtC,UAAU,IAAI;AACd,YAAY,IAAI,QAAQ,EAAE;AAC1B,cAAc,QAAQ,CAAC,GAAG,IAAI,CAAC;AAC/B;AACA,YAAY,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAC7D,WAAY,CAAA,OAAO,CAAC,EAAE;AACtB,YAAY,gBAAgB,CAAC,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AACzC;AACA,UAAU,CAAC,GAAI,GAAQ,MAAM,CAAA,GAAI,oBAAoB;AACrD,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAA,EAAO;AACjE;AACA,YAAY,KAAM;AAClB,WAAW;AACX;AACA;;AAEA,MAAM,OAAO,GAAG;AAChB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
|
package/build/esm/handler.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { withIsolationScope, startSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, captureException, flush } from '@sentry/core';
|
|
2
2
|
import { setAsyncLocalStorageAsyncContextStrategy } from './async.js';
|
|
3
|
+
import { isInstrumented, markAsInstrumented } from './instrument.js';
|
|
4
|
+
import { getFinalOptions } from './options.js';
|
|
3
5
|
import { wrapRequestHandler } from './request.js';
|
|
4
6
|
import { addCloudResourceContext } from './scope-utils.js';
|
|
5
7
|
import { init } from './sdk.js';
|
|
6
8
|
|
|
7
|
-
/**
|
|
8
|
-
* Extract environment generic from exported handler.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* Wrapper for Cloudflare handlers.
|
|
13
11
|
*
|
|
@@ -19,83 +17,75 @@ import { init } from './sdk.js';
|
|
|
19
17
|
* @param handler {ExportedHandler} The handler to wrap.
|
|
20
18
|
* @returns The wrapped handler.
|
|
21
19
|
*/
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
20
|
function withSentry(
|
|
24
21
|
optionsCallback,
|
|
25
22
|
handler,
|
|
26
23
|
) {
|
|
27
24
|
setAsyncLocalStorageAsyncContextStrategy();
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
handler.fetch
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));
|
|
35
|
-
},
|
|
36
|
-
});
|
|
26
|
+
try {
|
|
27
|
+
if ('fetch' in handler && typeof handler.fetch === 'function' && !isInstrumented(handler.fetch)) {
|
|
28
|
+
handler.fetch = new Proxy(handler.fetch, {
|
|
29
|
+
apply(target, thisArg, args) {
|
|
30
|
+
const [request, env, context] = args;
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
}
|
|
32
|
+
const options = getFinalOptions(optionsCallback(env), env);
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const [event, env, context] = args;
|
|
45
|
-
return withIsolationScope(isolationScope => {
|
|
46
|
-
const options = optionsCallback(env);
|
|
47
|
-
const client = init(options);
|
|
48
|
-
isolationScope.setClient(client);
|
|
34
|
+
return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));
|
|
35
|
+
},
|
|
36
|
+
});
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
markAsInstrumented(handler.fetch);
|
|
39
|
+
}
|
|
51
40
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
'faas.time': new Date(event.scheduledTime).toISOString(),
|
|
59
|
-
'faas.trigger': 'timer',
|
|
60
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare',
|
|
61
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
async () => {
|
|
65
|
-
try {
|
|
66
|
-
return await (target.apply(thisArg, args) );
|
|
67
|
-
} catch (e) {
|
|
68
|
-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
69
|
-
throw e;
|
|
70
|
-
} finally {
|
|
71
|
-
context.waitUntil(flush(2000));
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
});
|
|
41
|
+
if ('scheduled' in handler && typeof handler.scheduled === 'function' && !isInstrumented(handler.scheduled)) {
|
|
42
|
+
handler.scheduled = new Proxy(handler.scheduled, {
|
|
43
|
+
apply(target, thisArg, args) {
|
|
44
|
+
const [event, env, context] = args;
|
|
45
|
+
return withIsolationScope(isolationScope => {
|
|
46
|
+
const options = getFinalOptions(optionsCallback(env), env);
|
|
78
47
|
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
const client = init(options);
|
|
49
|
+
isolationScope.setClient(client);
|
|
81
50
|
|
|
82
|
-
|
|
83
|
-
}
|
|
51
|
+
addCloudResourceContext(isolationScope);
|
|
84
52
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
53
|
+
return startSpan(
|
|
54
|
+
{
|
|
55
|
+
op: 'faas.cron',
|
|
56
|
+
name: `Scheduled Cron ${event.cron}`,
|
|
57
|
+
attributes: {
|
|
58
|
+
'faas.cron': event.cron,
|
|
59
|
+
'faas.time': new Date(event.scheduledTime).toISOString(),
|
|
60
|
+
'faas.trigger': 'timer',
|
|
61
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare',
|
|
62
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
async () => {
|
|
66
|
+
try {
|
|
67
|
+
return await (target.apply(thisArg, args) );
|
|
68
|
+
} catch (e) {
|
|
69
|
+
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
|
|
70
|
+
throw e;
|
|
71
|
+
} finally {
|
|
72
|
+
context.waitUntil(flush(2000));
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
92
79
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
markAsInstrumented(handler.scheduled);
|
|
81
|
+
}
|
|
82
|
+
// This is here because Miniflare sometimes cannot get instrumented
|
|
83
|
+
//
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// Do not console anything here, we don't want to spam the console with errors
|
|
98
86
|
}
|
|
87
|
+
|
|
88
|
+
return handler;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
91
|
export { withSentry };
|
package/build/esm/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../../src/handler.ts"],"sourcesContent":["import {\n captureException,\n flush,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { isInstrumented, markAsInstrumented } from './instrument';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { addCloudResourceContext } from './scope-utils';\nimport { init } from './sdk';\n\n/**\n * Wrapper for Cloudflare handlers.\n *\n * Initializes the SDK and wraps the handler with Sentry instrumentation.\n *\n * Automatically instruments the `fetch` method of the handler.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param handler {ExportedHandler} The handler to wrap.\n * @returns The wrapped handler.\n */\nexport function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostMetadata = unknown>(\n optionsCallback: (env: Env) => CloudflareOptions,\n handler: ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata>,\n): ExportedHandler<Env, QueueHandlerMessage, CfHostMetadata> {\n setAsyncLocalStorageAsyncContextStrategy();\n\n try {\n if ('fetch' in handler && typeof handler.fetch === 'function' && !isInstrumented(handler.fetch)) {\n handler.fetch = new Proxy(handler.fetch, {\n apply(target, thisArg, args: Parameters<ExportedHandlerFetchHandler<Env, CfHostMetadata>>) {\n const [request, env, context] = args;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));\n },\n });\n\n markAsInstrumented(handler.fetch);\n }\n\n if ('scheduled' in handler && typeof handler.scheduled === 'function' && !isInstrumented(handler.scheduled)) {\n handler.scheduled = new Proxy(handler.scheduled, {\n apply(target, thisArg, args: Parameters<ExportedHandlerScheduledHandler<Env>>) {\n const [event, env, context] = args;\n return withIsolationScope(isolationScope => {\n const options = getFinalOptions(optionsCallback(env), env);\n\n const client = init(options);\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.cron',\n name: `Scheduled Cron ${event.cron}`,\n attributes: {\n 'faas.cron': event.cron,\n 'faas.time': new Date(event.scheduledTime).toISOString(),\n 'faas.trigger': 'timer',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await (target.apply(thisArg, args) as ReturnType<typeof target>);\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });\n throw e;\n } finally {\n context.waitUntil(flush(2000));\n }\n },\n );\n });\n },\n });\n\n markAsInstrumented(handler.scheduled);\n }\n // This is here because Miniflare sometimes cannot get instrumented\n //\n } catch (e) {\n // Do not console anything here, we don't want to spam the console with errors\n }\n\n return handler;\n}\n"],"names":[],"mappings":";;;;;;;;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU;AAC1B,EAAE,eAAe;AACjB,EAAE,OAAO;AACT,EAA6D;AAC7D,EAAE,wCAAwC,EAAE;;AAE5C,EAAE,IAAI;AACN,IAAI,IAAI,OAAQ,IAAG,WAAW,OAAO,OAAO,CAAC,KAAA,KAAU,UAAW,IAAG,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,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B,gBAAgB,IAAI,EAAE,CAAC,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;AACA,gBAAA,UAAA,EAAA;AACA,kBAAA,WAAA,EAAA,KAAA,CAAA,IAAA;AACA,kBAAA,WAAA,EAAA,IAAA,IAAA,CAAA,KAAA,CAAA,aAAA,CAAA,CAAA,WAAA,EAAA;AACA,kBAAA,cAAA,EAAA,OAAA;AACA,kBAAA,CAAA,gCAAA,GAAA,sBAAA;AACA,kBAAA,CAAA,gCAAA,GAAA,MAAA;AACA,iBAAA;AACA,eAAA;AACA,cAAA,YAAA;AACA,gBAAA,IAAA;AACA,kBAAA,OAAA,OAAA,MAAA,CAAA,KAAA,CAAA,OAAA,EAAA,IAAA,CAAA,EAAA;AACA,iBAAA,CAAA,OAAA,CAAA,EAAA;AACA,kBAAA,gBAAA,CAAA,CAAA,EAAA,EAAA,SAAA,EAAA,EAAA,OAAA,EAAA,KAAA,EAAA,IAAA,EAAA,YAAA,EAAA,EAAA,CAAA;AACA,kBAAA,MAAA,CAAA;AACA,iBAAA,SAAA;AACA,kBAAA,OAAA,CAAA,SAAA,CAAA,KAAA,CAAA,IAAA,CAAA,CAAA;AACA;AACA,eAAA;AACA,aAAA;AACA,WAAA,CAAA;AACA,SAAA;AACA,OAAA,CAAA;;AAEA,MAAA,kBAAA,CAAA,OAAA,CAAA,SAAA,CAAA;AACA;AACA;AACA;AACA,GAAA,CAAA,OAAA,CAAA,EAAA;AACA;AACA;;AAEA,EAAA,OAAA,OAAA;AACA;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, close, consoleIntegration, continueTrace, createTransport, dedupeIntegration, eventFiltersIntegration, extraErrorDataIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, inboundFiltersIntegration, instrumentSupabaseClient, isInitialized, lastEventId, linkedErrorsIntegration, moduleMetadataIntegration, requestDataIntegration, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSpan, startSpanManual, supabaseIntegration, suppressTracing, trpcMiddleware, updateSpanName, withActiveSpan, withIsolationScope, withMonitor, withScope, zodErrorsIntegration } from '@sentry/core';
|
|
1
|
+
export { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, Scope, addBreadcrumb, addEventProcessor, addIntegration, captureCheckIn, captureConsoleIntegration, captureEvent, captureException, captureFeedback, captureMessage, close, consoleIntegration, consoleLoggingIntegration, continueTrace, createTransport, dedupeIntegration, eventFiltersIntegration, extraErrorDataIntegration, flush, functionToStringIntegration, getActiveSpan, getClient, getCurrentScope, getGlobalScope, getIsolationScope, getRootSpan, getSpanDescendants, getSpanStatusFromHttpCode, getTraceData, getTraceMetaTags, inboundFiltersIntegration, instrumentSupabaseClient, isInitialized, lastEventId, linkedErrorsIntegration, moduleMetadataIntegration, requestDataIntegration, rewriteFramesIntegration, setContext, setCurrentClient, setExtra, setExtras, setHttpStatus, setMeasurement, setTag, setTags, setUser, spanToBaggageHeader, spanToJSON, spanToTraceHeader, startInactiveSpan, startNewTrace, startSpan, startSpanManual, supabaseIntegration, suppressTracing, trpcMiddleware, updateSpanName, withActiveSpan, withIsolationScope, withMonitor, withScope, wrapMcpServerWithSentry, zodErrorsIntegration } from '@sentry/core';
|
|
2
|
+
import * as exports from './logs/exports.js';
|
|
3
|
+
export { exports as logger };
|
|
2
4
|
export { withSentry } from './handler.js';
|
|
5
|
+
export { instrumentDurableObjectWithSentry } from './durableobject.js';
|
|
3
6
|
export { sentryPagesPlugin } from './pages-plugin.js';
|
|
4
7
|
export { wrapRequestHandler } from './request.js';
|
|
5
8
|
export { CloudflareClient } from './client.js';
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mark an object as instrumented.
|
|
3
|
+
*/
|
|
4
|
+
function markAsInstrumented(obj) {
|
|
5
|
+
try {
|
|
6
|
+
(obj ).__SENTRY_INSTRUMENTED__ = true;
|
|
7
|
+
} catch {
|
|
8
|
+
// ignore errors here
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if an object is instrumented.
|
|
14
|
+
*/
|
|
15
|
+
function isInstrumented(obj) {
|
|
16
|
+
try {
|
|
17
|
+
return (obj ).__SENTRY_INSTRUMENTED__;
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { isInstrumented, markAsInstrumented };
|
|
24
|
+
//# sourceMappingURL=instrument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument.js","sources":["../../src/instrument.ts"],"sourcesContent":["type SentryInstrumented<T> = T & {\n __SENTRY_INSTRUMENTED__?: boolean;\n};\n\n/**\n * Mark an object as instrumented.\n */\nexport function markAsInstrumented<T>(obj: T): void {\n try {\n (obj as SentryInstrumented<T>).__SENTRY_INSTRUMENTED__ = true;\n } catch {\n // ignore errors here\n }\n}\n\n/**\n * Check if an object is instrumented.\n */\nexport function isInstrumented<T>(obj: T): boolean | undefined {\n try {\n return (obj as SentryInstrumented<T>).__SENTRY_INSTRUMENTED__;\n } catch {\n return false;\n }\n}\n"],"names":[],"mappings":"AAIA;AACA;AACA;AACO,SAAS,kBAAkB,CAAI,GAAG,EAAW;AACpD,EAAE,IAAI;AACN,IAAI,CAAC,GAAI,GAA0B,uBAAA,GAA0B,IAAI;AACjE,IAAI,MAAM;AACV;AACA;AACA;;AAEA;AACA;AACA;AACO,SAAS,cAAc,CAAI,GAAG,EAA0B;AAC/D,EAAE,IAAI;AACN,IAAI,OAAO,CAAC,GAAI,GAA0B,uBAAuB;AACjE,IAAI,MAAM;AACV,IAAI,OAAO,KAAK;AAChB;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sources":["../../../src/integrations/fetch.ts"],"sourcesContent":["import type {\n Client,\n FetchBreadcrumbData,\n FetchBreadcrumbHint,\n HandlerDataFetch,\n IntegrationFn,\n Span,\n} from '@sentry/core';\nimport {\n
|
|
1
|
+
{"version":3,"file":"fetch.js","sources":["../../../src/integrations/fetch.ts"],"sourcesContent":["import type {\n Client,\n FetchBreadcrumbData,\n FetchBreadcrumbHint,\n HandlerDataFetch,\n IntegrationFn,\n Span,\n} from '@sentry/core';\nimport {\n addBreadcrumb,\n addFetchInstrumentationHandler,\n defineIntegration,\n getBreadcrumbLogLevelFromHttpStatusCode,\n getClient,\n instrumentFetchRequest,\n isSentryRequestUrl,\n LRUMap,\n stringMatchesSomePattern,\n} from '@sentry/core';\n\nconst INTEGRATION_NAME = 'Fetch';\n\nconst HAS_CLIENT_MAP = new WeakMap<Client, boolean>();\n\nexport interface Options {\n /**\n * Whether breadcrumbs should be recorded for requests\n * Defaults to true\n */\n breadcrumbs: boolean;\n\n /**\n * Function determining whether or not to create spans to track outgoing requests to the given URL.\n * By default, spans will be created for all outgoing requests.\n */\n shouldCreateSpanForRequest?: (url: string) => boolean;\n}\n\nconst _fetchIntegration = ((options: Partial<Options> = {}) => {\n const breadcrumbs = options.breadcrumbs === undefined ? true : options.breadcrumbs;\n const shouldCreateSpanForRequest = options.shouldCreateSpanForRequest;\n\n const _createSpanUrlMap = new LRUMap<string, boolean>(100);\n const _headersUrlMap = new LRUMap<string, boolean>(100);\n\n const spans: Record<string, Span> = {};\n\n /** Decides whether to attach trace data to the outgoing fetch request */\n function _shouldAttachTraceData(url: string): boolean {\n const client = getClient();\n\n if (!client) {\n return false;\n }\n\n const clientOptions = client.getOptions();\n\n if (clientOptions.tracePropagationTargets === undefined) {\n return true;\n }\n\n const cachedDecision = _headersUrlMap.get(url);\n if (cachedDecision !== undefined) {\n return cachedDecision;\n }\n\n const decision = stringMatchesSomePattern(url, clientOptions.tracePropagationTargets);\n _headersUrlMap.set(url, decision);\n return decision;\n }\n\n /** Helper that wraps shouldCreateSpanForRequest option */\n function _shouldCreateSpan(url: string): boolean {\n if (shouldCreateSpanForRequest === undefined) {\n return true;\n }\n\n const cachedDecision = _createSpanUrlMap.get(url);\n if (cachedDecision !== undefined) {\n return cachedDecision;\n }\n\n const decision = shouldCreateSpanForRequest(url);\n _createSpanUrlMap.set(url, decision);\n return decision;\n }\n\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n addFetchInstrumentationHandler(handlerData => {\n const client = getClient();\n if (!client || !HAS_CLIENT_MAP.get(client)) {\n return;\n }\n\n if (isSentryRequestUrl(handlerData.fetchData.url, client)) {\n return;\n }\n\n instrumentFetchRequest(handlerData, _shouldCreateSpan, _shouldAttachTraceData, spans, 'auto.http.fetch');\n\n if (breadcrumbs) {\n createBreadcrumb(handlerData);\n }\n }, true);\n },\n setup(client) {\n HAS_CLIENT_MAP.set(client, true);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Creates spans and attaches tracing headers to fetch requests.\n */\nexport const fetchIntegration = defineIntegration(_fetchIntegration);\n\nfunction createBreadcrumb(handlerData: HandlerDataFetch): void {\n const { startTimestamp, endTimestamp } = handlerData;\n\n // We only capture complete fetch requests\n if (!endTimestamp) {\n return;\n }\n\n const breadcrumbData: FetchBreadcrumbData = {\n method: handlerData.fetchData.method,\n url: handlerData.fetchData.url,\n };\n\n if (handlerData.error) {\n const hint: FetchBreadcrumbHint = {\n data: handlerData.error,\n input: handlerData.args,\n startTimestamp,\n endTimestamp,\n };\n\n addBreadcrumb(\n {\n category: 'fetch',\n data: breadcrumbData,\n level: 'error',\n type: 'http',\n },\n hint,\n );\n } else {\n const response = handlerData.response as Response | undefined;\n\n breadcrumbData.request_body_size = handlerData.fetchData.request_body_size;\n breadcrumbData.response_body_size = handlerData.fetchData.response_body_size;\n breadcrumbData.status_code = response?.status;\n\n const hint: FetchBreadcrumbHint = {\n input: handlerData.args,\n response,\n startTimestamp,\n endTimestamp,\n };\n const level = getBreadcrumbLogLevelFromHttpStatusCode(breadcrumbData.status_code);\n\n addBreadcrumb(\n {\n category: 'fetch',\n data: breadcrumbData,\n type: 'http',\n level,\n },\n hint,\n );\n }\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAA,GAAmB,OAAO;;AAEhC,MAAM,cAAe,GAAE,IAAI,OAAO,EAAmB;;AAgBrD,MAAM,iBAAA,IAAqB,CAAC,OAAO,GAAqB,EAAE,KAAK;AAC/D,EAAE,MAAM,WAAA,GAAc,OAAO,CAAC,WAAA,KAAgB,SAAA,GAAY,IAAA,GAAO,OAAO,CAAC,WAAW;AACpF,EAAE,MAAM,0BAAA,GAA6B,OAAO,CAAC,0BAA0B;;AAEvE,EAAE,MAAM,iBAAkB,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;AAC5D,EAAE,MAAM,cAAe,GAAE,IAAI,MAAM,CAAkB,GAAG,CAAC;;AAEzD,EAAE,MAAM,KAAK,GAAyB,EAAE;;AAExC;AACA,EAAE,SAAS,sBAAsB,CAAC,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