@sentry/cloudflare 10.53.1 → 10.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/build/cjs/async.js +4 -30
  2. package/build/cjs/async.js.map +1 -1
  3. package/build/cjs/client.js +31 -58
  4. package/build/cjs/client.js.map +1 -1
  5. package/build/cjs/d1.js +26 -80
  6. package/build/cjs/d1.js.map +1 -1
  7. package/build/cjs/debug-build.js +0 -5
  8. package/build/cjs/debug-build.js.map +1 -1
  9. package/build/cjs/durableobject.js +44 -131
  10. package/build/cjs/durableobject.js.map +1 -1
  11. package/build/cjs/flush.js +47 -34
  12. package/build/cjs/flush.js.map +1 -1
  13. package/build/cjs/instrument.js +7 -48
  14. package/build/cjs/instrument.js.map +1 -1
  15. package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js +9 -34
  16. package/build/cjs/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  17. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js +20 -54
  18. package/build/cjs/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  19. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js +12 -66
  20. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  21. package/build/cjs/instrumentations/worker/instrumentEmail.js +21 -43
  22. package/build/cjs/instrumentations/worker/instrumentEmail.js.map +1 -1
  23. package/build/cjs/instrumentations/worker/instrumentEnv.js +12 -42
  24. package/build/cjs/instrumentations/worker/instrumentEnv.js.map +1 -1
  25. package/build/cjs/instrumentations/worker/instrumentFetch.js +20 -34
  26. package/build/cjs/instrumentations/worker/instrumentFetch.js.map +1 -1
  27. package/build/cjs/instrumentations/worker/instrumentFetcher.js +5 -19
  28. package/build/cjs/instrumentations/worker/instrumentFetcher.js.map +1 -1
  29. package/build/cjs/instrumentations/worker/instrumentQueue.js +30 -62
  30. package/build/cjs/instrumentations/worker/instrumentQueue.js.map +1 -1
  31. package/build/cjs/instrumentations/worker/instrumentQueueProducer.js +31 -57
  32. package/build/cjs/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  33. package/build/cjs/instrumentations/worker/instrumentScheduled.js +25 -54
  34. package/build/cjs/instrumentations/worker/instrumentScheduled.js.map +1 -1
  35. package/build/cjs/instrumentations/worker/instrumentTail.js +16 -43
  36. package/build/cjs/instrumentations/worker/instrumentTail.js.map +1 -1
  37. package/build/cjs/integrations/fetch.js +24 -56
  38. package/build/cjs/integrations/fetch.js.map +1 -1
  39. package/build/cjs/integrations/hono.js +7 -38
  40. package/build/cjs/integrations/hono.js.map +1 -1
  41. package/build/cjs/integrations/httpServer.js +6 -39
  42. package/build/cjs/integrations/httpServer.js.map +1 -1
  43. package/build/cjs/integrations/tracing/vercelai.js +3 -31
  44. package/build/cjs/integrations/tracing/vercelai.js.map +1 -1
  45. package/build/cjs/opentelemetry/tracer.js +17 -45
  46. package/build/cjs/opentelemetry/tracer.js.map +1 -1
  47. package/build/cjs/options.js +10 -46
  48. package/build/cjs/options.js.map +1 -1
  49. package/build/cjs/pages-plugin.js +9 -42
  50. package/build/cjs/pages-plugin.js.map +1 -1
  51. package/build/cjs/request.js +21 -67
  52. package/build/cjs/request.js.map +1 -1
  53. package/build/cjs/scope-utils.js +4 -15
  54. package/build/cjs/scope-utils.js.map +1 -1
  55. package/build/cjs/sdk.js +8 -25
  56. package/build/cjs/sdk.js.map +1 -1
  57. package/build/cjs/transport.js +14 -48
  58. package/build/cjs/transport.js.map +1 -1
  59. package/build/cjs/utils/instrumentContext.js +16 -52
  60. package/build/cjs/utils/instrumentContext.js.map +1 -1
  61. package/build/cjs/utils/isBinding.js +3 -23
  62. package/build/cjs/utils/isBinding.js.map +1 -1
  63. package/build/cjs/utils/isCloudflareClass.js +2 -8
  64. package/build/cjs/utils/isCloudflareClass.js.map +1 -1
  65. package/build/cjs/utils/rpcMeta.js +8 -32
  66. package/build/cjs/utils/rpcMeta.js.map +1 -1
  67. package/build/cjs/utils/rpcOptions.js +9 -32
  68. package/build/cjs/utils/rpcOptions.js.map +1 -1
  69. package/build/cjs/utils/streaming.js +3 -29
  70. package/build/cjs/utils/streaming.js.map +1 -1
  71. package/build/cjs/utils/traceLinks.js +8 -33
  72. package/build/cjs/utils/traceLinks.js.map +1 -1
  73. package/build/cjs/vendor/stacktrace.js +6 -27
  74. package/build/cjs/vendor/stacktrace.js.map +1 -1
  75. package/build/cjs/withSentry.js +16 -47
  76. package/build/cjs/withSentry.js.map +1 -1
  77. package/build/cjs/workflows.js +40 -100
  78. package/build/cjs/workflows.js.map +1 -1
  79. package/build/cjs/wrapMethodWithSentry.js +110 -167
  80. package/build/cjs/wrapMethodWithSentry.js.map +1 -1
  81. package/build/esm/async.js +4 -30
  82. package/build/esm/async.js.map +1 -1
  83. package/build/esm/client.js +31 -58
  84. package/build/esm/client.js.map +1 -1
  85. package/build/esm/d1.js +26 -80
  86. package/build/esm/d1.js.map +1 -1
  87. package/build/esm/debug-build.js +0 -5
  88. package/build/esm/debug-build.js.map +1 -1
  89. package/build/esm/durableobject.js +44 -131
  90. package/build/esm/durableobject.js.map +1 -1
  91. package/build/esm/flush.js +47 -34
  92. package/build/esm/flush.js.map +1 -1
  93. package/build/esm/instrument.js +7 -48
  94. package/build/esm/instrument.js.map +1 -1
  95. package/build/esm/instrumentations/instrumentDurableObjectNamespace.js +9 -34
  96. package/build/esm/instrumentations/instrumentDurableObjectNamespace.js.map +1 -1
  97. package/build/esm/instrumentations/instrumentDurableObjectStorage.js +20 -54
  98. package/build/esm/instrumentations/instrumentDurableObjectStorage.js.map +1 -1
  99. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js +12 -66
  100. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js.map +1 -1
  101. package/build/esm/instrumentations/worker/instrumentEmail.js +21 -43
  102. package/build/esm/instrumentations/worker/instrumentEmail.js.map +1 -1
  103. package/build/esm/instrumentations/worker/instrumentEnv.js +12 -42
  104. package/build/esm/instrumentations/worker/instrumentEnv.js.map +1 -1
  105. package/build/esm/instrumentations/worker/instrumentFetch.js +20 -34
  106. package/build/esm/instrumentations/worker/instrumentFetch.js.map +1 -1
  107. package/build/esm/instrumentations/worker/instrumentFetcher.js +5 -19
  108. package/build/esm/instrumentations/worker/instrumentFetcher.js.map +1 -1
  109. package/build/esm/instrumentations/worker/instrumentQueue.js +30 -62
  110. package/build/esm/instrumentations/worker/instrumentQueue.js.map +1 -1
  111. package/build/esm/instrumentations/worker/instrumentQueueProducer.js +31 -57
  112. package/build/esm/instrumentations/worker/instrumentQueueProducer.js.map +1 -1
  113. package/build/esm/instrumentations/worker/instrumentScheduled.js +25 -54
  114. package/build/esm/instrumentations/worker/instrumentScheduled.js.map +1 -1
  115. package/build/esm/instrumentations/worker/instrumentTail.js +16 -43
  116. package/build/esm/instrumentations/worker/instrumentTail.js.map +1 -1
  117. package/build/esm/integrations/fetch.js +24 -56
  118. package/build/esm/integrations/fetch.js.map +1 -1
  119. package/build/esm/integrations/hono.js +7 -38
  120. package/build/esm/integrations/hono.js.map +1 -1
  121. package/build/esm/integrations/httpServer.js +6 -39
  122. package/build/esm/integrations/httpServer.js.map +1 -1
  123. package/build/esm/integrations/tracing/vercelai.js +3 -31
  124. package/build/esm/integrations/tracing/vercelai.js.map +1 -1
  125. package/build/esm/opentelemetry/tracer.js +17 -45
  126. package/build/esm/opentelemetry/tracer.js.map +1 -1
  127. package/build/esm/options.js +10 -46
  128. package/build/esm/options.js.map +1 -1
  129. package/build/esm/package.json +1 -1
  130. package/build/esm/pages-plugin.js +9 -42
  131. package/build/esm/pages-plugin.js.map +1 -1
  132. package/build/esm/request.js +21 -67
  133. package/build/esm/request.js.map +1 -1
  134. package/build/esm/scope-utils.js +4 -15
  135. package/build/esm/scope-utils.js.map +1 -1
  136. package/build/esm/sdk.js +8 -25
  137. package/build/esm/sdk.js.map +1 -1
  138. package/build/esm/transport.js +14 -48
  139. package/build/esm/transport.js.map +1 -1
  140. package/build/esm/utils/instrumentContext.js +16 -52
  141. package/build/esm/utils/instrumentContext.js.map +1 -1
  142. package/build/esm/utils/isBinding.js +3 -23
  143. package/build/esm/utils/isBinding.js.map +1 -1
  144. package/build/esm/utils/isCloudflareClass.js +2 -8
  145. package/build/esm/utils/isCloudflareClass.js.map +1 -1
  146. package/build/esm/utils/rpcMeta.js +8 -32
  147. package/build/esm/utils/rpcMeta.js.map +1 -1
  148. package/build/esm/utils/rpcOptions.js +9 -32
  149. package/build/esm/utils/rpcOptions.js.map +1 -1
  150. package/build/esm/utils/streaming.js +3 -29
  151. package/build/esm/utils/streaming.js.map +1 -1
  152. package/build/esm/utils/traceLinks.js +8 -33
  153. package/build/esm/utils/traceLinks.js.map +1 -1
  154. package/build/esm/vendor/stacktrace.js +6 -27
  155. package/build/esm/vendor/stacktrace.js.map +1 -1
  156. package/build/esm/withSentry.js +16 -47
  157. package/build/esm/withSentry.js.map +1 -1
  158. package/build/esm/workflows.js +40 -100
  159. package/build/esm/workflows.js.map +1 -1
  160. package/build/esm/wrapMethodWithSentry.js +110 -167
  161. package/build/esm/wrapMethodWithSentry.js.map +1 -1
  162. package/build/types/client.d.ts.map +1 -1
  163. package/build/types/flush.d.ts.map +1 -1
  164. package/build/types/instrumentations/worker/instrumentFetch.d.ts.map +1 -1
  165. package/build/types/pages-plugin.d.ts.map +1 -1
  166. package/package.json +2 -2
