@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
@@ -8,182 +8,95 @@ import { instrumentContext } from './utils/instrumentContext.js';
8
8
  import { getEffectiveRpcPropagation } from './utils/rpcOptions.js';
9
9
  import { wrapMethodWithSentry } from './wrapMethodWithSentry.js';
10
10
 
11
- /* eslint-disable @typescript-eslint/unbound-method */
12
-
13
- const BUILT_IN_DO_METHODS = new Set([
14
- 'constructor',
15
- 'fetch',
16
- 'alarm',
17
- 'webSocketError',
18
- 'webSocketClose',
19
- 'webSocketMessage',
11
+ const BUILT_IN_DO_METHODS = /* @__PURE__ */ new Set([
12
+ "constructor",
13
+ "fetch",
14
+ "alarm",
15
+ "webSocketError",
16
+ "webSocketClose",
17
+ "webSocketMessage"
20
18
  ]);
21
-
22
- /**
23
- * Instruments a Durable Object class to capture errors and performance data.
24
- *
25
- * Instruments the following methods by default:
26
- * - fetch
27
- * - alarm
28
- * - webSocketMessage
29
- * - webSocketClose
30
- * - webSocketError
31
- *
32
- * To instrument RPC methods (prototype methods), enable the `enableRpcTracePropagation` option.
33
- *
34
- * @param optionsCallback Function that returns the options for the SDK initialization.
35
- * @param DurableObjectClass The Durable Object class to instrument.
36
- * @returns The instrumented Durable Object class.
37
- *
38
- * @example
39
- * ```ts
40
- * class MyDurableObjectBase extends DurableObject {
41
- * constructor(ctx: DurableObjectState, env: Env) {
42
- * super(ctx, env);
43
- * }
44
- * }
45
- *
46
- * export const MyDurableObject = instrumentDurableObjectWithSentry(
47
- * env => ({
48
- * dsn: env.SENTRY_DSN,
49
- * tracesSampleRate: 1.0,
50
- * }),
51
- * MyDurableObjectBase,
52
- * );
53
- * ```
54
- */
55
- function instrumentDurableObjectWithSentry
56
-
57
- (optionsCallback, DurableObjectClass) {
19
+ function instrumentDurableObjectWithSentry(optionsCallback, DurableObjectClass) {
58
20
  return new Proxy(DurableObjectClass, {
59
21
  construct(target, [ctx, env]) {
60
22
  setAsyncLocalStorageAsyncContextStrategy();
61
23
  const context = instrumentContext(ctx);
62
24
  const options = getFinalOptions(optionsCallback(env), env);
63
25
  const instrumentedEnv = instrumentEnv(env, options);
64
-
65
26
  const obj = new target(context, instrumentedEnv);
66
-
67
- // These are the methods that are available on a Durable Object
68
- // ref: https://developers.cloudflare.com/durable-objects/api/base/
69
- // obj.alarm
70
- // obj.fetch
71
- // obj.webSocketError
72
- // obj.webSocketClose
73
- // obj.webSocketMessage
74
-
75
- // Any other public methods on the Durable Object instance are RPC calls.
76
-
77
- if (obj.fetch && typeof obj.fetch === 'function') {
27
+ if (obj.fetch && typeof obj.fetch === "function") {
78
28
  obj.fetch = ensureInstrumented(
79
29
  obj.fetch,
80
- original =>
81
- new Proxy(original, {
82
- apply(target, thisArg, args) {
83
- return wrapRequestHandler({ options, request: args[0], context }, () => {
84
- return Reflect.apply(target, thisArg, args);
85
- });
86
- },
87
- }),
30
+ (original) => new Proxy(original, {
31
+ apply(target2, thisArg, args) {
32
+ return wrapRequestHandler({ options, request: args[0], context }, () => {
33
+ return Reflect.apply(target2, thisArg, args);
34
+ });
35
+ }
36
+ })
88
37
  );
89
38
  }
90
-
91
- if (obj.alarm && typeof obj.alarm === 'function') {
92
- // Alarms are independent invocations, so we start a new trace and link to the previous alarm
39
+ if (obj.alarm && typeof obj.alarm === "function") {
93
40
  obj.alarm = wrapMethodWithSentry(
94
- { options, context, spanName: 'alarm', spanOp: 'function', startNewTrace: true },
95
- obj.alarm,
41
+ { options, context, spanName: "alarm", spanOp: "function", startNewTrace: true },
42
+ obj.alarm
96
43
  );
97
44
  }
98
-
99
- if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {
45
+ if (obj.webSocketMessage && typeof obj.webSocketMessage === "function") {
100
46
  obj.webSocketMessage = wrapMethodWithSentry(
101
- { options, context, spanName: 'webSocketMessage' },
102
- obj.webSocketMessage,
47
+ { options, context, spanName: "webSocketMessage" },
48
+ obj.webSocketMessage
103
49
  );
104
50
  }
105
-
106
- if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {
107
- obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose);
51
+ if (obj.webSocketClose && typeof obj.webSocketClose === "function") {
52
+ obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: "webSocketClose" }, obj.webSocketClose);
108
53
  }
109
-
110
- if (obj.webSocketError && typeof obj.webSocketError === 'function') {
54
+ if (obj.webSocketError && typeof obj.webSocketError === "function") {
111
55
  obj.webSocketError = wrapMethodWithSentry(
112
- { options, context, spanName: 'webSocketError' },
56
+ { options, context, spanName: "webSocketError" },
113
57
  obj.webSocketError,
114
- (_, error) =>
115
- captureException(error, {
116
- mechanism: {
117
- type: 'auto.faas.cloudflare.durable_object_websocket',
118
- handled: false,
119
- },
120
- }),
58
+ (_, error) => captureException(error, {
59
+ mechanism: {
60
+ type: "auto.faas.cloudflare.durable_object_websocket",
61
+ handled: false
62
+ }
63
+ })
121
64
  );
122
65
  }
123
-
124
- // Get effective RPC propagation setting (handles deprecation of instrumentPrototypeMethods)
125
66
  const rpcPropagation = getEffectiveRpcPropagation(options);
126
-
127
- // Skip RPC instrumentation if not enabled
128
67
  if (!rpcPropagation) {
129
68
  return obj;
130
69
  }
131
-
132
- // If `instrumentPrototypeMethods` was passed as an array (deprecated),
133
- // only the listed method names should be instrumented.
134
- const instrumentPrototypeMethods = Array.isArray(options.instrumentPrototypeMethods)
135
- ? options.instrumentPrototypeMethods
136
- : undefined;
70
+ const instrumentPrototypeMethods = Array.isArray(options.instrumentPrototypeMethods) ? options.instrumentPrototypeMethods : void 0;
137
71
  const allowSet = instrumentPrototypeMethods ? new Set(instrumentPrototypeMethods) : null;
138
-
139
- // Return a Proxy that lazily wraps prototype methods on access.
140
- // This avoids iterating the prototype chain at construction time —
141
- // we only check if a property is an RPC method when it's accessed.
142
- const rpcMethodCache = new Map();
143
-
72
+ const rpcMethodCache = /* @__PURE__ */ new Map();
144
73
  return new Proxy(obj, {
145
74
  get(proxyTarget, prop, receiver) {
146
75
  const value = Reflect.get(proxyTarget, prop, receiver);
147
-
148
- if (typeof prop !== 'string' || BUILT_IN_DO_METHODS.has(prop)) {
76
+ if (typeof prop !== "string" || BUILT_IN_DO_METHODS.has(prop)) {
149
77
  return value;
150
78
  }
151
-
152
79
  const cached = rpcMethodCache.get(prop);
153
-
154
80
  if (cached) {
155
81
  return cached;
156
82
  }
157
-
158
- if (
159
- typeof value !== 'function' ||
160
- Object.prototype.hasOwnProperty.call(proxyTarget, prop) ||
161
- (allowSet && !allowSet.has(prop)) ||
162
- // Exclude inherited Object.prototype methods (toString, valueOf, etc.)
163
- // These are not RPC methods and should not create spans
164
- prop in Object.prototype
165
- ) {
83
+ if (typeof value !== "function" || Object.prototype.hasOwnProperty.call(proxyTarget, prop) || allowSet && !allowSet.has(prop) || // Exclude inherited Object.prototype methods (toString, valueOf, etc.)
84
+ // These are not RPC methods and should not create spans
85
+ prop in Object.prototype) {
166
86
  return value;
167
87
  }
168
-
169
- // Bind the method to the original object to ensure private fields work correctly.
170
- // When called via the Proxy, `this` would be the Proxy, but private fields require
171
- // the original object. Bound functions ignore the thisArg passed via Reflect.apply.
172
- const boundValue = (value ).bind(proxyTarget);
173
-
88
+ const boundValue = value.bind(proxyTarget);
174
89
  const wrapped = wrapMethodWithSentry(
175
- { options, context, spanName: prop, spanOp: 'rpc' },
90
+ { options, context, spanName: prop, spanOp: "rpc" },
176
91
  boundValue,
177
- undefined,
178
- true,
92
+ void 0,
93
+ true
179
94
  );
180
-
181
95
  rpcMethodCache.set(prop, wrapped);
182
-
183
96
  return wrapped;
184
- },
97
+ }
185
98
  });
186
- },
99
+ }
187
100
  });
188
101
  }
189
102
 
@@ -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":[],"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,MAAM,wCAAwC,EAAE;AAChD,MAAM,MAAM,OAAA,GAAU,iBAAiB,CAAC,GAAG,CAAC;AAC5C,MAAM,MAAM,OAAA,GAAU,eAAe,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;AAChE,MAAM,MAAM,kBAAkB,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC;;AAEzD,MAAM,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,MAAM,IAAI,GAAG,CAAC,KAAA,IAAS,OAAO,GAAG,CAAC,KAAA,KAAU,UAAU,EAAE;AACxD,QAAQ,GAAG,CAAC,KAAA,GAAQ,kBAAkB;AACtC,UAAU,GAAG,CAAC,KAAK;AACnB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AC,IAAI,CAAC;;AAEjD,UAAU,IAAI,MAAM,EAAE;AACtB,YAAY,OAAO,MAAM;AACzB,UAAU;;AAEV,UAAU;AACV,YAAY,OAAO,KAAA,KAAU,UAAA;AAC7B,YAAY,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAA;AAClE,aAAa,QAAA,IAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC5C;AACA;AACA,YAAY,IAAA,IAAQ,MAAM,CAAC;AAC3B,YAAY;AACZ,YAAY,OAAO,KAAK;AACxB,UAAU;;AAEV;AACA;AACA;AACA,UAAU,MAAM,UAAA,GAAa,CAAC,KAAA,GAA0B,IAAI,CAAC,WAAW,CAAC;;AAEzE,UAAU,MAAM,OAAA,GAAU,oBAAoB;AAC9C,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAA,EAAO;AAC/D,YAAY,UAAU;AACtB,YAAY,SAAS;AACrB,YAAY,IAAI;AAChB,WAAW;;AAEX,UAAU,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC;;AAE3C,UAAU,OAAO,OAAO;AACxB,QAAQ,CAAC;AACT,OAAO,CAAC;AACR,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;;;"}
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":["target"],"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,CAAA,EAAG;AAC5B,MAAA,wCAAA,EAAyC;AACzC,MAAA,MAAM,OAAA,GAAU,kBAAkB,GAAG,CAAA;AACrC,MAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,eAAA,CAAgB,GAAG,GAAG,GAAG,CAAA;AACzD,MAAA,MAAM,eAAA,GAAkB,aAAA,CAAc,GAAA,EAAK,OAAO,CAAA;AAElD,MAAA,MAAM,GAAA,GAAM,IAAI,MAAA,CAAO,OAAA,EAAS,eAAe,CAAA;AAY/C,MAAA,IAAI,GAAA,CAAI,KAAA,IAAS,OAAO,GAAA,CAAI,UAAU,UAAA,EAAY;AAChD,QAAA,GAAA,CAAI,KAAA,GAAQ,kBAAA;AAAA,UACV,GAAA,CAAI,KAAA;AA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AAA,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,GAAU,oBAAA;AAAA,YACd,EAAE,OAAA,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;;;;"}
@@ -1,52 +1,65 @@
1
1
  import { flush } from '@sentry/core';
2
2
 
3
- /**
4
- * Enhances the given execution context by wrapping its `waitUntil` method with a proxy
5
- * to monitor pending tasks, and provides a flusher function to ensure all tasks
6
- * have been completed before executing any subsequent logic.
7
- *
8
- * @param {ExecutionContext} context - The execution context to be enhanced. If no context is provided, the function returns undefined.
9
- * @return {FlushLock} Returns a flusher function if a valid context is provided, otherwise undefined.
10
- */
3
+ const flushLockRegistries = /* @__PURE__ */ new WeakMap();
11
4
  function makeFlushLock(context) {
12
- let resolveAllDone = () => undefined;
13
- const allDone = new Promise(res => {
5
+ const registry = getOrCreateFlushLockRegistry(context);
6
+ let resolveAllDone = () => void 0;
7
+ const allDone = new Promise((res) => {
14
8
  resolveAllDone = res;
15
9
  });
16
10
  let pending = 0;
17
- const originalWaitUntil = context.waitUntil.bind(context) ;
18
- context.waitUntil = promise => {
19
- pending++;
11
+ const lock = {
12
+ ready: allDone,
13
+ acquire: () => {
14
+ pending++;
15
+ },
16
+ release: () => {
17
+ if (--pending === 0) {
18
+ registry.locks.delete(lock);
19
+ resolveAllDone();
20
+ }
21
+ },
22
+ finalize: () => {
23
+ if (pending === 0) {
24
+ registry.locks.delete(lock);
25
+ resolveAllDone();
26
+ }
27
+ return allDone;
28
+ }
29
+ };
30
+ registry.locks.add(lock);
31
+ return Object.freeze(lock);
32
+ }
33
+ function getOrCreateFlushLockRegistry(context) {
34
+ const waitUntil = context.waitUntil;
35
+ const existingRegistry = flushLockRegistries.get(waitUntil);
36
+ if (existingRegistry) {
37
+ return existingRegistry;
38
+ }
39
+ const registry = { locks: /* @__PURE__ */ new Set() };
40
+ const originalWaitUntil = context.waitUntil.bind(context);
41
+ const instrumentedWaitUntil = (promise) => {
42
+ const locks = [...registry.locks];
43
+ for (const lock of locks) {
44
+ lock.acquire();
45
+ }
20
46
  return originalWaitUntil(
21
47
  promise.finally(() => {
22
- if (--pending === 0) resolveAllDone();
23
- }),
48
+ for (const lock of locks) {
49
+ lock.release();
50
+ }
51
+ })
24
52
  );
25
53
  };
26
- return Object.freeze({
27
- ready: allDone,
28
- finalize: () => {
29
- if (pending === 0) resolveAllDone();
30
- return allDone;
31
- },
32
- });
54
+ flushLockRegistries.set(instrumentedWaitUntil, registry);
55
+ context.waitUntil = instrumentedWaitUntil;
56
+ return registry;
33
57
  }
34
-
35
- /**
36
- * Flushes the client and then disposes of it to allow garbage collection.
37
- * This should be called at the end of each request to prevent memory leaks.
38
- *
39
- * @param client - The CloudflareClient instance to flush and dispose
40
- * @param timeout - Timeout in milliseconds for the flush operation
41
- * @returns A promise that resolves when flush and dispose are complete
42
- */
43
- async function flushAndDispose(client, timeout = 2000) {
58
+ async function flushAndDispose(client, timeout = 2e3) {
44
59
  if (!client) {
45
60
  await flush(timeout);
46
-
47
61
  return;
48
62
  }
49
-
50
63
  await client.flush(timeout);
51
64
  client.dispose();
52
65
  }
@@ -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":[],"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,MAAM,KAAK,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":[],"mappings":";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A,GAAoB,OAAA,CAAQ,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AACxD,EAAA,MAAM,wBAAkD,CAAA,OAAA,KAAW;AAEjE,IAAA,MAAM,KAAA,GAAQ,CAAC,GAAG,QAAA,CAAS,KAAK,CAAA;AAEhC,IAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,MAAA,IAAA,CAAK,OAAA,EAAQ;AAAA,IACf;AAEA,IAAA,OAAO,iBAAA;AAAA,MACL,OAAA,CAAQ,QAAQ,MAAM;AACpB,QAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,UAAA,IAAA,CAAK,OAAA,EAAQ;AAAA,QACf;AAAA,MACF,CAAC;AAAA,KACH;AAAA,EACF,CAAA;AAEA,EAAA,mBAAA,CAAoB,GAAA,CAAI,uBAAuB,QAAQ,CAAA;AACvD,EAAA,OAAA,CAAQ,SAAA,GAAY,qBAAA;AAEpB,EAAA,OAAO,QAAA;AACT;AAUA,eAAsB,eAAA,CAAgB,MAAA,EAA4B,OAAA,GAAU,GAAA,EAAqB;AAC/F,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,MAAM,OAAO,CAAA;AAEnB,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAC1B,EAAA,MAAA,CAAO,OAAA,EAAQ;AACjB;;;;"}
@@ -1,85 +1,44 @@
1
- // Use a global WeakMap to track instrumented objects across module instances.
2
- // This is important for Cloudflare Workers where the module may be bundled
3
- // separately for workers and Durable Objects, but they share the same global scope.
4
- // The WeakMap stores original -> instrumented mappings so we can retrieve the
5
- // instrumented version even if we only have a reference to the original.
6
- const GLOBAL_KEY = '__SENTRY_INSTRUMENTED_MAP__' ;
7
-
8
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1
+ const GLOBAL_KEY = "__SENTRY_INSTRUMENTED_MAP__";
9
2
  function getInstrumentedMap() {
10
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
- const globalObj = globalThis ;
3
+ const globalObj = globalThis;
12
4
  if (!globalObj[GLOBAL_KEY]) {
13
- globalObj[GLOBAL_KEY] = new WeakMap();
5
+ globalObj[GLOBAL_KEY] = /* @__PURE__ */ new WeakMap();
14
6
  }
15
7
  return globalObj[GLOBAL_KEY];
16
8
  }
17
-
18
- /**
19
- * Check if a value can be used as a WeakMap key.
20
- * WeakMap keys must be objects or non-registered symbols.
21
- */
22
9
  function isWeakMapKey(value) {
23
- return (typeof value === 'object' && value !== null) || typeof value === 'function';
10
+ return typeof value === "object" && value !== null || typeof value === "function";
24
11
  }
25
-
26
- /**
27
- * Mark an object as instrumented, storing the instrumented version.
28
- * @param original The original uninstrumented object
29
- * @param instrumented The instrumented version (defaults to original if not provided)
30
- */
31
12
  function markAsInstrumented(original, instrumented) {
32
13
  try {
33
14
  if (isWeakMapKey(original)) {
34
- // Store mapping from original to instrumented version
35
- // If instrumented is not provided, store original (for backwards compat)
36
15
  getInstrumentedMap().set(original, instrumented ?? original);
37
16
  }
38
- // Also mark the instrumented version itself so we recognize it
39
17
  if (isWeakMapKey(instrumented) && instrumented !== original) {
40
18
  getInstrumentedMap().set(instrumented, instrumented);
41
19
  }
42
20
  } catch {
43
- // ignore errors here
44
21
  }
45
22
  }
46
-
47
- /**
48
- * Get the instrumented version of an object, if available.
49
- * Returns the instrumented version if the object was previously instrumented,
50
- * or undefined if not found.
51
- */
52
23
  function getInstrumented(obj) {
53
24
  try {
54
25
  if (isWeakMapKey(obj)) {
55
- return getInstrumentedMap().get(obj) ;
26
+ return getInstrumentedMap().get(obj);
56
27
  }
57
-
58
- return undefined;
28
+ return void 0;
59
29
  } catch {
60
- return undefined;
30
+ return void 0;
61
31
  }
62
32
  }
63
-
64
- /**
65
- * Returns the already-instrumented version of `original` if one exists,
66
- * otherwise calls `instrumentFn` to create it, marks the mapping, and returns it.
67
- *
68
- * @param noMark - If true, skips storing the original→instrumented mapping.
69
- */
70
33
  function ensureInstrumented(original, instrumentFn, noMark) {
71
34
  const existing = getInstrumented(original);
72
-
73
35
  if (existing) {
74
36
  return existing;
75
37
  }
76
-
77
38
  const instrumented = instrumentFn(original);
78
-
79
39
  if (!noMark) {
80
40
  markAsInstrumented(original, instrumented);
81
41
  }
82
-
83
42
  return instrumented;
84
43
  }
85
44
 
@@ -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,CAAC,UAAU,CAAC,EAAE;AAC9B,IAAI,SAAS,CAAC,UAAU,CAAA,GAAI,IAAI,OAAO,EAAE;AACzC,EAAE;AACF,EAAE,OAAO,SAAS,CAAC,UAAU,CAAC;AAC9B;;AAEA;AACA;AACA;AACA;AACA,SAAS,YAAY,CAAC,KAAK,EAA4B;AACvD,EAAE,OAAO,CAAC,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAI,KAAK,OAAO,KAAA,KAAU,UAAU;AACrF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAI,QAAQ,EAAK,YAAY,EAAY;AAC3E,EAAE,IAAI;AACN,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE;AAChC;AACA;AACA,MAAM,kBAAkB,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAA,IAAgB,QAAQ,CAAC;AAClE,IAAI;AACJ;AACA,IAAI,IAAI,YAAY,CAAC,YAAY,KAAK,YAAA,KAAiB,QAAQ,EAAE;AACjE,MAAM,kBAAkB,EAAE,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;AAC1D,IAAI;AACJ,EAAE,EAAE,MAAM;AACV;AACA,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAI,GAAG,EAAoB;AAC1D,EAAE,IAAI;AACN,IAAI,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE;AAC3B,MAAM,OAAO,kBAAkB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAA;AACzC,IAAI;;AAEJ,IAAI,OAAO,SAAS;AACpB,EAAE,EAAE,MAAM;AACV,IAAI,OAAO,SAAS;AACpB,EAAE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAI,QAAQ,EAAK,YAAY,EAAsB,MAAM,EAAe;AAC1G,EAAE,MAAM,QAAA,GAAW,eAAe,CAAC,QAAQ,CAAC;;AAE5C,EAAE,IAAI,QAAQ,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,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AA,EAAQ;AACX,IAAA,kBAAA,CAAmB,UAAU,YAAY,CAAA;AAAA,EAC3C;AAEA,EAAA,OAAO,YAAA;AACT;;;;"}
@@ -1,61 +1,36 @@
1
1
  import { appendRpcMeta } from '../utils/rpcMeta.js';
2
2
  import { instrumentFetcher } from './worker/instrumentFetcher.js';
3
3
 
4
- // Built-in DurableObjectStub methods that are not RPC calls.
5
- const STUB_NON_RPC_METHODS = new Set(['fetch', 'connect', 'dup']);
6
-
7
- /**
8
- * Instruments a DurableObjectNamespace binding to create spans for DO interactions.
9
- *
10
- * Wraps:
11
- * - `namespace.get(id)` / `namespace.getByName(name)` with a span + instruments returned stub
12
- * - `namespace.idFromName(name)` / `namespace.idFromString(id)` / `namespace.newUniqueId()` with breadcrumbs
13
- *
14
- * @param namespace - The DurableObjectNamespace to instrument
15
- */
4
+ const STUB_NON_RPC_METHODS = /* @__PURE__ */ new Set(["fetch", "connect", "dup"]);
16
5
  function instrumentDurableObjectNamespace(namespace) {
17
6
  return new Proxy(namespace, {
18
7
  get(target, prop, _receiver) {
19
- const value = Reflect.get(target, prop) ;
20
-
21
- if (typeof value !== 'function') {
8
+ const value = Reflect.get(target, prop);
9
+ if (typeof value !== "function") {
22
10
  return value;
23
11
  }
24
-
25
- if (prop === 'get' || prop === 'getByName') {
26
- return function ( ...args) {
12
+ if (prop === "get" || prop === "getByName") {
13
+ return function(...args) {
27
14
  const stub = Reflect.apply(value, target, args);
28
-
29
15
  return instrumentDurableObjectStub(stub);
30
16
  };
31
17
  }
32
-
33
18
  return value.bind(target);
34
- },
19
+ }
35
20
  });
36
21
  }
37
-
38
- /**
39
- * Instruments a DurableObjectStub to create spans for outgoing fetch calls
40
- * and propagate trace context across RPC calls.
41
- *
42
- * @param stub - The DurableObjectStub to instrument
43
- */
44
22
  function instrumentDurableObjectStub(stub) {
45
23
  return new Proxy(stub, {
46
24
  get(target, prop) {
47
25
  const value = Reflect.get(target, prop);
48
-
49
- if (prop === 'fetch' && typeof value === 'function') {
26
+ if (prop === "fetch" && typeof value === "function") {
50
27
  return instrumentFetcher((...args) => Reflect.apply(value, target, args));
51
28
  }
52
-
53
- if (typeof value === 'function' && typeof prop === 'string' && !STUB_NON_RPC_METHODS.has(prop)) {
29
+ if (typeof value === "function" && typeof prop === "string" && !STUB_NON_RPC_METHODS.has(prop)) {
54
30
  return (...args) => Reflect.apply(value, target, appendRpcMeta(args));
55
31
  }
56
-
57
32
  return value;
58
- },
33
+ }
59
34
  });
60
35
  }
61
36
 
@@ -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":[],"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,IAAI,EAAE,SAAS,EAAE;AACjC,MAAM,MAAM,KAAA,GAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAA;;AAE5C,MAAM,IAAI,OAAO,KAAA,KAAU,UAAU,EAAE;AACvC,QAAQ,OAAO,KAAK;AACpB,MAAM;;AAEN,MAAM,IAAI,IAAA,KAAS,SAAS,IAAA,KAAS,WAAW,EAAE;AAClD,QAAQ,OAAO,WAAyB,GAAG,IAAI,EAAa;AAC5D,UAAU,MAAM,IAAA,GAAO,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC;;AAEzD,UAAU,OAAO,2BAA2B,CAAC,IAAI,CAAC;AAClD,QAAQ,CAAC;AACT,MAAM;;AAEN,MAAM,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;AAC/B,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,2BAA2B,CAAC,IAAI,EAAwC;AACjF,EAAE,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;AACzB,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE;AACtB,MAAM,MAAM,KAAA,GAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;;AAE7C,MAAM,IAAI,IAAA,KAAS,OAAA,IAAW,OAAO,KAAA,KAAU,UAAU,EAAE;AAC3D,QAAQ,OAAO,iBAAiB,CAAC,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACjF,MAAM;;AAEN,MAAM,IAAI,OAAO,UAAU,UAAA,IAAc,OAAO,IAAA,KAAS,QAAA,IAAY,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AACtG,QAAQ,OAAO,CAAC,GAAG,IAAI,KAAgB,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,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[]) => Reflect.apply(value, target, appendRpcMeta(args));\n }\n\n return value;\n },\n });\n}\n"],"names":[],"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,QAC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