@sentry/cloudflare 10.53.1 → 10.55.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 +53 -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 +22 -68
- 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 +53 -35
- 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 +23 -69
- 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 +15 -0
- package/build/types/flush.d.ts.map +1 -1
- package/build/types/instrumentations/worker/instrumentFetch.d.ts.map +1 -1
- package/build/types/integrations/hono.d.ts +3 -0
- package/build/types/integrations/hono.d.ts.map +1 -1
- package/build/types/pages-plugin.d.ts.map +1 -1
- package/build/types/request.d.ts.map +1 -1
- package/build/types-ts3.8/flush.d.ts +15 -0
- package/build/types-ts3.8/integrations/hono.d.ts +3 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentDurableObjectNamespace.js","sources":["../../../src/instrumentations/instrumentDurableObjectNamespace.ts"],"sourcesContent":["import type { DurableObjectNamespace, DurableObjectStub } from '@cloudflare/workers-types';\nimport { appendRpcMeta } from '../utils/rpcMeta';\nimport { instrumentFetcher } from './worker/instrumentFetcher';\n\n// Built-in DurableObjectStub methods that are not RPC calls.\nexport const STUB_NON_RPC_METHODS = new Set(['fetch', 'connect', 'dup']);\n\n/**\n * Instruments a DurableObjectNamespace binding to create spans for DO interactions.\n *\n * Wraps:\n * - `namespace.get(id)` / `namespace.getByName(name)` with a span + instruments returned stub\n * - `namespace.idFromName(name)` / `namespace.idFromString(id)` / `namespace.newUniqueId()` with breadcrumbs\n *\n * @param namespace - The DurableObjectNamespace to instrument\n */\nexport function instrumentDurableObjectNamespace(namespace: DurableObjectNamespace): DurableObjectNamespace {\n return new Proxy(namespace, {\n get(target, prop, _receiver) {\n const value = Reflect.get(target, prop) as unknown;\n\n if (typeof value !== 'function') {\n return value;\n }\n\n if (prop === 'get' || prop === 'getByName') {\n return function (this: unknown, ...args: unknown[]) {\n const stub = Reflect.apply(value, target, args);\n\n return instrumentDurableObjectStub(stub);\n };\n }\n\n return value.bind(target);\n },\n });\n}\n\n/**\n * Instruments a DurableObjectStub to create spans for outgoing fetch calls\n * and propagate trace context across RPC calls.\n *\n * @param stub - The DurableObjectStub to instrument\n */\nfunction instrumentDurableObjectStub(stub: DurableObjectStub): DurableObjectStub {\n return new Proxy(stub, {\n get(target, prop) {\n const value = Reflect.get(target, prop);\n\n if (prop === 'fetch' && typeof value === 'function') {\n return instrumentFetcher((...args) => Reflect.apply(value, target, args));\n }\n\n if (typeof value === 'function' && typeof prop === 'string' && !STUB_NON_RPC_METHODS.has(prop)) {\n return (...args: unknown[]) => Reflect.apply(value, target, appendRpcMeta(args));\n }\n\n return value;\n },\n });\n}\n"],"names":["instrumentFetcher","appendRpcMeta"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"instrumentDurableObjectNamespace.js","sources":["../../../src/instrumentations/instrumentDurableObjectNamespace.ts"],"sourcesContent":["import type { DurableObjectNamespace, DurableObjectStub } from '@cloudflare/workers-types';\nimport { appendRpcMeta } from '../utils/rpcMeta';\nimport { instrumentFetcher } from './worker/instrumentFetcher';\n\n// Built-in DurableObjectStub methods that are not RPC calls.\nexport const STUB_NON_RPC_METHODS = new Set(['fetch', 'connect', 'dup']);\n\n/**\n * Instruments a DurableObjectNamespace binding to create spans for DO interactions.\n *\n * Wraps:\n * - `namespace.get(id)` / `namespace.getByName(name)` with a span + instruments returned stub\n * - `namespace.idFromName(name)` / `namespace.idFromString(id)` / `namespace.newUniqueId()` with breadcrumbs\n *\n * @param namespace - The DurableObjectNamespace to instrument\n */\nexport function instrumentDurableObjectNamespace(namespace: DurableObjectNamespace): DurableObjectNamespace {\n return new Proxy(namespace, {\n get(target, prop, _receiver) {\n const value = Reflect.get(target, prop) as unknown;\n\n if (typeof value !== 'function') {\n return value;\n }\n\n if (prop === 'get' || prop === 'getByName') {\n return function (this: unknown, ...args: unknown[]) {\n const stub = Reflect.apply(value, target, args);\n\n return instrumentDurableObjectStub(stub);\n };\n }\n\n return value.bind(target);\n },\n });\n}\n\n/**\n * Instruments a DurableObjectStub to create spans for outgoing fetch calls\n * and propagate trace context across RPC calls.\n *\n * @param stub - The DurableObjectStub to instrument\n */\nfunction instrumentDurableObjectStub(stub: DurableObjectStub): DurableObjectStub {\n return new Proxy(stub, {\n get(target, prop) {\n const value = Reflect.get(target, prop);\n\n if (prop === 'fetch' && typeof value === 'function') {\n return instrumentFetcher((...args) => Reflect.apply(value, target, args));\n }\n\n if (typeof value === 'function' && typeof prop === 'string' && !STUB_NON_RPC_METHODS.has(prop)) {\n return (...args: unknown[]) => Reflect.apply(value, target, appendRpcMeta(args));\n }\n\n return value;\n },\n });\n}\n"],"names":["instrumentFetcher","appendRpcMeta"],"mappings":";;;;;AAKO,MAAM,uCAAuB,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,SAAA,EAAW,KAAK,CAAC;AAWhE,SAAS,iCAAiC,SAAA,EAA2D;AAC1G,EAAA,OAAO,IAAI,MAAM,SAAA,EAAW;AAAA,IAC1B,GAAA,CAAI,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAW;AAC3B,MAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,IAAI,CAAA;AAEtC,MAAA,IAAI,OAAO,UAAU,UAAA,EAAY;AAC/B,QAAA,OAAO,KAAA;AAAA,MACT;AAEA,MAAA,IAAI,IAAA,KAAS,KAAA,IAAS,IAAA,KAAS,WAAA,EAAa;AAC1C,QAAA,OAAO,YAA4B,IAAA,EAAiB;AAClD,UAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,KAAA,CAAM,KAAA,EAAO,QAAQ,IAAI,CAAA;AAE9C,UAAA,OAAO,4BAA4B,IAAI,CAAA;AAAA,QACzC,CAAA;AAAA,MACF;AAEA,MAAA,OAAO,KAAA,CAAM,KAAK,MAAM,CAAA;AAAA,IAC1B;AAAA,GACD,CAAA;AACH;AAQA,SAAS,4BAA4B,IAAA,EAA4C;AAC/E,EAAA,OAAO,IAAI,MAAM,IAAA,EAAM;AAAA,IACrB,GAAA,CAAI,QAAQ,IAAA,EAAM;AAChB,MAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,IAAI,CAAA;AAEtC,MAAA,IAAI,IAAA,KAAS,OAAA,IAAW,OAAO,KAAA,KAAU,UAAA,EAAY;AACnD,QAAA,OAAOA,mCAAA,CAAkB,IAAI,IAAA,KAAS,OAAA,CAAQ,MAAM,KAAA,EAAO,MAAA,EAAQ,IAAI,CAAC,CAAA;AAAA,MAC1E;AAEA,MAAA,IAAI,OAAO,KAAA,KAAU,UAAA,IAAc,OAAO,IAAA,KAAS,YAAY,CAAC,oBAAA,CAAqB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC9F,QAAA,OAAO,CAAA,GAAI,SAAoB,OAAA,CAAQ,KAAA,CAAM,OAAO,MAAA,EAAQC,qBAAA,CAAc,IAAI,CAAC,CAAA;AAAA,MACjF;AAEA,MAAA,OAAO,KAAA;AAAA,IACT;AAAA,GACD,CAAA;AACH;;;;;"}
|
|
@@ -3,88 +3,54 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
const traceLinks = require('../utils/traceLinks.js');
|
|
5
5
|
|
|
6
|
-
const STORAGE_METHODS_TO_INSTRUMENT = [
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Instruments DurableObjectStorage methods with Sentry spans.
|
|
10
|
-
*
|
|
11
|
-
* Wraps the following async methods:
|
|
12
|
-
* - get, put, delete, list (KV API)
|
|
13
|
-
* - setAlarm, getAlarm, deleteAlarm (Alarm API)
|
|
14
|
-
*
|
|
15
|
-
* When setAlarm is called, it also stores the current span context so that when
|
|
16
|
-
* the alarm fires later, it can link back to the trace that called setAlarm.
|
|
17
|
-
*
|
|
18
|
-
* @param storage - The DurableObjectStorage instance to instrument
|
|
19
|
-
* @param waitUntil - Optional waitUntil function to defer span context storage
|
|
20
|
-
* @returns An instrumented DurableObjectStorage instance
|
|
21
|
-
*/
|
|
22
|
-
function instrumentDurableObjectStorage(
|
|
23
|
-
storage,
|
|
24
|
-
waitUntil,
|
|
25
|
-
) {
|
|
6
|
+
const STORAGE_METHODS_TO_INSTRUMENT = ["get", "put", "delete", "list", "setAlarm", "getAlarm", "deleteAlarm"];
|
|
7
|
+
function instrumentDurableObjectStorage(storage, waitUntil) {
|
|
26
8
|
return new Proxy(storage, {
|
|
27
9
|
get(target, prop, _receiver) {
|
|
28
|
-
// Use `target` as the receiver instead of the proxy (`_receiver`).
|
|
29
|
-
// Native workerd getters (e.g., `storage.sql`) validate `this` via
|
|
30
|
-
// internal slots. Passing the proxy as receiver breaks that check,
|
|
31
|
-
// causing "Illegal invocation: function called with incorrect `this`
|
|
32
|
-
// reference" errors.
|
|
33
10
|
const original = Reflect.get(target, prop, target);
|
|
34
|
-
|
|
35
|
-
if (typeof original !== 'function') {
|
|
11
|
+
if (typeof original !== "function") {
|
|
36
12
|
return original;
|
|
37
13
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return (original ).bind(target);
|
|
14
|
+
const methodName = prop;
|
|
15
|
+
if (!STORAGE_METHODS_TO_INSTRUMENT.includes(methodName)) {
|
|
16
|
+
return original.bind(target);
|
|
42
17
|
}
|
|
43
|
-
|
|
44
|
-
return function ( ...args) {
|
|
18
|
+
return function(...args) {
|
|
45
19
|
return core.startSpan(
|
|
46
20
|
{
|
|
47
21
|
// Use underscore naming to match Cloudflare's native instrumentation (e.g., "durable_object_storage_get")
|
|
48
22
|
name: `durable_object_storage_${methodName}`,
|
|
49
|
-
op:
|
|
23
|
+
op: "db",
|
|
50
24
|
attributes: {
|
|
51
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
25
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.db.cloudflare.durable_object",
|
|
26
|
+
"db.system.name": "cloudflare.durable_object.storage",
|
|
27
|
+
"db.operation.name": methodName
|
|
28
|
+
}
|
|
55
29
|
},
|
|
56
30
|
() => {
|
|
57
31
|
const teardown = async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// We use the original (uninstrumented) storage (target) to avoid creating a span
|
|
61
|
-
// for this internal operation. The storage is deferred via waitUntil to not block.
|
|
62
|
-
if (methodName === 'setAlarm') {
|
|
63
|
-
await traceLinks.storeSpanContext(target, 'alarm');
|
|
32
|
+
if (methodName === "setAlarm") {
|
|
33
|
+
await traceLinks.storeSpanContext(target, "alarm");
|
|
64
34
|
}
|
|
65
35
|
};
|
|
66
|
-
|
|
67
|
-
const result = (original ).apply(target, args);
|
|
68
|
-
|
|
36
|
+
const result = original.apply(target, args);
|
|
69
37
|
if (!core.isThenable(result)) {
|
|
70
38
|
waitUntil?.(teardown());
|
|
71
|
-
|
|
72
39
|
return result;
|
|
73
40
|
}
|
|
74
|
-
|
|
75
41
|
return result.then(
|
|
76
|
-
res => {
|
|
42
|
+
(res) => {
|
|
77
43
|
waitUntil?.(teardown());
|
|
78
44
|
return res;
|
|
79
45
|
},
|
|
80
|
-
e => {
|
|
46
|
+
(e) => {
|
|
81
47
|
throw e;
|
|
82
|
-
}
|
|
48
|
+
}
|
|
83
49
|
);
|
|
84
|
-
}
|
|
50
|
+
}
|
|
85
51
|
);
|
|
86
52
|
};
|
|
87
|
-
}
|
|
53
|
+
}
|
|
88
54
|
});
|
|
89
55
|
}
|
|
90
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentDurableObjectStorage.js","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport { isThenable, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\nimport { storeSpanContext } from '../utils/traceLinks';\n\nconst STORAGE_METHODS_TO_INSTRUMENT = ['get', 'put', 'delete', 'list', 'setAlarm', 'getAlarm', 'deleteAlarm'] as const;\n\ntype StorageMethod = (typeof STORAGE_METHODS_TO_INSTRUMENT)[number];\n\ntype WaitUntil = (promise: Promise<unknown>) => void;\n\n/**\n * Instruments DurableObjectStorage methods with Sentry spans.\n *\n * Wraps the following async methods:\n * - get, put, delete, list (KV API)\n * - setAlarm, getAlarm, deleteAlarm (Alarm API)\n *\n * When setAlarm is called, it also stores the current span context so that when\n * the alarm fires later, it can link back to the trace that called setAlarm.\n *\n * @param storage - The DurableObjectStorage instance to instrument\n * @param waitUntil - Optional waitUntil function to defer span context storage\n * @returns An instrumented DurableObjectStorage instance\n */\nexport function instrumentDurableObjectStorage(\n storage: DurableObjectStorage,\n waitUntil?: WaitUntil,\n): DurableObjectStorage {\n return new Proxy(storage, {\n get(target, prop, _receiver) {\n // Use `target` as the receiver instead of the proxy (`_receiver`).\n // Native workerd getters (e.g., `storage.sql`) validate `this` via\n // internal slots. Passing the proxy as receiver breaks that check,\n // causing \"Illegal invocation: function called with incorrect `this`\n // reference\" errors.\n const original = Reflect.get(target, prop, target);\n\n if (typeof original !== 'function') {\n return original;\n }\n\n const methodName = prop as string;\n if (!STORAGE_METHODS_TO_INSTRUMENT.includes(methodName as StorageMethod)) {\n return (original as (...args: unknown[]) => unknown).bind(target);\n }\n\n return function (this: unknown, ...args: unknown[]) {\n return startSpan(\n {\n // Use underscore naming to match Cloudflare's native instrumentation (e.g., \"durable_object_storage_get\")\n name: `durable_object_storage_${methodName}`,\n op: 'db',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object',\n 'db.system.name': 'cloudflare.durable_object.storage',\n 'db.operation.name': methodName,\n },\n },\n () => {\n const teardown = async (): Promise<void> => {\n // When setAlarm is called, store the current span context so that when the alarm\n // fires later, it can link back to the trace that called setAlarm.\n // We use the original (uninstrumented) storage (target) to avoid creating a span\n // for this internal operation. The storage is deferred via waitUntil to not block.\n if (methodName === 'setAlarm') {\n await storeSpanContext(target, 'alarm');\n }\n };\n\n const result = (original as (...args: unknown[]) => unknown).apply(target, args);\n\n if (!isThenable(result)) {\n waitUntil?.(teardown());\n\n return result;\n }\n\n return result.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n throw e;\n },\n );\n },\n );\n };\n },\n });\n}\n"],"names":["startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","storeSpanContext","isThenable"],"mappings":";;;;;AAIA,MAAM,
|
|
1
|
+
{"version":3,"file":"instrumentDurableObjectStorage.js","sources":["../../../src/instrumentations/instrumentDurableObjectStorage.ts"],"sourcesContent":["import type { DurableObjectStorage } from '@cloudflare/workers-types';\nimport { isThenable, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';\nimport { storeSpanContext } from '../utils/traceLinks';\n\nconst STORAGE_METHODS_TO_INSTRUMENT = ['get', 'put', 'delete', 'list', 'setAlarm', 'getAlarm', 'deleteAlarm'] as const;\n\ntype StorageMethod = (typeof STORAGE_METHODS_TO_INSTRUMENT)[number];\n\ntype WaitUntil = (promise: Promise<unknown>) => void;\n\n/**\n * Instruments DurableObjectStorage methods with Sentry spans.\n *\n * Wraps the following async methods:\n * - get, put, delete, list (KV API)\n * - setAlarm, getAlarm, deleteAlarm (Alarm API)\n *\n * When setAlarm is called, it also stores the current span context so that when\n * the alarm fires later, it can link back to the trace that called setAlarm.\n *\n * @param storage - The DurableObjectStorage instance to instrument\n * @param waitUntil - Optional waitUntil function to defer span context storage\n * @returns An instrumented DurableObjectStorage instance\n */\nexport function instrumentDurableObjectStorage(\n storage: DurableObjectStorage,\n waitUntil?: WaitUntil,\n): DurableObjectStorage {\n return new Proxy(storage, {\n get(target, prop, _receiver) {\n // Use `target` as the receiver instead of the proxy (`_receiver`).\n // Native workerd getters (e.g., `storage.sql`) validate `this` via\n // internal slots. Passing the proxy as receiver breaks that check,\n // causing \"Illegal invocation: function called with incorrect `this`\n // reference\" errors.\n const original = Reflect.get(target, prop, target);\n\n if (typeof original !== 'function') {\n return original;\n }\n\n const methodName = prop as string;\n if (!STORAGE_METHODS_TO_INSTRUMENT.includes(methodName as StorageMethod)) {\n return (original as (...args: unknown[]) => unknown).bind(target);\n }\n\n return function (this: unknown, ...args: unknown[]) {\n return startSpan(\n {\n // Use underscore naming to match Cloudflare's native instrumentation (e.g., \"durable_object_storage_get\")\n name: `durable_object_storage_${methodName}`,\n op: 'db',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object',\n 'db.system.name': 'cloudflare.durable_object.storage',\n 'db.operation.name': methodName,\n },\n },\n () => {\n const teardown = async (): Promise<void> => {\n // When setAlarm is called, store the current span context so that when the alarm\n // fires later, it can link back to the trace that called setAlarm.\n // We use the original (uninstrumented) storage (target) to avoid creating a span\n // for this internal operation. The storage is deferred via waitUntil to not block.\n if (methodName === 'setAlarm') {\n await storeSpanContext(target, 'alarm');\n }\n };\n\n const result = (original as (...args: unknown[]) => unknown).apply(target, args);\n\n if (!isThenable(result)) {\n waitUntil?.(teardown());\n\n return result;\n }\n\n return result.then(\n res => {\n waitUntil?.(teardown());\n return res;\n },\n e => {\n throw e;\n },\n );\n },\n );\n };\n },\n });\n}\n"],"names":["startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","storeSpanContext","isThenable"],"mappings":";;;;;AAIA,MAAM,6BAAA,GAAgC,CAAC,KAAA,EAAO,KAAA,EAAO,UAAU,MAAA,EAAQ,UAAA,EAAY,YAAY,aAAa,CAAA;AAoBrG,SAAS,8BAAA,CACd,SACA,SAAA,EACsB;AACtB,EAAA,OAAO,IAAI,MAAM,OAAA,EAAS;AAAA,IACxB,GAAA,CAA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gBAAA,MAAM,CAAA;AAAA,cACR;AAAA,aACF;AAAA,UACF;AAAA,SACF;AAAA,MACF,CAAA;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -9,102 +9,48 @@ const options = require('../options.js');
|
|
|
9
9
|
const instrumentContext = require('../utils/instrumentContext.js');
|
|
10
10
|
const instrumentEnv = require('./worker/instrumentEnv.js');
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
* Instruments a WorkerEntrypoint class to capture errors and performance data.
|
|
14
|
-
*
|
|
15
|
-
* Instruments the following methods (same as `withSentry` for ExportedHandler):
|
|
16
|
-
* - fetch (HTTP requests)
|
|
17
|
-
* - scheduled (cron triggers)
|
|
18
|
-
* - queue (queue consumers)
|
|
19
|
-
* - email (email handlers)
|
|
20
|
-
* - tail (tail workers)
|
|
21
|
-
*
|
|
22
|
-
* as well as any other public RPC methods on the WorkerEntrypoint instance.
|
|
23
|
-
*
|
|
24
|
-
* @param optionsCallback Function that returns the options for the SDK initialization.
|
|
25
|
-
* @param WorkerEntrypointClass The WorkerEntrypoint class to instrument.
|
|
26
|
-
* @returns The instrumented WorkerEntrypoint class.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```ts
|
|
30
|
-
* class MyWorkerBase extends WorkerEntrypoint<Env> {
|
|
31
|
-
* async fetch(request: Request): Promise<Response> {
|
|
32
|
-
* return new Response('Hello World!');
|
|
33
|
-
* }
|
|
34
|
-
*
|
|
35
|
-
* async myRpcMethod(arg: string): Promise<string> {
|
|
36
|
-
* return `Hello ${arg}!`;
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
*
|
|
40
|
-
* export default instrumentWorkerEntrypoint(
|
|
41
|
-
* env => ({
|
|
42
|
-
* dsn: env.SENTRY_DSN,
|
|
43
|
-
* tracesSampleRate: 1.0,
|
|
44
|
-
* }),
|
|
45
|
-
* MyWorkerBase,
|
|
46
|
-
* );
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
function instrumentWorkerEntrypoint(
|
|
50
|
-
optionsCallback,
|
|
51
|
-
WorkerEntrypointClass,
|
|
52
|
-
) {
|
|
53
|
-
// Set up AsyncLocalStorage strategy ONCE at instrumentation time, not per-request
|
|
54
|
-
// This is critical - calling this per-request would create a new AsyncLocalStorage
|
|
55
|
-
// each time, breaking scope isolation for concurrent requests
|
|
12
|
+
function instrumentWorkerEntrypoint(optionsCallback, WorkerEntrypointClass) {
|
|
56
13
|
async.setAsyncLocalStorageAsyncContextStrategy();
|
|
57
|
-
|
|
58
14
|
return new Proxy(WorkerEntrypointClass, {
|
|
59
15
|
construct(target, [ctx, env]) {
|
|
60
16
|
const context = instrumentContext.instrumentContext(ctx);
|
|
61
17
|
const options$1 = options.getFinalOptions(optionsCallback(env), env);
|
|
62
18
|
const instrumentedEnv = instrumentEnv.instrumentEnv(env, options$1);
|
|
63
19
|
const obj = new target(context, instrumentedEnv);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// This is necessary because the base WorkerEntrypoint class sets this.ctx
|
|
67
|
-
// from the constructor parameter, but we want users accessing this.ctx
|
|
68
|
-
// to get the instrumented version
|
|
69
|
-
if ('ctx' in obj) {
|
|
70
|
-
Object.defineProperty(obj, 'ctx', {
|
|
20
|
+
if ("ctx" in obj) {
|
|
21
|
+
Object.defineProperty(obj, "ctx", {
|
|
71
22
|
value: context,
|
|
72
23
|
writable: true,
|
|
73
24
|
enumerable: true,
|
|
74
|
-
configurable: true
|
|
25
|
+
configurable: true
|
|
75
26
|
});
|
|
76
27
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Object.defineProperty(obj, 'env', {
|
|
28
|
+
if ("env" in obj) {
|
|
29
|
+
Object.defineProperty(obj, "env", {
|
|
80
30
|
value: instrumentedEnv,
|
|
81
31
|
writable: true,
|
|
82
32
|
enumerable: true,
|
|
83
|
-
configurable: true
|
|
33
|
+
configurable: true
|
|
84
34
|
});
|
|
85
35
|
}
|
|
86
|
-
|
|
87
|
-
Object.defineProperty(obj, '__SENTRY_CONTEXT__', {
|
|
36
|
+
Object.defineProperty(obj, "__SENTRY_CONTEXT__", {
|
|
88
37
|
value: context,
|
|
89
38
|
enumerable: false,
|
|
90
39
|
writable: false,
|
|
91
|
-
configurable: false
|
|
40
|
+
configurable: false
|
|
92
41
|
});
|
|
93
|
-
|
|
94
|
-
Object.defineProperty(obj, '__SENTRY_OPTIONS__', {
|
|
42
|
+
Object.defineProperty(obj, "__SENTRY_OPTIONS__", {
|
|
95
43
|
value: options$1,
|
|
96
44
|
enumerable: false,
|
|
97
45
|
writable: false,
|
|
98
|
-
configurable: false
|
|
46
|
+
configurable: false
|
|
99
47
|
});
|
|
100
|
-
|
|
101
48
|
instrumentFetch.instrumentWorkerEntrypointFetch(obj, options$1, context);
|
|
102
49
|
instrumentScheduled.instrumentWorkerEntrypointScheduled(obj, options$1, context);
|
|
103
50
|
instrumentQueue.instrumentWorkerEntrypointQueue(obj, options$1, context);
|
|
104
51
|
instrumentTail.instrumentWorkerEntrypointTail(obj, options$1, context);
|
|
105
|
-
|
|
106
52
|
return obj;
|
|
107
|
-
}
|
|
53
|
+
}
|
|
108
54
|
});
|
|
109
55
|
}
|
|
110
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentWorkerEntrypoint.js","sources":["../../../src/instrumentations/instrumentWorkerEntrypoint.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '../async';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport type { CloudflareOptions } from '../client';\nimport { instrumentWorkerEntrypointFetch } from './worker/instrumentFetch';\nimport { instrumentWorkerEntrypointQueue } from './worker/instrumentQueue';\nimport { instrumentWorkerEntrypointScheduled } from './worker/instrumentScheduled';\nimport { instrumentWorkerEntrypointTail } from './worker/instrumentTail';\nimport { getFinalOptions } from '../options';\nimport { instrumentContext } from '../utils/instrumentContext';\nimport { instrumentEnv } from './worker/instrumentEnv';\n\nexport type WorkerEntrypointConstructor<Env = typeof cloudflareEnv, Props = {}> = new (\n ctx: ExecutionContext,\n env: typeof cloudflareEnv,\n) => InstanceType<typeof WorkerEntrypoint<Env, Props>>;\n\n/**\n * Instruments a WorkerEntrypoint class to capture errors and performance data.\n *\n * Instruments the following methods (same as `withSentry` for ExportedHandler):\n * - fetch (HTTP requests)\n * - scheduled (cron triggers)\n * - queue (queue consumers)\n * - email (email handlers)\n * - tail (tail workers)\n *\n * as well as any other public RPC methods on the WorkerEntrypoint instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param WorkerEntrypointClass The WorkerEntrypoint class to instrument.\n * @returns The instrumented WorkerEntrypoint class.\n *\n * @example\n * ```ts\n * class MyWorkerBase extends WorkerEntrypoint<Env> {\n * async fetch(request: Request): Promise<Response> {\n * return new Response('Hello World!');\n * }\n *\n * async myRpcMethod(arg: string): Promise<string> {\n * return `Hello ${arg}!`;\n * }\n * }\n *\n * export default instrumentWorkerEntrypoint(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyWorkerBase,\n * );\n * ```\n */\nexport function instrumentWorkerEntrypoint<T extends WorkerEntrypointConstructor>(\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n WorkerEntrypointClass: T,\n): T {\n // Set up AsyncLocalStorage strategy ONCE at instrumentation time, not per-request\n // This is critical - calling this per-request would create a new AsyncLocalStorage\n // each time, breaking scope isolation for concurrent requests\n setAsyncLocalStorageAsyncContextStrategy();\n\n return new Proxy(WorkerEntrypointClass, {\n construct(target, [ctx, env]) {\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n const instrumentedEnv = instrumentEnv(env, options);\n const obj = new target(context, instrumentedEnv);\n\n // Override this.ctx to ensure the instrumented context is used\n // This is necessary because the base WorkerEntrypoint class sets this.ctx\n // from the constructor parameter, but we want users accessing this.ctx\n // to get the instrumented version\n if ('ctx' in obj) {\n Object.defineProperty(obj, 'ctx', {\n value: context,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n\n if ('env' in obj) {\n Object.defineProperty(obj, 'env', {\n value: instrumentedEnv,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n\n Object.defineProperty(obj, '__SENTRY_CONTEXT__', {\n value: context,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n Object.defineProperty(obj, '__SENTRY_OPTIONS__', {\n value: options,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n instrumentWorkerEntrypointFetch(obj, options, context);\n instrumentWorkerEntrypointScheduled(obj, options, context);\n instrumentWorkerEntrypointQueue(obj, options, context);\n instrumentWorkerEntrypointTail(obj, options, context);\n\n return obj;\n },\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","instrumentEnv","instrumentWorkerEntrypointFetch","instrumentWorkerEntrypointScheduled","instrumentWorkerEntrypointQueue","instrumentWorkerEntrypointTail"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"instrumentWorkerEntrypoint.js","sources":["../../../src/instrumentations/instrumentWorkerEntrypoint.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '../async';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport type { CloudflareOptions } from '../client';\nimport { instrumentWorkerEntrypointFetch } from './worker/instrumentFetch';\nimport { instrumentWorkerEntrypointQueue } from './worker/instrumentQueue';\nimport { instrumentWorkerEntrypointScheduled } from './worker/instrumentScheduled';\nimport { instrumentWorkerEntrypointTail } from './worker/instrumentTail';\nimport { getFinalOptions } from '../options';\nimport { instrumentContext } from '../utils/instrumentContext';\nimport { instrumentEnv } from './worker/instrumentEnv';\n\nexport type WorkerEntrypointConstructor<Env = typeof cloudflareEnv, Props = {}> = new (\n ctx: ExecutionContext,\n env: typeof cloudflareEnv,\n) => InstanceType<typeof WorkerEntrypoint<Env, Props>>;\n\n/**\n * Instruments a WorkerEntrypoint class to capture errors and performance data.\n *\n * Instruments the following methods (same as `withSentry` for ExportedHandler):\n * - fetch (HTTP requests)\n * - scheduled (cron triggers)\n * - queue (queue consumers)\n * - email (email handlers)\n * - tail (tail workers)\n *\n * as well as any other public RPC methods on the WorkerEntrypoint instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param WorkerEntrypointClass The WorkerEntrypoint class to instrument.\n * @returns The instrumented WorkerEntrypoint class.\n *\n * @example\n * ```ts\n * class MyWorkerBase extends WorkerEntrypoint<Env> {\n * async fetch(request: Request): Promise<Response> {\n * return new Response('Hello World!');\n * }\n *\n * async myRpcMethod(arg: string): Promise<string> {\n * return `Hello ${arg}!`;\n * }\n * }\n *\n * export default instrumentWorkerEntrypoint(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyWorkerBase,\n * );\n * ```\n */\nexport function instrumentWorkerEntrypoint<T extends WorkerEntrypointConstructor>(\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n WorkerEntrypointClass: T,\n): T {\n // Set up AsyncLocalStorage strategy ONCE at instrumentation time, not per-request\n // This is critical - calling this per-request would create a new AsyncLocalStorage\n // each time, breaking scope isolation for concurrent requests\n setAsyncLocalStorageAsyncContextStrategy();\n\n return new Proxy(WorkerEntrypointClass, {\n construct(target, [ctx, env]) {\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n const instrumentedEnv = instrumentEnv(env, options);\n const obj = new target(context, instrumentedEnv);\n\n // Override this.ctx to ensure the instrumented context is used\n // This is necessary because the base WorkerEntrypoint class sets this.ctx\n // from the constructor parameter, but we want users accessing this.ctx\n // to get the instrumented version\n if ('ctx' in obj) {\n Object.defineProperty(obj, 'ctx', {\n value: context,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n\n if ('env' in obj) {\n Object.defineProperty(obj, 'env', {\n value: instrumentedEnv,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n\n Object.defineProperty(obj, '__SENTRY_CONTEXT__', {\n value: context,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n Object.defineProperty(obj, '__SENTRY_OPTIONS__', {\n value: options,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n instrumentWorkerEntrypointFetch(obj, options, context);\n instrumentWorkerEntrypointScheduled(obj, options, context);\n instrumentWorkerEntrypointQueue(obj, options, context);\n instrumentWorkerEntrypointTail(obj, options, context);\n\n return obj;\n },\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","instrumentEnv","instrumentWorkerEntrypointFetch","instrumentWorkerEntrypointScheduled","instrumentWorkerEntrypointQueue","instrumentWorkerEntrypointTail"],"mappings":";;;;;;;;;;;AAqDO,SAAS,0BAAA,CACd,iBACA,qBAAA,EACG;AAIH,EAAAA,8CAAA,EAAyC;AAEzC,EAAA,OAAO,IAAI,MAAM,qBAAA,EAAuB;AAAA,IACtC,SAAA,CAAU,MAAA,EAAQ,CAAC,GAAA,EAAK,GAAG,CAAA,EAAG;AAC5B,MAAA,MAAM,OAAA,GAAUC,oCAAkB,GAAG,CAAA;AACrC,MAAA,MAAMC,SAAA,GAAUC,uBAAA,CAAgB,eAAA,CAAgB,GAAG,GAAG,GAAG,CAAA;AACzD,MAAA,MAAM,eAAA,GAAkBC,2BAAA,CAAc,GAAA,EAAKF,SAAO,CAAA;AAClD,MAAA,MAAM,GAAA,GAAM,IAAI,MAAA,CAAO,OAAA,EAAS,eAAe,CAAA;AAM/C,MAAA,IAAI,SAAS,GAAA,EAAK;AAChB,QAAA,MAAA,CAAO,cAAA,CAAe,KAAK,KAAA,EAAO;AAAA,UAChC,KAAA,EAAO,OAAA;AAAA,UACP,QAAA,EAAU,IAAA;AAAA,UACV,UAAA,EAAY,IAAA;AAAA,UACZ,YAAA,EAAc;AAAA,SACf,CAAA;AAAA,MACH;AAEA,MAAA,IAAI,SAAS,GAAA,EAAK;AAChB,QAAA,MAAA,CAAO,cAAA,CAAe,KAAK,KAAA,EAAO;AAAA,UAChC,KAAA,EAAO,eAAA;AAAA,UACP,QAAA,EAAU,IAAA;AAAA,UACV,UAAA,EAAY,IAAA;AAAA,UACZ,YAAA,EAAc;AAAA,SACf,CAAA;AAAA,MACH;AAEA,MAAA,MAAA,CAAO,cAAA,CAAe,KAAK,oBAAA,EAAsB;AAAA,QAC/C,KAAA,EAAO,OAAA;AAAA,QACP,UAAA,EAAY,KAAA;AAAA,QACZ,QAAA,EAAU,KAAA;AAAA,QACV,YAAA,EAAc;AAAA,OACf,CAAA;AAED,MAAA,MAAA,CAAO,cAAA,CAAe,KAAK,oBAAA,EAAsB;AAAA,QAC/C,KAAA,EAAOA,SAAA;AAAA,QACP,UAAA,EAAY,KAAA;AAAA,QACZ,QAAA,EAAU,KAAA;AAAA,QACV,YAAA,EAAc;AAAA,OACf,CAAA;AAED,MAAAG,+CAAA,CAAgC,GAAA,EAAKH,WAAS,OAAO,CAAA;AACrD,MAAAI,uDAAA,CAAoC,GAAA,EAAKJ,WAAS,OAAO,CAAA;AACzD,MAAAK,+CAAA,CAAgC,GAAA,EAAKL,WAAS,OAAO,CAAA;AACrD,MAAAM,6CAAA,CAA+B,GAAA,EAAKN,WAAS,OAAO,CAAA;AAEpD,MAAA,OAAO,GAAA;AAAA,IACT;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -9,73 +9,51 @@ const sdk = require('../../sdk.js');
|
|
|
9
9
|
const instrumentContext = require('../../utils/instrumentContext.js');
|
|
10
10
|
const instrumentEnv = require('./instrumentEnv.js');
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
function wrapEmailHandler(
|
|
16
|
-
emailMessage,
|
|
17
|
-
options,
|
|
18
|
-
context,
|
|
19
|
-
fn,
|
|
20
|
-
) {
|
|
21
|
-
return core.withIsolationScope(isolationScope => {
|
|
12
|
+
function wrapEmailHandler(emailMessage, options, context, fn) {
|
|
13
|
+
return core.withIsolationScope((isolationScope) => {
|
|
22
14
|
const waitUntil = context.waitUntil.bind(context);
|
|
23
|
-
|
|
24
15
|
const client = sdk.init({ ...options, ctx: context });
|
|
25
16
|
isolationScope.setClient(client);
|
|
26
|
-
|
|
27
17
|
scopeUtils.addCloudResourceContext(isolationScope);
|
|
28
|
-
|
|
29
18
|
return core.startSpan(
|
|
30
19
|
{
|
|
31
|
-
op:
|
|
20
|
+
op: "faas.email",
|
|
32
21
|
name: `Handle Email ${emailMessage.to}`,
|
|
33
22
|
attributes: {
|
|
34
|
-
|
|
35
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
36
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
37
|
-
}
|
|
23
|
+
"faas.trigger": "email",
|
|
24
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.faas.cloudflare.email",
|
|
25
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "task"
|
|
26
|
+
}
|
|
38
27
|
},
|
|
39
28
|
async () => {
|
|
40
29
|
try {
|
|
41
30
|
return await fn();
|
|
42
31
|
} catch (e) {
|
|
43
|
-
core.captureException(e, { mechanism: { handled: false, type:
|
|
32
|
+
core.captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.email" } });
|
|
44
33
|
throw e;
|
|
45
34
|
} finally {
|
|
46
35
|
waitUntil(flush.flushAndDispose(client));
|
|
47
36
|
}
|
|
48
|
-
}
|
|
37
|
+
}
|
|
49
38
|
);
|
|
50
39
|
});
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* Instruments an email handler for ExportedHandler (env/ctx come from args).
|
|
55
|
-
*/
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
function instrumentExportedHandlerEmail(
|
|
58
|
-
handler,
|
|
59
|
-
optionsCallback,
|
|
60
|
-
) {
|
|
61
|
-
if (!('email' in handler) || typeof handler.email !== 'function') {
|
|
41
|
+
function instrumentExportedHandlerEmail(handler, optionsCallback) {
|
|
42
|
+
if (!("email" in handler) || typeof handler.email !== "function") {
|
|
62
43
|
return;
|
|
63
44
|
}
|
|
64
|
-
|
|
65
45
|
handler.email = instrument.ensureInstrumented(
|
|
66
46
|
handler.email,
|
|
67
|
-
original =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
47
|
+
(original) => new Proxy(original, {
|
|
48
|
+
apply(target, thisArg, args) {
|
|
49
|
+
const [emailMessage, env, ctx] = args;
|
|
50
|
+
const context = instrumentContext.instrumentContext(ctx);
|
|
51
|
+
const options$1 = options.getFinalOptions(optionsCallback(env), env);
|
|
52
|
+
args[1] = instrumentEnv.instrumentEnv(env, options$1);
|
|
53
|
+
args[2] = context;
|
|
54
|
+
return wrapEmailHandler(emailMessage, options$1, context, () => target.apply(thisArg, args));
|
|
55
|
+
}
|
|
56
|
+
})
|
|
79
57
|
);
|
|
80
58
|
}
|
|
81
59
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentEmail.js","sources":["../../../../src/instrumentations/worker/instrumentEmail.ts"],"sourcesContent":["import type { EmailMessage, ExportedHandler } from '@cloudflare/workers-types';\nimport type { env as cloudflareEnv } from 'cloudflare:workers';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { instrumentEnv } from './instrumentEnv';\n\n/**\n * Core email handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapEmailHandler(\n emailMessage: EmailMessage,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.email',\n name: `Handle Email ${emailMessage.to}`,\n attributes: {\n 'faas.trigger': 'email',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.email',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments an email handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerEmail<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('email' in handler) || typeof handler.email !== 'function') {\n return;\n }\n\n handler.email = ensureInstrumented(\n handler.email,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['email']>>) {\n const [emailMessage, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapEmailHandler(emailMessage, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions","instrumentEnv"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"instrumentEmail.js","sources":["../../../../src/instrumentations/worker/instrumentEmail.ts"],"sourcesContent":["import type { EmailMessage, ExportedHandler } from '@cloudflare/workers-types';\nimport type { env as cloudflareEnv } from 'cloudflare:workers';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { instrumentEnv } from './instrumentEnv';\n\n/**\n * Core email handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapEmailHandler(\n emailMessage: EmailMessage,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.email',\n name: `Handle Email ${emailMessage.to}`,\n attributes: {\n 'faas.trigger': 'email',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.email',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments an email handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerEmail<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('email' in handler) || typeof handler.email !== 'function') {\n return;\n }\n\n handler.email = ensureInstrumented(\n handler.email,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['email']>>) {\n const [emailMessage, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapEmailHandler(emailMessage, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions","instrumentEnv"],"mappings":";;;;;;;;;;;AAqBA,SAAS,gBAAA,CACP,YAAA,EACA,OAAA,EACA,OAAA,EACA,EAAA,EACS;AACT,EAAA,OAAOA,wBAAmB,CAAA,cAAA,KAAkB;AAC1C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAEhD,IAAA,MAAM,SAASC,QAAA,CAAK,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AAChD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAAC,kCAAA,CAAwB,cAAc,CAAA;AAEtC,IAAA,OAAOC,cAAA;AAAA,MACL;AAAA,QACE,EAAA,EAAI,YAAA;AAAA,QACJ,IAAA,EAAM,CAAA,aAAA,EAAgB,YAAA,CAAa,EAAE,CAAA,CAAA;AAAA,QACrC,UAAA,EAAY;AAAA,UACV,cAAA,EAAgB,OAAA;AAAA,UAChB,CAACC,qCAAgC,GAAG,4BAAA;AAAA,UACpC,CAACC,qCAAgC,GAAG;AAAA;AACtC,OACF;AAAA,MACA,YAAY;AACV,QAAA,IAAI;AACF,UAAA,OAAO,MAAM,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her.js');
|
|
|
8
8
|
const instrumentQueueProducer = require('./instrumentQueueProducer.js');
|
|
9
9
|
|
|
10
10
|
function isProxyable(item) {
|
|
11
|
-
return item !== null && (typeof item ===
|
|
11
|
+
return item !== null && (typeof item === "object" || typeof item === "function");
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
const instrumentedBindings = new WeakMap();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Wraps the Cloudflare `env` object in a Proxy that detects binding types
|
|
18
|
-
* on property access and returns instrumented versions.
|
|
19
|
-
*
|
|
20
|
-
* Currently detects:
|
|
21
|
-
* - DurableObjectNamespace (via `idFromName` duck-typing)
|
|
22
|
-
* - Service bindings / JSRPC proxies
|
|
23
|
-
* - Queue producers (via `send` + `sendBatch` duck-typing)
|
|
24
|
-
*
|
|
25
|
-
* Extensible for future binding types (KV, D1, etc.).
|
|
26
|
-
*
|
|
27
|
-
* @param env - The Cloudflare env object to instrument
|
|
28
|
-
* @param options - Optional CloudflareOptions to control RPC trace propagation
|
|
29
|
-
*/
|
|
13
|
+
const instrumentedBindings = /* @__PURE__ */ new WeakMap();
|
|
30
14
|
function instrumentEnv(env, options) {
|
|
31
|
-
if (!env || typeof env !==
|
|
15
|
+
if (!env || typeof env !== "object") {
|
|
32
16
|
return env;
|
|
33
17
|
}
|
|
34
|
-
|
|
35
18
|
const rpcPropagation = options ? rpcOptions.getEffectiveRpcPropagation(options) : false;
|
|
36
|
-
|
|
37
19
|
return new Proxy(env, {
|
|
38
20
|
get(target, prop, receiver) {
|
|
39
21
|
const item = Reflect.get(target, prop, receiver);
|
|
40
|
-
|
|
41
22
|
if (!isProxyable(item)) {
|
|
42
23
|
return item;
|
|
43
24
|
}
|
|
44
|
-
|
|
45
25
|
const cached = instrumentedBindings.get(item);
|
|
46
|
-
|
|
47
26
|
if (cached) {
|
|
48
27
|
return cached;
|
|
49
28
|
}
|
|
50
|
-
|
|
51
29
|
if (isBinding.isQueue(item)) {
|
|
52
|
-
const bindingName = typeof prop ===
|
|
30
|
+
const bindingName = typeof prop === "string" ? prop : String(prop);
|
|
53
31
|
const instrumented = instrumentQueueProducer.instrumentQueueProducer(item, bindingName);
|
|
54
32
|
instrumentedBindings.set(item, instrumented);
|
|
55
33
|
return instrumented;
|
|
56
34
|
}
|
|
57
|
-
|
|
58
35
|
if (!rpcPropagation) {
|
|
59
36
|
return item;
|
|
60
37
|
}
|
|
61
|
-
|
|
62
38
|
if (isBinding.isDurableObjectNamespace(item)) {
|
|
63
39
|
const instrumented = instrumentDurableObjectNamespace.instrumentDurableObjectNamespace(item);
|
|
64
40
|
instrumentedBindings.set(item, instrumented);
|
|
65
41
|
return instrumented;
|
|
66
42
|
}
|
|
67
|
-
|
|
68
43
|
if (isBinding.isJSRPC(item)) {
|
|
69
44
|
const instrumented = new Proxy(item, {
|
|
70
|
-
get(
|
|
71
|
-
const value = Reflect.get(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return instrumentFetcher.instrumentFetcher((...args) => Reflect.apply(value, target, args));
|
|
45
|
+
get(target2, p) {
|
|
46
|
+
const value = Reflect.get(target2, p);
|
|
47
|
+
if (p === "fetch" && typeof value === "function") {
|
|
48
|
+
return instrumentFetcher.instrumentFetcher((...args) => Reflect.apply(value, target2, args));
|
|
75
49
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return (...args) => Reflect.apply(value, target, rpcMeta.appendRpcMeta(args));
|
|
50
|
+
if (typeof value === "function" && typeof p === "string" && !instrumentDurableObjectNamespace.STUB_NON_RPC_METHODS.has(p)) {
|
|
51
|
+
return (...args) => Reflect.apply(value, target2, rpcMeta.appendRpcMeta(args));
|
|
79
52
|
}
|
|
80
|
-
|
|
81
53
|
return value;
|
|
82
|
-
}
|
|
54
|
+
}
|
|
83
55
|
});
|
|
84
|
-
|
|
85
56
|
instrumentedBindings.set(item, instrumented);
|
|
86
57
|
return instrumented;
|
|
87
58
|
}
|
|
88
|
-
|
|
89
59
|
return item;
|
|
90
|
-
}
|
|
60
|
+
}
|
|
91
61
|
});
|
|
92
62
|
}
|
|
93
63
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentEnv.js","sources":["../../../../src/instrumentations/worker/instrumentEnv.ts"],"sourcesContent":["import type { CloudflareOptions } from '../../client';\nimport { isDurableObjectNamespace, isJSRPC, isQueue } from '../../utils/isBinding';\nimport { appendRpcMeta } from '../../utils/rpcMeta';\nimport { getEffectiveRpcPropagation } from '../../utils/rpcOptions';\nimport { instrumentDurableObjectNamespace, STUB_NON_RPC_METHODS } from '../instrumentDurableObjectNamespace';\nimport { instrumentFetcher } from './instrumentFetcher';\nimport { instrumentQueueProducer } from './instrumentQueueProducer';\n\nfunction isProxyable(item: unknown): item is object {\n return item !== null && (typeof item === 'object' || typeof item === 'function');\n}\n\nconst instrumentedBindings = new WeakMap<object, unknown>();\n\n/**\n * Wraps the Cloudflare `env` object in a Proxy that detects binding types\n * on property access and returns instrumented versions.\n *\n * Currently detects:\n * - DurableObjectNamespace (via `idFromName` duck-typing)\n * - Service bindings / JSRPC proxies\n * - Queue producers (via `send` + `sendBatch` duck-typing)\n *\n * Extensible for future binding types (KV, D1, etc.).\n *\n * @param env - The Cloudflare env object to instrument\n * @param options - Optional CloudflareOptions to control RPC trace propagation\n */\nexport function instrumentEnv<Env extends Record<string, unknown>>(env: Env, options?: CloudflareOptions): Env {\n if (!env || typeof env !== 'object') {\n return env;\n }\n\n const rpcPropagation = options ? getEffectiveRpcPropagation(options) : false;\n\n return new Proxy(env, {\n get(target, prop, receiver) {\n const item = Reflect.get(target, prop, receiver);\n\n if (!isProxyable(item)) {\n return item;\n }\n\n const cached = instrumentedBindings.get(item);\n\n if (cached) {\n return cached;\n }\n\n if (isQueue(item)) {\n const bindingName = typeof prop === 'string' ? prop : String(prop);\n const instrumented = instrumentQueueProducer(item, bindingName);\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n if (!rpcPropagation) {\n return item;\n }\n\n if (isDurableObjectNamespace(item)) {\n const instrumented = instrumentDurableObjectNamespace(item);\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n if (isJSRPC(item)) {\n const instrumented = new Proxy(item, {\n get(target, p) {\n const value = Reflect.get(target, p);\n\n if (p === 'fetch' && typeof value === 'function') {\n return instrumentFetcher((...args) => Reflect.apply(value, target, args));\n }\n\n if (typeof value === 'function' && typeof p === 'string' && !STUB_NON_RPC_METHODS.has(p)) {\n return (...args: unknown[]) => Reflect.apply(value, target, appendRpcMeta(args));\n }\n\n return value;\n },\n });\n\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n return item;\n },\n });\n}\n"],"names":["getEffectiveRpcPropagation","isQueue","instrumentQueueProducer","isDurableObjectNamespace","instrumentDurableObjectNamespace","isJSRPC","instrumentFetcher","STUB_NON_RPC_METHODS","appendRpcMeta"],"mappings":";;;;;;;;;AAQA,SAAS,
|
|
1
|
+
{"version":3,"file":"instrumentEnv.js","sources":["../../../../src/instrumentations/worker/instrumentEnv.ts"],"sourcesContent":["import type { CloudflareOptions } from '../../client';\nimport { isDurableObjectNamespace, isJSRPC, isQueue } from '../../utils/isBinding';\nimport { appendRpcMeta } from '../../utils/rpcMeta';\nimport { getEffectiveRpcPropagation } from '../../utils/rpcOptions';\nimport { instrumentDurableObjectNamespace, STUB_NON_RPC_METHODS } from '../instrumentDurableObjectNamespace';\nimport { instrumentFetcher } from './instrumentFetcher';\nimport { instrumentQueueProducer } from './instrumentQueueProducer';\n\nfunction isProxyable(item: unknown): item is object {\n return item !== null && (typeof item === 'object' || typeof item === 'function');\n}\n\nconst instrumentedBindings = new WeakMap<object, unknown>();\n\n/**\n * Wraps the Cloudflare `env` object in a Proxy that detects binding types\n * on property access and returns instrumented versions.\n *\n * Currently detects:\n * - DurableObjectNamespace (via `idFromName` duck-typing)\n * - Service bindings / JSRPC proxies\n * - Queue producers (via `send` + `sendBatch` duck-typing)\n *\n * Extensible for future binding types (KV, D1, etc.).\n *\n * @param env - The Cloudflare env object to instrument\n * @param options - Optional CloudflareOptions to control RPC trace propagation\n */\nexport function instrumentEnv<Env extends Record<string, unknown>>(env: Env, options?: CloudflareOptions): Env {\n if (!env || typeof env !== 'object') {\n return env;\n }\n\n const rpcPropagation = options ? getEffectiveRpcPropagation(options) : false;\n\n return new Proxy(env, {\n get(target, prop, receiver) {\n const item = Reflect.get(target, prop, receiver);\n\n if (!isProxyable(item)) {\n return item;\n }\n\n const cached = instrumentedBindings.get(item);\n\n if (cached) {\n return cached;\n }\n\n if (isQueue(item)) {\n const bindingName = typeof prop === 'string' ? prop : String(prop);\n const instrumented = instrumentQueueProducer(item, bindingName);\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n if (!rpcPropagation) {\n return item;\n }\n\n if (isDurableObjectNamespace(item)) {\n const instrumented = instrumentDurableObjectNamespace(item);\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n if (isJSRPC(item)) {\n const instrumented = new Proxy(item, {\n get(target, p) {\n const value = Reflect.get(target, p);\n\n if (p === 'fetch' && typeof value === 'function') {\n return instrumentFetcher((...args) => Reflect.apply(value, target, args));\n }\n\n if (typeof value === 'function' && typeof p === 'string' && !STUB_NON_RPC_METHODS.has(p)) {\n return (...args: unknown[]) => Reflect.apply(value, target, appendRpcMeta(args));\n }\n\n return value;\n },\n });\n\n instrumentedBindings.set(item, instrumented);\n return instrumented;\n }\n\n return item;\n },\n });\n}\n"],"names":["getEffectiveRpcPropagation","isQueue","instrumentQueueProducer","isDurableObjectNamespace","instrumentDurableObjectNamespace","isJSRPC","target","instrumentFetcher","STUB_NON_RPC_METHODS","appendRpcMeta"],"mappings":";;;;;;;;;AAQA,SAAS,YAAY,IAAA,EAA+B;AAClD,EAAA,OAAO,SAAS,IAAA,KAAS,OAAO,IAAA,KAAS,QAAA,IAAY,OAAO,IAAA,KAAS,UAAA,CAAA;AACvE;AAEA,MAAM,oBAAA,uBAA2B,OAAA,EAAyB;AAgBnD,SAAS,aAAA,CAAmD,KAA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