@@ -10,182 +10,95 @@ const instrumentContext = require('./utils/instrumentContext.js');
10
10
  const rpcOptions = require('./utils/rpcOptions.js');
11
11
  const wrapMethodWithSentry = require('./wrapMethodWithSentry.js');
12
12
 
13
- /* eslint-disable @typescript-eslint/unbound-method */
14
-
15
- const BUILT_IN_DO_METHODS = new Set([
16
- 'constructor',
17
- 'fetch',
18
- 'alarm',
19
- 'webSocketError',
20
- 'webSocketClose',
21
- 'webSocketMessage',
13
+ const BUILT_IN_DO_METHODS = /* @__PURE__ */ new Set([
14
+ "constructor",
15
+ "fetch",
16
+ "alarm",
17
+ "webSocketError",
18
+ "webSocketClose",
19
+ "webSocketMessage"
22
20
  ]);
23
-
24
- /**
25
- * Instruments a Durable Object class to capture errors and performance data.
26
- *
27
- * Instruments the following methods by default:
28
- * - fetch
29
- * - alarm
30
- * - webSocketMessage
31
- * - webSocketClose
32
- * - webSocketError
33
- *
34
- * To instrument RPC methods (prototype methods), enable the `enableRpcTracePropagation` option.
35
- *
36
- * @param optionsCallback Function that returns the options for the SDK initialization.
37
- * @param DurableObjectClass The Durable Object class to instrument.
38
- * @returns The instrumented Durable Object class.
39
- *
40
- * @example
41
- * ```ts
42
- * class MyDurableObjectBase extends DurableObject {
43
- * constructor(ctx: DurableObjectState, env: Env) {
44
- * super(ctx, env);
45
- * }
46
- * }
47
- *
48
- * export const MyDurableObject = instrumentDurableObjectWithSentry(
49
- * env => ({
50
- * dsn: env.SENTRY_DSN,
51
- * tracesSampleRate: 1.0,
52
- * }),
53
- * MyDurableObjectBase,
54
- * );
55
- * ```
56
- */
57
- function instrumentDurableObjectWithSentry
58
-
59
- (optionsCallback, DurableObjectClass) {
21
+ function instrumentDurableObjectWithSentry(optionsCallback, DurableObjectClass) {
60
22
  return new Proxy(DurableObjectClass, {
61
23
  construct(target, [ctx, env]) {
62
24
  async.setAsyncLocalStorageAsyncContextStrategy();
63
25
  const context = instrumentContext.instrumentContext(ctx);
64
26
  const options$1 = options.getFinalOptions(optionsCallback(env), env);
65
27
  const instrumentedEnv = instrumentEnv.instrumentEnv(env, options$1);
66
-
67
28
  const obj = new target(context, instrumentedEnv);
68
-
69
- // These are the methods that are available on a Durable Object
70
- // ref: https://developers.cloudflare.com/durable-objects/api/base/
71
- // obj.alarm
72
- // obj.fetch
73
- // obj.webSocketError
74
- // obj.webSocketClose
75
- // obj.webSocketMessage
76
-
77
- // Any other public methods on the Durable Object instance are RPC calls.
78
-
79
- if (obj.fetch && typeof obj.fetch === 'function') {
29
+ if (obj.fetch && typeof obj.fetch === "function") {
80
30
  obj.fetch = instrument.ensureInstrumented(
81
31
  obj.fetch,
82
- original =>
83
- new Proxy(original, {
84
- apply(target, thisArg, args) {
85
- return request.wrapRequestHandler({ options: options$1, request: args[0], context }, () => {
86
- return Reflect.apply(target, thisArg, args);
87
- });
88
- },
89
- }),
32
+ (original) => new Proxy(original, {
33
+ apply(target2, thisArg, args) {
34
+ return request.wrapRequestHandler({ options: options$1, request: args[0], context }, () => {
35
+ return Reflect.apply(target2, thisArg, args);
36
+ });
37
+ }
38
+ })
90
39
  );
91
40
  }
92
-
93
- if (obj.alarm && typeof obj.alarm === 'function') {
94
- // Alarms are independent invocations, so we start a new trace and link to the previous alarm
41
+ if (obj.alarm && typeof obj.alarm === "function") {
95
42
  obj.alarm = wrapMethodWithSentry.wrapMethodWithSentry(
96
- { options: options$1, context, spanName: 'alarm', spanOp: 'function', startNewTrace: true },
97
- obj.alarm,
43
+ { options: options$1, context, spanName: "alarm", spanOp: "function", startNewTrace: true },
44
+ obj.alarm
98
45
  );
99
46
  }
100
-
101
- if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {
47
+ if (obj.webSocketMessage && typeof obj.webSocketMessage === "function") {
102
48
  obj.webSocketMessage = wrapMethodWithSentry.wrapMethodWithSentry(
103
- { options: options$1, context, spanName: 'webSocketMessage' },
104
- obj.webSocketMessage,
49
+ { options: options$1, context, spanName: "webSocketMessage" },
50
+ obj.webSocketMessage
105
51
  );
106
52
  }
107
-
108
- if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {
109
- obj.webSocketClose = wrapMethodWithSentry.wrapMethodWithSentry({ options: options$1, context, spanName: 'webSocketClose' }, obj.webSocketClose);
53
+ if (obj.webSocketClose && typeof obj.webSocketClose === "function") {
54
+ obj.webSocketClose = wrapMethodWithSentry.wrapMethodWithSentry({ options: options$1, context, spanName: "webSocketClose" }, obj.webSocketClose);
110
55
  }
111
-
112
- if (obj.webSocketError && typeof obj.webSocketError === 'function') {
56
+ if (obj.webSocketError && typeof obj.webSocketError === "function") {
113
57
  obj.webSocketError = wrapMethodWithSentry.wrapMethodWithSentry(
114
- { options: options$1, context, spanName: 'webSocketError' },
58
+ { options: options$1, context, spanName: "webSocketError" },
115
59
  obj.webSocketError,
116
- (_, error) =>
117
- core.captureException(error, {
118
- mechanism: {
119
- type: 'auto.faas.cloudflare.durable_object_websocket',
120
- handled: false,
121
- },
122
- }),
60
+ (_, error) => core.captureException(error, {
61
+ mechanism: {
62
+ type: "auto.faas.cloudflare.durable_object_websocket",
63
+ handled: false
64
+ }
65
+ })
123
66
  );
124
67
  }
125
-
126
- // Get effective RPC propagation setting (handles deprecation of instrumentPrototypeMethods)
127
68
  const rpcPropagation = rpcOptions.getEffectiveRpcPropagation(options$1);
128
-
129
- // Skip RPC instrumentation if not enabled
130
69
  if (!rpcPropagation) {
131
70
  return obj;
132
71
  }
133
-
134
- // If `instrumentPrototypeMethods` was passed as an array (deprecated),
135
- // only the listed method names should be instrumented.
136
- const instrumentPrototypeMethods = Array.isArray(options$1.instrumentPrototypeMethods)
137
- ? options$1.instrumentPrototypeMethods
138
- : undefined;
72
+ const instrumentPrototypeMethods = Array.isArray(options$1.instrumentPrototypeMethods) ? options$1.instrumentPrototypeMethods : void 0;
139
73
  const allowSet = instrumentPrototypeMethods ? new Set(instrumentPrototypeMethods) : null;
140
-
141
- // Return a Proxy that lazily wraps prototype methods on access.
142
- // This avoids iterating the prototype chain at construction time —
143
- // we only check if a property is an RPC method when it's accessed.
144
- const rpcMethodCache = new Map();
145
-
74
+ const rpcMethodCache = /* @__PURE__ */ new Map();
146
75
  return new Proxy(obj, {
147
76
  get(proxyTarget, prop, receiver) {
148
77
  const value = Reflect.get(proxyTarget, prop, receiver);
149
-
150
- if (typeof prop !== 'string' || BUILT_IN_DO_METHODS.has(prop)) {
78
+ if (typeof prop !== "string" || BUILT_IN_DO_METHODS.has(prop)) {
151
79
  return value;
152
80
  }
153
-
154
81
  const cached = rpcMethodCache.get(prop);
155
-
156
82
  if (cached) {
157
83
  return cached;
158
84
  }
159
-
160
- if (
161
- typeof value !== 'function' ||
162
- Object.prototype.hasOwnProperty.call(proxyTarget, prop) ||
163
- (allowSet && !allowSet.has(prop)) ||
164
- // Exclude inherited Object.prototype methods (toString, valueOf, etc.)
165
- // These are not RPC methods and should not create spans
166
- prop in Object.prototype
167
- ) {
85
+ if (typeof value !== "function" || Object.prototype.hasOwnProperty.call(proxyTarget, prop) || allowSet && !allowSet.has(prop) || // Exclude inherited Object.prototype methods (toString, valueOf, etc.)
86
+ // These are not RPC methods and should not create spans
87
+ prop in Object.prototype) {
168
88
  return value;
169
89
  }
170
-
171
- // Bind the method to the original object to ensure private fields work correctly.
172
- // When called via the Proxy, `this` would be the Proxy, but private fields require
173
- // the original object. Bound functions ignore the thisArg passed via Reflect.apply.
174
- const boundValue = (value ).bind(proxyTarget);
175
-
90
+ const boundValue = value.bind(proxyTarget);
176
91
  const wrapped = wrapMethodWithSentry.wrapMethodWithSentry(
177
- { options: options$1, context, spanName: prop, spanOp: 'rpc' },
92
+ { options: options$1, context, spanName: prop, spanOp: "rpc" },
178
93
  boundValue,
179
- undefined,
180
- true,
94
+ void 0,
95
+ true
181
96
  );
182
-
183
97
  rpcMethodCache.set(prop, wrapped);
184
-
185
98
  return wrapped;
186
- },
99
+ }
187
100
  });
188
- },
101
+ }
189
102
  });
190
103
  }
191
104
 
@@ -1 +1 @@
1
- {"version":3,"file":"durableobject.js","sources":["../../src/durableobject.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\nimport { captureException } from '@sentry/core';\nimport type { DurableObject } from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { ensureInstrumented } from './instrument';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { instrumentContext } from './utils/instrumentContext';\nimport { getEffectiveRpcPropagation } from './utils/rpcOptions';\nimport { type UncheckedMethod, wrapMethodWithSentry } from './wrapMethodWithSentry';\n\nconst BUILT_IN_DO_METHODS = new Set([\n 'constructor',\n 'fetch',\n 'alarm',\n 'webSocketError',\n 'webSocketClose',\n 'webSocketMessage',\n]);\n\n/**\n * Instruments a Durable Object class to capture errors and performance data.\n *\n * Instruments the following methods by default:\n * - fetch\n * - alarm\n * - webSocketMessage\n * - webSocketClose\n * - webSocketError\n *\n * To instrument RPC methods (prototype methods), enable the `enableRpcTracePropagation` option.\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<\n E,\n T extends DurableObject<E>,\n C extends new (state: DurableObjectState, env: E) => T,\n>(optionsCallback: (env: E) => CloudflareOptions, DurableObjectClass: C): C {\n return new Proxy(DurableObjectClass, {\n construct(target, [ctx, env]) {\n setAsyncLocalStorageAsyncContextStrategy();\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n const instrumentedEnv = instrumentEnv(env, options);\n\n const obj = new target(context, instrumentedEnv);\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') {\n obj.fetch = ensureInstrumented(\n obj.fetch,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args) {\n return wrapRequestHandler({ options, request: args[0], context }, () => {\n return Reflect.apply(target, thisArg, args);\n });\n },\n }),\n );\n }\n\n if (obj.alarm && typeof obj.alarm === 'function') {\n // Alarms are independent invocations, so we start a new trace and link to the previous alarm\n obj.alarm = wrapMethodWithSentry(\n { options, context, spanName: 'alarm', spanOp: 'function', startNewTrace: true },\n obj.alarm,\n );\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: 'auto.faas.cloudflare.durable_object_websocket',\n handled: false,\n },\n }),\n );\n }\n\n // Get effective RPC propagation setting (handles deprecation of instrumentPrototypeMethods)\n const rpcPropagation = getEffectiveRpcPropagation(options);\n\n // Skip RPC instrumentation if not enabled\n if (!rpcPropagation) {\n return obj;\n }\n\n // If `instrumentPrototypeMethods` was passed as an array (deprecated),\n // only the listed method names should be instrumented.\n const instrumentPrototypeMethods = Array.isArray(options.instrumentPrototypeMethods)\n ? options.instrumentPrototypeMethods\n : undefined;\n const allowSet = instrumentPrototypeMethods ? new Set(instrumentPrototypeMethods) : null;\n\n // Return a Proxy that lazily wraps prototype methods on access.\n // This avoids iterating the prototype chain at construction time —\n // we only check if a property is an RPC method when it's accessed.\n const rpcMethodCache = new Map<string, UncheckedMethod>();\n\n return new Proxy(obj, {\n get(proxyTarget, prop, receiver) {\n const value = Reflect.get(proxyTarget, prop, receiver);\n\n if (typeof prop !== 'string' || BUILT_IN_DO_METHODS.has(prop)) {\n return value;\n }\n\n const cached = rpcMethodCache.get(prop);\n\n if (cached) {\n return cached;\n }\n\n if (\n typeof value !== 'function' ||\n Object.prototype.hasOwnProperty.call(proxyTarget, prop) ||\n (allowSet && !allowSet.has(prop)) ||\n // Exclude inherited Object.prototype methods (toString, valueOf, etc.)\n // These are not RPC methods and should not create spans\n prop in Object.prototype\n ) {\n return value;\n }\n\n // Bind the method to the original object to ensure private fields work correctly.\n // When called via the Proxy, `this` would be the Proxy, but private fields require\n // the original object. Bound functions ignore the thisArg passed via Reflect.apply.\n const boundValue = (value as UncheckedMethod).bind(proxyTarget);\n\n const wrapped = wrapMethodWithSentry(\n { options, context, spanName: prop, spanOp: 'rpc' },\n boundValue,\n undefined,\n true,\n );\n\n rpcMethodCache.set(prop, wrapped);\n\n return wrapped;\n },\n });\n },\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","instrumentEnv","ensureInstrumented","wrapRequestHandler","wrapMethodWithSentry","captureException","getEffectiveRpcPropagation"],"mappings":";;;;;;;;;;;;AAAA;;AAaA,MAAM,mBAAA,GAAsB,IAAI,GAAG,CAAC;AACpC,EAAE,aAAa;AACf,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,gBAAgB;AAClB,EAAE,gBAAgB;AAClB,EAAE,kBAAkB;AACpB,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS;;AAIhB,CAAE,eAAe,EAAiC,kBAAkB,EAAQ;AAC5E,EAAE,OAAO,IAAI,KAAK,CAAC,kBAAkB,EAAE;AACvC,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;AAClC,MAAMA,8CAAwC,EAAE;AAChD,MAAM,MAAM,OAAA,GAAUC,mCAAiB,CAAC,GAAG,CAAC;AAC5C,MAAM,MAAMC,SAAA,GAAUC,uBAAe,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;AAChE,MAAM,MAAM,k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object.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/unbound-method */\nimport { captureException } from '@sentry/core';\nimport type { DurableObject } from 'cloudflare:workers';\nimport { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { ensureInstrumented } from './instrument';\nimport { instrumentEnv } from './instrumentations/worker/instrumentEnv';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { instrumentContext } from './utils/instrumentContext';\nimport { getEffectiveRpcPropagation } from './utils/rpcOptions';\nimport { type UncheckedMethod, wrapMethodWithSentry } from './wrapMethodWithSentry';\n\nconst BUILT_IN_DO_METHODS = new Set([\n 'constructor',\n 'fetch',\n 'alarm',\n 'webSocketError',\n 'webSocketClose',\n 'webSocketMessage',\n]);\n\n/**\n * Instruments a Durable Object class to capture errors and performance data.\n *\n * Instruments the following methods by default:\n * - fetch\n * - alarm\n * - webSocketMessage\n * - webSocketClose\n * - webSocketError\n *\n * To instrument RPC methods (prototype methods), enable the `enableRpcTracePropagation` option.\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<\n E,\n T extends DurableObject<E>,\n C extends new (state: DurableObjectState, env: E) => T,\n>(optionsCallback: (env: E) => CloudflareOptions, DurableObjectClass: C): C {\n return new Proxy(DurableObjectClass, {\n construct(target, [ctx, env]) {\n setAsyncLocalStorageAsyncContextStrategy();\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n const instrumentedEnv = instrumentEnv(env, options);\n\n const obj = new target(context, instrumentedEnv);\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') {\n obj.fetch = ensureInstrumented(\n obj.fetch,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args) {\n return wrapRequestHandler({ options, request: args[0], context }, () => {\n return Reflect.apply(target, thisArg, args);\n });\n },\n }),\n );\n }\n\n if (obj.alarm && typeof obj.alarm === 'function') {\n // Alarms are independent invocations, so we start a new trace and link to the previous alarm\n obj.alarm = wrapMethodWithSentry(\n { options, context, spanName: 'alarm', spanOp: 'function', startNewTrace: true },\n obj.alarm,\n );\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: 'auto.faas.cloudflare.durable_object_websocket',\n handled: false,\n },\n }),\n );\n }\n\n // Get effective RPC propagation setting (handles deprecation of instrumentPrototypeMethods)\n const rpcPropagation = getEffectiveRpcPropagation(options);\n\n // Skip RPC instrumentation if not enabled\n if (!rpcPropagation) {\n return obj;\n }\n\n // If `instrumentPrototypeMethods` was passed as an array (deprecated),\n // only the listed method names should be instrumented.\n const instrumentPrototypeMethods = Array.isArray(options.instrumentPrototypeMethods)\n ? options.instrumentPrototypeMethods\n : undefined;\n const allowSet = instrumentPrototypeMethods ? new Set(instrumentPrototypeMethods) : null;\n\n // Return a Proxy that lazily wraps prototype methods on access.\n // This avoids iterating the prototype chain at construction time —\n // we only check if a property is an RPC method when it's accessed.\n const rpcMethodCache = new Map<string, UncheckedMethod>();\n\n return new Proxy(obj, {\n get(proxyTarget, prop, receiver) {\n const value = Reflect.get(proxyTarget, prop, receiver);\n\n if (typeof prop !== 'string' || BUILT_IN_DO_METHODS.has(prop)) {\n return value;\n }\n\n const cached = rpcMethodCache.get(prop);\n\n if (cached) {\n return cached;\n }\n\n if (\n typeof value !== 'function' ||\n Object.prototype.hasOwnProperty.call(proxyTarget, prop) ||\n (allowSet && !allowSet.has(prop)) ||\n // Exclude inherited Object.prototype methods (toString, valueOf, etc.)\n // These are not RPC methods and should not create spans\n prop in Object.prototype\n ) {\n return value;\n }\n\n // Bind the method to the original object to ensure private fields work correctly.\n // When called via the Proxy, `this` would be the Proxy, but private fields require\n // the original object. Bound functions ignore the thisArg passed via Reflect.apply.\n const boundValue = (value as UncheckedMethod).bind(proxyTarget);\n\n const wrapped = wrapMethodWithSentry(\n { options, context, spanName: prop, spanOp: 'rpc' },\n boundValue,\n undefined,\n true,\n );\n\n rpcMethodCache.set(prop, wrapped);\n\n return wrapped;\n },\n });\n },\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","instrumentEnv","ensureInstrumented","target","wrapRequestHandler","wrapMethodWithSentry","captureException","getEffectiveRpcPropagation"],"mappings":";;;;;;;;;;;;AAaA,MAAM,mBAAA,uBAA0B,GAAA,CAAI;AAAA,EAClC,aAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACF,CAAC,CAAA;AAmCM,SAAS,iCAAA,CAId,iBAAgD,kBAAA,EAA0B;AAC1E,EAAA,OAAO,IAAI,MAAM,kBAAA,EAAoB;AAAA,IACnC,SAAA,CAAU,MAAA,EAAQ,CAAC,GAAA,EAAK,GAAG,CA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EAAM,QAAA,EAAU;AAC/B,UAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AAErD,UAAA,IAAI,OAAO,IAAA,KAAS,QAAA,IAAY,mBAAA,CAAoB,GAAA,CAAI,IAAI,CAAA,EAAG;AAC7D,YAAA,OAAO,KAAA;AAAA,UACT;AAEA,UAAA,MAAM,MAAA,GAAS,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAEtC,UAAA,IAAI,MAAA,EAAQ;AACV,YAAA,OAAO,MAAA;AAAA,UACT;AAEA,UAAA,IACE,OAAO,KAAA,KAAU,UAAA,IACjB,MAAA,CAAO,UAAU,cAAA,CAAe,IAAA,CAAK,WAAA,EAAa,IAAI,CAAA,IACrD,QAAA,IAAY,CAAC,QAAA,CAAS,IAAI,IAAI,CAAA;AAAA;AAAA,UAG/B,IAAA,IAAQ,OAAO,SAAA,EACf;AACA,YAAA,OAAO,KAAA;AAAA,UACT;AAKA,UAAA,MAAM,UAAA,GAAc,KAAA,CAA0B,IAAA,CAAK,WAAW,CAAA;AAE9D,UAAA,MAAM,OAAA,GAAUM,yCAAA;AAAA,YACd,WAAEN,SAAA,EAAS,OAAA,EAAS,QAAA,EAAU,IAAA,EAAM,QAAQ,KAAA,EAAM;AAAA,YAClD,UAAA;AAAA,YACA,KAAA,CAAA;AAAA,YACA;AAAA,WACF;AAEA,UAAA,cAAA,CAAe,GAAA,CAAI,MAAM,OAAO,CAAA;AAEhC,UAAA,OAAO,OAAA;AAAA,QACT;AAAA,OACD,CAAA;AAAA,IACH;AAAA,GACD,CAAA;AACH;;;;"}
@@ -2,53 +2,66 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const core = require('@sentry/core');
4
4
 
5
- /**
6
- * Enhances the given execution context by wrapping its `waitUntil` method with a proxy
7
- * to monitor pending tasks, and provides a flusher function to ensure all tasks
8
- * have been completed before executing any subsequent logic.
9
- *
10
- * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.
11
- * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.
12
- */
5
+ const flushLockRegistries = /* @__PURE__ */ new WeakMap();
13
6
  function makeFlushLock(context) {
14
- let resolveAllDone = () => undefined;
15
- const allDone = new Promise(res => {
7
+ const registry = getOrCreateFlushLockRegistry(context);
8
+ let resolveAllDone = () => void 0;
9
+ const allDone = new Promise((res) => {
16
10
  resolveAllDone = res;
17
11
  });
18
12
  let pending = 0;
19
- const originalWaitUntil = context.waitUntil.bind(context) ;
20
- context.waitUntil = promise => {
21
- pending++;
13
+ const lock = {
14
+ ready: allDone,
15
+ acquire: () => {
16
+ pending++;
17
+ },
18
+ release: () => {
19
+ if (--pending === 0) {
20
+ registry.locks.delete(lock);
21
+ resolveAllDone();
22
+ }
23
+ },
24
+ finalize: () => {
25
+ if (pending === 0) {
26
+ registry.locks.delete(lock);
27
+ resolveAllDone();
28
+ }
29
+ return allDone;
30
+ }
31
+ };
32
+ registry.locks.add(lock);
33
+ return Object.freeze(lock);
34
+ }
35
+ function getOrCreateFlushLockRegistry(context) {
36
+ const waitUntil = context.waitUntil;
37
+ const existingRegistry = flushLockRegistries.get(waitUntil);
38
+ if (existingRegistry) {
39
+ return existingRegistry;
40
+ }
41
+ const registry = { locks: /* @__PURE__ */ new Set() };
42
+ const originalWaitUntil = context.waitUntil.bind(context);
43
+ const instrumentedWaitUntil = (promise) => {
44
+ const locks = [...registry.locks];
45
+ for (const lock of locks) {
46
+ lock.acquire();
47
+ }
22
48
  return originalWaitUntil(
23
49
  promise.finally(() => {
24
- if (--pending === 0) resolveAllDone();
25
- }),
50
+ for (const lock of locks) {
51
+ lock.release();
52
+ }
53
+ })
26
54
  );
27
55
  };
28
- return Object.freeze({
29
- ready: allDone,
30
- finalize: () => {
31
- if (pending === 0) resolveAllDone();
32
- return allDone;
33
- },
34
- });
56
+ flushLockRegistries.set(instrumentedWaitUntil, registry);
57
+ context.waitUntil = instrumentedWaitUntil;
58
+ return registry;
35
59
  }
36
-
37
- /**
38
- * Flushes the client and then disposes of it to allow garbage collection.
39
- * This should be called at the end of each request to prevent memory leaks.
40
- *
41
- * @param client - The CloudflareClient instance to flush and dispose
42
- * @param timeout - Timeout in milliseconds for the flush operation
43
- * @returns A promise that resolves when flush and dispose are complete
44
- */
45
- async function flushAndDispose(client, timeout = 2000) {
60
+ async function flushAndDispose(client, timeout = 2e3) {
46
61
  if (!client) {
47
62
  await core.flush(timeout);
48
-
49
63
  return;
50
64
  }
51
-
52
65
  await client.flush(timeout);
53
66
  client.dispose();
54
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"flush.js","sources":["../../src/flush.ts"],"sourcesContent":["import type { ExecutionContext } from '@cloudflare/workers-types';\nimport type { Client } from '@sentry/core';\nimport { flush } from '@sentry/core';\n\ntype FlushLock = {\n readonly ready: Promise<void>;\n readonly finalize: () => Promise<void>;\n};\n\n/**\n * Enhances the given execution context by wrapping its `waitUntil` method with a proxy\n * to monitor pending tasks, and provides a flusher function to ensure all tasks\n * have been completed before executing any subsequent logic.\n *\n * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.\n * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.\n */\nexport function makeFlushLock(context: ExecutionContext): FlushLock {\n let resolveAllDone: () => void = () => undefined;\n const allDone = new Promise<void>(res => {\n resolveAllDone = res;\n });\n let pending = 0;\n const originalWaitUntil = context.waitUntil.bind(context) as typeof context.waitUntil;\n context.waitUntil = promise => {\n pending++;\n return originalWaitUntil(\n promise.finally(() => {\n if (--pending === 0) resolveAllDone();\n }),\n );\n };\n return Object.freeze({\n ready: allDone,\n finalize: () => {\n if (pending === 0) resolveAllDone();\n return allDone;\n },\n });\n}\n\n/**\n * Flushes the client and then disposes of it to allow garbage collection.\n * This should be called at the end of each request to prevent memory leaks.\n *\n * @param client - The CloudflareClient instance to flush and dispose\n * @param timeout - Timeout in milliseconds for the flush operation\n * @returns A promise that resolves when flush and dispose are complete\n */\nexport async function flushAndDispose(client: Client | undefined, timeout = 2000): Promise<void> {\n if (!client) {\n await flush(timeout);\n\n return;\n }\n\n await client.flush(timeout);\n client.dispose();\n}\n"],"names":["flush"],"mappings":";;;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,OAAO,EAA+B;AACpE,EAAE,IAAI,cAAc,GAAe,MAAM,SAAS;AAClD,EAAE,MAAM,OAAA,GAAU,IAAI,OAAO,CAAO,OAAO;AAC3C,IAAI,cAAA,GAAiB,GAAG;AACxB,EAAE,CAAC,CAAC;AACJ,EAAE,IAAI,OAAA,GAAU,CAAC;AACjB,EAAE,MAAM,iBAAA,GAAoB,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAA;AAC1D,EAAE,OAAO,CAAC,SAAA,GAAY,WAAW;AACjC,IAAI,OAAO,EAAE;AACb,IAAI,OAAO,iBAAiB;AAC5B,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM;AAC5B,QAAQ,IAAI,EAAE,OAAA,KAAY,CAAC,EAAE,cAAc,EAAE;AAC7C,MAAM,CAAC,CAAC;AACR,KAAK;AACL,EAAE,CAAC;AACH,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,IAAI,KAAK,EAAE,OAAO;AAClB,IAAI,QAAQ,EAAE,MAAM;AACpB,MAAM,IAAI,OAAA,KAAY,CAAC,EAAE,cAAc,EAAE;AACzC,MAAM,OAAO,OAAO;AACpB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,eAAe,CAAC,MAAM,EAAsB,OAAA,GAAU,IAAI,EAAiB;AACjG,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI,MAAMA,UAAK,CAAC,OAAO,CAAC;;AAExB,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;AAC7B,EAAE,MAAM,CAAC,OAAO,EAAE;AAClB;;;;;"}
1
+ {"version":3,"file":"flush.js","sources":["../../src/flush.ts"],"sourcesContent":["import type { ExecutionContext } from '@cloudflare/workers-types';\nimport type { Client } from '@sentry/core';\nimport { flush } from '@sentry/core';\n\ntype FlushLock = {\n readonly ready: Promise<void>;\n readonly finalize: () => Promise<void>;\n};\n\ntype FlushLockRegistry = {\n readonly locks: Set<FlushLockInternal>;\n};\n\ntype FlushLockInternal = FlushLock & {\n readonly acquire: () => void;\n readonly release: () => void;\n};\n\nconst flushLockRegistries = new WeakMap<ExecutionContext['waitUntil'], FlushLockRegistry>();\n\n/**\n * Enhances the given execution context by wrapping its `waitUntil` method with a proxy\n * to monitor pending tasks, and provides a flusher function to ensure all tasks\n * have been completed before executing any subsequent logic.\n *\n * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.\n * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.\n */\nexport function makeFlushLock(context: ExecutionContext): FlushLock {\n const registry = getOrCreateFlushLockRegistry(context);\n let resolveAllDone: () => void = () => undefined;\n const allDone = new Promise<void>(res => {\n resolveAllDone = res;\n });\n let pending = 0;\n\n const lock: FlushLockInternal = {\n ready: allDone,\n acquire: () => {\n pending++;\n },\n release: () => {\n if (--pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n },\n finalize: () => {\n if (pending === 0) {\n registry.locks.delete(lock);\n resolveAllDone();\n }\n return allDone;\n },\n };\n\n registry.locks.add(lock);\n return Object.freeze(lock);\n}\n\nfunction getOrCreateFlushLockRegistry(context: ExecutionContext): FlushLockRegistry {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const waitUntil = context.waitUntil;\n const existingRegistry = flushLockRegistries.get(waitUntil);\n\n if (existingRegistry) {\n return existingRegistry;\n }\n\n const registry: FlushLockRegistry = { locks: new Set() };\n const originalWaitUntil = context.waitUntil.bind(context) as typeof context.waitUntil;\n const instrumentedWaitUntil: typeof context.waitUntil = promise => {\n // Snapshot active locks so locks created after this call do not wait for earlier waitUntil work.\n const locks = [...registry.locks];\n\n for (const lock of locks) {\n lock.acquire();\n }\n\n return originalWaitUntil(\n promise.finally(() => {\n for (const lock of locks) {\n lock.release();\n }\n }),\n );\n };\n\n flushLockRegistries.set(instrumentedWaitUntil, registry);\n context.waitUntil = instrumentedWaitUntil;\n\n return registry;\n}\n\n/**\n * Flushes the client and then disposes of it to allow garbage collection.\n * This should be called at the end of each request to prevent memory leaks.\n *\n * @param client - The CloudflareClient instance to flush and dispose\n * @param timeout - Timeout in milliseconds for the flush operation\n * @returns A promise that resolves when flush and dispose are complete\n */\nexport async function flushAndDispose(client: Client | undefined, timeout = 2000): Promise<void> {\n if (!client) {\n await flush(timeout);\n\n return;\n }\n\n await client.flush(timeout);\n client.dispose();\n}\n"],"names":["flush"],"mappings":";;;;AAkBA,MAAM,mBAAA,uBAA0B,OAAA,EAA0D;AAUnF,SAAS,cAAc,OAAA,EAAsC;AAClE,EAAA,MAAM,QAAA,GAAW,6BAA6B,OAAO,CAAA;AACrD,EAAA,IAAI,iBAA6B,MAAM,MAAA;AACvC,EAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAc,CAAA,GAAA,KAAO;AACvC,IAAA,cAAA,GAAiB,GAAA;AAAA,EACnB,CAAC,CAAA;AACD,EAAA,IAAI,OAAA,GAAU,CAAA;AAEd,EAAA,MAAM,IAAA,GAA0B;AAAA,IAC9B,KAAA,EAAO,OAAA;AAAA,IACP,SAAS,MAAM;AACb,MAAA,OAAA,EAAA;AAAA,IACF,CAAA;AAAA,IACA,SAAS,MAAM;AACb,MAAA,IAAI,EAAE,YAAY,CAAA,EAAG;AACnB,QAAA,QAAA,CAAS,KAAA,CAAM,OAAO,IAAI,CAAA;AAC1B,QAAA,cAAA,EAAe;AAAA,MACjB;AAAA,IACF,CAAA;AAAA,IACA,UAAU,MAAM;AACd,MAAA,IAAI,YAAY,CAAA,EAAG;AACj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I,CAAC,MAAA,EAAQ;AACX,IAAA,MAAMA,WAAM,OAAO,CAAA;AAEnB,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAC1B,EAAA,MAAA,CAAO,OAAA,EAAQ;AACjB;;;;;"}
@@ -1,87 +1,46 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- // Use a global WeakMap to track instrumented objects across module instances.
4
- // This is important for Cloudflare Workers where the module may be bundled
5
- // separately for workers and Durable Objects, but they share the same global scope.
6
- // The WeakMap stores original -> instrumented mappings so we can retrieve the
7
- // instrumented version even if we only have a reference to the original.
8
- const GLOBAL_KEY = '__SENTRY_INSTRUMENTED_MAP__' ;
9
-
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ const GLOBAL_KEY = "__SENTRY_INSTRUMENTED_MAP__";
11
4
  function getInstrumentedMap() {
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
- const globalObj = globalThis ;
5
+ const globalObj = globalThis;
14
6
  if (!globalObj[GLOBAL_KEY]) {
15
- globalObj[GLOBAL_KEY] = new WeakMap();
7
+ globalObj[GLOBAL_KEY] = /* @__PURE__ */ new WeakMap();
16
8
  }
17
9
  return globalObj[GLOBAL_KEY];
18
10
  }
19
-
20
- /**
21
- * Check if a value can be used as a WeakMap key.
22
- * WeakMap keys must be objects or non-registered symbols.
23
- */
24
11
  function isWeakMapKey(value) {
25
- return (typeof value === 'object' && value !== null) || typeof value === 'function';
12
+ return typeof value === "object" && value !== null || typeof value === "function";
26
13
  }
27
-
28
- /**
29
- * Mark an object as instrumented, storing the instrumented version.
30
- * @param original The original uninstrumented object
31
- * @param instrumented The instrumented version (defaults to original if not provided)
32
- */
33
14
  function markAsInstrumented(original, instrumented) {
34
15
  try {
35
16
  if (isWeakMapKey(original)) {
36
- // Store mapping from original to instrumented version
37
- // If instrumented is not provided, store original (for backwards compat)
38
17
  getInstrumentedMap().set(original, instrumented ?? original);
39
18
  }
40
- // Also mark the instrumented version itself so we recognize it
41
19
  if (isWeakMapKey(instrumented) && instrumented !== original) {
42
20
  getInstrumentedMap().set(instrumented, instrumented);
43
21
  }
44
22
  } catch {
45
- // ignore errors here
46
23
  }
47
24
  }
48
-
49
- /**
50
- * Get the instrumented version of an object, if available.
51
- * Returns the instrumented version if the object was previously instrumented,
52
- * or undefined if not found.
53
- */
54
25
  function getInstrumented(obj) {
55
26
  try {
56
27
  if (isWeakMapKey(obj)) {
57
- return getInstrumentedMap().get(obj) ;
28
+ return getInstrumentedMap().get(obj);
58
29
  }
59
-
60
- return undefined;
30
+ return void 0;
61
31
  } catch {
62
- return undefined;
32
+ return void 0;
63
33
  }
64
34
  }
65
-
66
- /**
67
- * Returns the already-instrumented version of `original` if one exists,
68
- * otherwise calls `instrumentFn` to create it, marks the mapping, and returns it.
69
- *
70
- * @param noMark - If true, skips storing the original→instrumented mapping.
71
- */
72
35
  function ensureInstrumented(original, instrumentFn, noMark) {
73
36
  const existing = getInstrumented(original);
74
-
75
37
  if (existing) {
76
38
  return existing;
77
39
  }
78
-
79
40
  const instrumented = instrumentFn(original);
80
-
81
41
  if (!noMark) {
82
42
  markAsInstrumented(original, instrumented);
83
43
  }
84
-
85
44
  return instrumented;
86
45
  }
87
46
 
@@ -1 +1 @@
1
- {"version":3,"file":"instrument.js","sources":["../../src/instrument.ts"],"sourcesContent":["// Use a global WeakMap to track instrumented objects across module instances.\n// This is important for Cloudflare Workers where the module may be bundled\n// separately for workers and Durable Objects, but they share the same global scope.\n// The WeakMap stores original -> instrumented mappings so we can retrieve the\n// instrumented version even if we only have a reference to the original.\nconst GLOBAL_KEY = '__SENTRY_INSTRUMENTED_MAP__' as const;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction getInstrumentedMap(): WeakMap<any, any> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const globalObj = globalThis as typeof globalThis & { [GLOBAL_KEY]?: WeakMap<any, any> };\n if (!globalObj[GLOBAL_KEY]) {\n globalObj[GLOBAL_KEY] = new WeakMap();\n }\n return globalObj[GLOBAL_KEY];\n}\n\n/**\n * Check if a value can be used as a WeakMap key.\n * WeakMap keys must be objects or non-registered symbols.\n */\nfunction isWeakMapKey(value: unknown): value is object {\n return (typeof value === 'object' && value !== null) || typeof value === 'function';\n}\n\n/**\n * Mark an object as instrumented, storing the instrumented version.\n * @param original The original uninstrumented object\n * @param instrumented The instrumented version (defaults to original if not provided)\n */\nexport function markAsInstrumented<T>(original: T, instrumented?: T): void {\n try {\n if (isWeakMapKey(original)) {\n // Store mapping from original to instrumented version\n // If instrumented is not provided, store original (for backwards compat)\n getInstrumentedMap().set(original, instrumented ?? original);\n }\n // Also mark the instrumented version itself so we recognize it\n if (isWeakMapKey(instrumented) && instrumented !== original) {\n getInstrumentedMap().set(instrumented, instrumented);\n }\n } catch {\n // ignore errors here\n }\n}\n\n/**\n * Get the instrumented version of an object, if available.\n * Returns the instrumented version if the object was previously instrumented,\n * or undefined if not found.\n */\nexport function getInstrumented<T>(obj: T): T | undefined {\n try {\n if (isWeakMapKey(obj)) {\n return getInstrumentedMap().get(obj) as T | undefined;\n }\n\n return undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns the already-instrumented version of `original` if one exists,\n * otherwise calls `instrumentFn` to create it, marks the mapping, and returns it.\n *\n * @param noMark - If true, skips storing the original→instrumented mapping.\n */\nexport function ensureInstrumented<T>(original: T, instrumentFn: (original: T) => T, noMark?: boolean): T {\n const existing = getInstrumented(original);\n\n if (existing) {\n return existing;\n }\n\n const instrumented = instrumentFn(original);\n\n if (!noMark) {\n markAsInstrumented(original, instrumented);\n }\n\n return instrumented;\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA,MAAM,UAAA,GAAa,6BAAA;;AAEnB;AACA,SAAS,kBAAkB,GAAsB;AACjD;AACA,EAAE,MAAM,SAAA,GAAY,UAAA;AACpB,EAAE,IAAI,CAAC,SAAS,C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,EAAE;AAChB,IAAI,OAAO,QAAQ;AACnB,EAAE;;AAEF,EAAE,MAAM,YAAA,GAAe,YAAY,CAAC,QAAQ,CAAC;;AAE7C,EAAE,IAAI,CAAC,MAAM,EAAE;AACf,IAAI,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC;AAC9C,EAAE;;AAEF,EAAE,OAAO,YAAY;AACrB;;;;;;"}
1
+ {"version":3,"file":"instrument.js","sources":["../../src/instrument.ts"],"sourcesContent":["// Use a global WeakMap to track instrumented objects across module instances.\n// This is important for Cloudflare Workers where the module may be bundled\n// separately for workers and Durable Objects, but they share the same global scope.\n// The WeakMap stores original -> instrumented mappings so we can retrieve the\n// instrumented version even if we only have a reference to the original.\nconst GLOBAL_KEY = '__SENTRY_INSTRUMENTED_MAP__' as const;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction getInstrumentedMap(): WeakMap<any, any> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const globalObj = globalThis as typeof globalThis & { [GLOBAL_KEY]?: WeakMap<any, any> };\n if (!globalObj[GLOBAL_KEY]) {\n globalObj[GLOBAL_KEY] = new WeakMap();\n }\n return globalObj[GLOBAL_KEY];\n}\n\n/**\n * Check if a value can be used as a WeakMap key.\n * WeakMap keys must be objects or non-registered symbols.\n */\nfunction isWeakMapKey(value: unknown): value is object {\n return (typeof value === 'object' && value !== null) || typeof value === 'function';\n}\n\n/**\n * Mark an object as instrumented, storing the instrumented version.\n * @param original The original uninstrumented object\n * @param instrumented The instrumented version (defaults to original if not provided)\n */\nexport function markAsInstrumented<T>(original: T, instrumented?: T): void {\n try {\n if (isWeakMapKey(original)) {\n // Store mapping from original to instrumented version\n // If instrumented is not provided, store original (for backwards compat)\n getInstrumentedMap().set(original, instrumented ?? original);\n }\n // Also mark the instrumented version itself so we recognize it\n if (isWeakMapKey(instrumented) && instrumented !== original) {\n getInstrumentedMap().set(instrumented, instrumented);\n }\n } catch {\n // ignore errors here\n }\n}\n\n/**\n * Get the instrumented version of an object, if available.\n * Returns the instrumented version if the object was previously instrumented,\n * or undefined if not found.\n */\nexport function getInstrumented<T>(obj: T): T | undefined {\n try {\n if (isWeakMapKey(obj)) {\n return getInstrumentedMap().get(obj) as T | undefined;\n }\n\n return undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns the already-instrumented version of `original` if one exists,\n * otherwise calls `instrumentFn` to create it, marks the mapping, and returns it.\n *\n * @param noMark - If true, skips storing the original→instrumented mapping.\n */\nexport function ensureInstrumented<T>(original: T, instrumentFn: (original: T) => T, noMark?: boolean): T {\n const existing = getInstrumented(original);\n\n if (existing) {\n return existing;\n }\n\n const instrumented = instrumentFn(original);\n\n if (!noMark) {\n markAsInstrumented(original, instrumented);\n }\n\n return instrumented;\n}\n"],"names":[],"mappings":";;AAKA,MAAM,UAAA,GAAa,6BAAA;AAGnB,SAAS,kBAAA,GAAwC;AAE/C,EAAA,MAAM,SAAA,GAAY,UAAA;AAClB,EAAA,IAAI,CAAC,SAAA,CAAU,UAAU,CAAA,EAAG;AAC1B,IAAA,SAAA,CAAU,UAAU,CAAA,mBAAI,IAAI,OAAA,EAAQ;AAAA,EACtC;AACA,EAAA,OAAO,UAAU,UAAU,CAAA;AAC7B;AAMA,SAAS,aAAa,KAAA,EAAiC;AACrD,EAAA,OAAQ,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAS,OAAO,KAAA,KAAU,UAAA;AAC3E;AAOO,SAAS,kBAAA,CAAsB,UAAa,YAAA,EAAwB;AACzE,EAAA,IAAI;AACF,IAAA,IAAI,YAAA,CAAa,QAAQ,CAAA,EAAG;AAG1B,MAAA,kBAAA,EAAmB,CAAE,GAAA,CAAI,QAAA,EAAU,YAAA,IAAgB,QAAQ,CAAA;AAAA,IAC7D;AAEA,IAAA,IAAI,YAAA,CAAa,YAAY,CAAA,IAAK,YAAA,KAAiB,QAAA,EAAU;AAC3D,MAAA,kBAAA,EAAmB,CAAE,GAAA,CAAI,YAAA,EAAc,YAAY,CAAA;AAAA,IACrD;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;AAOO,SAAS,gBAAmB,GAAA,EAAuB;AACxD,EAAA,IAAI;AACF,IAAA,IAAI,YAAA,CAAa,GAAG,CAAA,EAAG;AACrB,MAAA,OAAO,kBAAA,EAAmB,CAAE,GAAA,CAAI,GAAG,CAAA;AAAA,IACrC;AAEA,IAAA,OAAO,KAAA,CAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAQO,SAAS,kBAAA,CAAsB,QAAA,EAAa,YAAA,EAAkC,MAAA,EAAqB;AACxG,EAAA,MAAM,QAAA,GAAW,gBAAgB,QAAQ,CAAA;AAEzC,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,OAAO,QAAA;AAAA,EACT;AAEA,EAAA,MAAM,YAAA,GAAe,aAAa,QAAQ,CAAA;AAE1C,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,kBAAA,CAAmB,UAAU,YAAY,CAAA;AAAA,EAC3C;AAEA,EAAA,OAAO,YAAA;AACT;;;;;;"}
@@ -3,61 +3,36 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
3
  const rpcMeta = require('../utils/rpcMeta.js');
4
4
  const instrumentFetcher = require('./worker/instrumentFetcher.js');
5
5
 
6
- // Built-in DurableObjectStub methods that are not RPC calls.
7
- const STUB_NON_RPC_METHODS = new Set(['fetch', 'connect', 'dup']);
8
-
9
- /**
10
- * Instruments a DurableObjectNamespace binding to create spans for DO interactions.
11
- *
12
- * Wraps:
13
- * - `namespace.get(id)` / `namespace.getByName(name)` with a span + instruments returned stub
14
- * - `namespace.idFromName(name)` / `namespace.idFromString(id)` / `namespace.newUniqueId()` with breadcrumbs
15
- *
16
- * @param namespace - The DurableObjectNamespace to instrument
17
- */
6
+ const STUB_NON_RPC_METHODS = /* @__PURE__ */ new Set(["fetch", "connect", "dup"]);
18
7
  function instrumentDurableObjectNamespace(namespace) {
19
8
  return new Proxy(namespace, {
20
9
  get(target, prop, _receiver) {
21
- const value = Reflect.get(target, prop) ;
22
-
23
- if (typeof value !== 'function') {
10
+ const value = Reflect.get(target, prop);
11
+ if (typeof value !== "function") {
24
12
  return value;
25
13
  }
26
-
27
- if (prop === 'get' || prop === 'getByName') {
28
- return function ( ...args) {
14
+ if (prop === "get" || prop === "getByName") {
15
+ return function(...args) {
29
16
  const stub = Reflect.apply(value, target, args);
30
-
31
17
  return instrumentDurableObjectStub(stub);
32
18
  };
33
19
  }
34
-
35
20
  return value.bind(target);
36
- },
21
+ }
37
22
  });
38
23
  }
39
-
40
- /**
41
- * Instruments a DurableObjectStub to create spans for outgoing fetch calls
42
- * and propagate trace context across RPC calls.
43
- *
44
- * @param stub - The DurableObjectStub to instrument
45
- */
46
24
  function instrumentDurableObjectStub(stub) {
47
25
  return new Proxy(stub, {
48
26
  get(target, prop) {
49
27
  const value = Reflect.get(target, prop);
50
-
51
- if (prop === 'fetch' && typeof value === 'function') {
28
+ if (prop === "fetch" && typeof value === "function") {
52
29
  return instrumentFetcher.instrumentFetcher((...args) => Reflect.apply(value, target, args));
53
30
  }
54
-
55
- if (typeof value === 'function' && typeof prop === 'string' && !STUB_NON_RPC_METHODS.has(prop)) {
31
+ if (typeof value === "function" && typeof prop === "string" && !STUB_NON_RPC_METHODS.has(prop)) {
56
32
  return (...args) => Reflect.apply(value, target, rpcMeta.appendRpcMeta(args));
57
33
  }
58
-
59
34
  return value;
60
- },
35
+ }
61
36
  });
62
37
  }
63
38
 
@@ -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":";;;;;AAIA;AACO,MAAM,oBAAA,GAAuB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC;;AAEvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,gCAAgC,CAAC,SAAS,EAAkD;AAC5G,EAAE,OAAO,IAAI,KAAK,CAAC,SAAS,EAAE;AAC9B,IAAI,GAAG,CAAC,MAAM,EAAE,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EAAEC,qBAAa,CAAC,IAAI,CAAC,CAAC;AACxF,MAAM;;AAEN,MAAM,OAAO,KAAK;AAClB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;;;;"}
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[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