@sentry/cloudflare 10.47.0 → 10.48.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 (92) hide show
  1. package/build/cjs/durableobject.js +29 -11
  2. package/build/cjs/durableobject.js.map +1 -1
  3. package/build/cjs/index.js +2 -0
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/cjs/instrument.js +72 -8
  6. package/build/cjs/instrument.js.map +1 -1
  7. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js +101 -0
  8. package/build/cjs/instrumentations/instrumentWorkerEntrypoint.js.map +1 -0
  9. package/build/cjs/instrumentations/worker/instrumentEmail.js +14 -12
  10. package/build/cjs/instrumentations/worker/instrumentEmail.js.map +1 -1
  11. package/build/cjs/instrumentations/worker/instrumentFetch.js +35 -10
  12. package/build/cjs/instrumentations/worker/instrumentFetch.js.map +1 -1
  13. package/build/cjs/instrumentations/worker/instrumentQueue.js +35 -10
  14. package/build/cjs/instrumentations/worker/instrumentQueue.js.map +1 -1
  15. package/build/cjs/instrumentations/worker/instrumentScheduled.js +35 -13
  16. package/build/cjs/instrumentations/worker/instrumentScheduled.js.map +1 -1
  17. package/build/cjs/instrumentations/worker/instrumentTail.js +33 -10
  18. package/build/cjs/instrumentations/worker/instrumentTail.js.map +1 -1
  19. package/build/cjs/request.js +5 -6
  20. package/build/cjs/request.js.map +1 -1
  21. package/build/cjs/scope-utils.js.map +1 -1
  22. package/build/cjs/utils/isCloudflareClass.js +29 -0
  23. package/build/cjs/utils/isCloudflareClass.js.map +1 -0
  24. package/build/cjs/withSentry.js +31 -20
  25. package/build/cjs/withSentry.js.map +1 -1
  26. package/build/cjs/wrapMethodWithSentry.js +111 -111
  27. package/build/cjs/wrapMethodWithSentry.js.map +1 -1
  28. package/build/esm/durableobject.js +30 -12
  29. package/build/esm/durableobject.js.map +1 -1
  30. package/build/esm/index.js +1 -1
  31. package/build/esm/instrument.js +71 -8
  32. package/build/esm/instrument.js.map +1 -1
  33. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js +99 -0
  34. package/build/esm/instrumentations/instrumentWorkerEntrypoint.js.map +1 -0
  35. package/build/esm/instrumentations/worker/instrumentEmail.js +15 -13
  36. package/build/esm/instrumentations/worker/instrumentEmail.js.map +1 -1
  37. package/build/esm/instrumentations/worker/instrumentFetch.js +36 -12
  38. package/build/esm/instrumentations/worker/instrumentFetch.js.map +1 -1
  39. package/build/esm/instrumentations/worker/instrumentQueue.js +36 -12
  40. package/build/esm/instrumentations/worker/instrumentQueue.js.map +1 -1
  41. package/build/esm/instrumentations/worker/instrumentScheduled.js +36 -15
  42. package/build/esm/instrumentations/worker/instrumentScheduled.js.map +1 -1
  43. package/build/esm/instrumentations/worker/instrumentTail.js +34 -12
  44. package/build/esm/instrumentations/worker/instrumentTail.js.map +1 -1
  45. package/build/esm/package.json +1 -1
  46. package/build/esm/request.js +5 -6
  47. package/build/esm/request.js.map +1 -1
  48. package/build/esm/scope-utils.js.map +1 -1
  49. package/build/esm/utils/isCloudflareClass.js +27 -0
  50. package/build/esm/utils/isCloudflareClass.js.map +1 -0
  51. package/build/esm/withSentry.js +32 -21
  52. package/build/esm/withSentry.js.map +1 -1
  53. package/build/esm/wrapMethodWithSentry.js +107 -107
  54. package/build/esm/wrapMethodWithSentry.js.map +1 -1
  55. package/build/types/durableobject.d.ts.map +1 -1
  56. package/build/types/index.d.ts +1 -1
  57. package/build/types/index.d.ts.map +1 -1
  58. package/build/types/instrument.d.ts +15 -4
  59. package/build/types/instrument.d.ts.map +1 -1
  60. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts +42 -0
  61. package/build/types/instrumentations/instrumentWorkerEntrypoint.d.ts.map +1 -0
  62. package/build/types/instrumentations/worker/instrumentEmail.d.ts +2 -1
  63. package/build/types/instrumentations/worker/instrumentEmail.d.ts.map +1 -1
  64. package/build/types/instrumentations/worker/instrumentFetch.d.ts +6 -1
  65. package/build/types/instrumentations/worker/instrumentFetch.d.ts.map +1 -1
  66. package/build/types/instrumentations/worker/instrumentQueue.d.ts +6 -1
  67. package/build/types/instrumentations/worker/instrumentQueue.d.ts.map +1 -1
  68. package/build/types/instrumentations/worker/instrumentScheduled.d.ts +6 -1
  69. package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
  70. package/build/types/instrumentations/worker/instrumentTail.d.ts +6 -1
  71. package/build/types/instrumentations/worker/instrumentTail.d.ts.map +1 -1
  72. package/build/types/request.d.ts +3 -3
  73. package/build/types/request.d.ts.map +1 -1
  74. package/build/types/scope-utils.d.ts +2 -2
  75. package/build/types/scope-utils.d.ts.map +1 -1
  76. package/build/types/utils/isCloudflareClass.d.ts +30 -0
  77. package/build/types/utils/isCloudflareClass.d.ts.map +1 -0
  78. package/build/types/withSentry.d.ts +3 -2
  79. package/build/types/withSentry.d.ts.map +1 -1
  80. package/build/types-ts3.8/index.d.ts +1 -1
  81. package/build/types-ts3.8/instrument.d.ts +15 -4
  82. package/build/types-ts3.8/instrumentations/instrumentWorkerEntrypoint.d.ts +42 -0
  83. package/build/types-ts3.8/instrumentations/worker/instrumentEmail.d.ts +2 -1
  84. package/build/types-ts3.8/instrumentations/worker/instrumentFetch.d.ts +6 -1
  85. package/build/types-ts3.8/instrumentations/worker/instrumentQueue.d.ts +6 -1
  86. package/build/types-ts3.8/instrumentations/worker/instrumentScheduled.d.ts +6 -1
  87. package/build/types-ts3.8/instrumentations/worker/instrumentTail.d.ts +6 -1
  88. package/build/types-ts3.8/request.d.ts +3 -3
  89. package/build/types-ts3.8/scope-utils.d.ts +2 -2
  90. package/build/types-ts3.8/utils/isCloudflareClass.d.ts +30 -0
  91. package/build/types-ts3.8/withSentry.d.ts +3 -2
  92. package/package.json +2 -2
@@ -65,16 +65,18 @@ function instrumentDurableObjectWithSentry
65
65
 
66
66
  // Any other public methods on the Durable Object instance are RPC calls.
67
67
 
68
- if (obj.fetch && typeof obj.fetch === 'function' && !instrument.isInstrumented(obj.fetch)) {
69
- obj.fetch = new Proxy(obj.fetch, {
70
- apply(target, thisArg, args) {
71
- return request.wrapRequestHandler({ options: options$1, request: args[0], context }, () =>
72
- Reflect.apply(target, thisArg, args),
73
- );
74
- },
75
- });
76
-
77
- instrument.markAsInstrumented(obj.fetch);
68
+ if (obj.fetch && typeof obj.fetch === 'function') {
69
+ obj.fetch = instrument.ensureInstrumented(
70
+ obj.fetch,
71
+ original =>
72
+ new Proxy(original, {
73
+ apply(target, thisArg, args) {
74
+ return request.wrapRequestHandler({ options: options$1, request: args[0], context }, () => {
75
+ return Reflect.apply(target, thisArg, args);
76
+ });
77
+ },
78
+ }),
79
+ );
78
80
  }
79
81
 
80
82
  if (obj.alarm && typeof obj.alarm === 'function') {
@@ -175,7 +177,18 @@ function instrumentPrototype(target, methodsToInstrument) {
175
177
  methodNames.forEach(methodName => {
176
178
  const originalMethod = (proto )[methodName];
177
179
 
178
- if (!originalMethod || instrument.isInstrumented(originalMethod)) {
180
+ if (!originalMethod) {
181
+ return;
182
+ }
183
+
184
+ const existingInstrumented = instrument.getInstrumented(originalMethod);
185
+ if (existingInstrumented) {
186
+ Object.defineProperty(proto, methodName, {
187
+ value: existingInstrumented,
188
+ enumerable: false,
189
+ writable: true,
190
+ configurable: true,
191
+ });
179
192
  return;
180
193
  }
181
194
 
@@ -213,6 +226,11 @@ function instrumentPrototype(target, methodsToInstrument) {
213
226
  return wrapper.apply(this, args);
214
227
  };
215
228
 
229
+ // Only mark wrappedMethod as instrumented (not originalMethod → wrappedMethod).
230
+ // originalMethod must stay unmapped because wrappedMethod calls
231
+ // wrapMethodWithSentry(options, originalMethod) on each invocation to create
232
+ // a per-instance proxy. If originalMethod mapped to wrappedMethod, that call
233
+ // would return wrappedMethod itself, causing infinite recursion.
216
234
  instrument.markAsInstrumented(wrappedMethod);
217
235
 
218
236
  // Replace the prototype method
@@ -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 { isInstrumented, markAsInstrumented } from './instrument';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { UncheckedMethod } from './wrapMethodWithSentry';\nimport { wrapMethodWithSentry } from './wrapMethodWithSentry';\n\n/**\n * Instruments a Durable Object class to capture errors and performance data.\n *\n * Instruments the following methods:\n * - fetch\n * - alarm\n * - webSocketMessage\n * - webSocketClose\n * - webSocketError\n *\n * as well as any other public RPC methods on the Durable Object instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param DurableObjectClass The Durable Object class to instrument.\n * @returns The instrumented Durable Object class.\n *\n * @example\n * ```ts\n * class MyDurableObjectBase extends DurableObject {\n * constructor(ctx: DurableObjectState, env: Env) {\n * super(ctx, env);\n * }\n * }\n *\n * export const MyDurableObject = instrumentDurableObjectWithSentry(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyDurableObjectBase,\n * );\n * ```\n */\nexport function instrumentDurableObjectWithSentry<\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\n const options = getFinalOptions(optionsCallback(env), env);\n\n const obj = new target(context, env);\n\n // These are the methods that are available on a Durable Object\n // ref: https://developers.cloudflare.com/durable-objects/api/base/\n // obj.alarm\n // obj.fetch\n // obj.webSocketError\n // obj.webSocketClose\n // obj.webSocketMessage\n\n // Any other public methods on the Durable Object instance are RPC calls.\n\n if (obj.fetch && typeof obj.fetch === 'function' && !isInstrumented(obj.fetch)) {\n obj.fetch = new Proxy(obj.fetch, {\n apply(target, thisArg, args) {\n return wrapRequestHandler({ options, request: args[0], context }, () =>\n Reflect.apply(target, thisArg, args),\n );\n },\n });\n\n markAsInstrumented(obj.fetch);\n }\n\n if (obj.alarm && typeof obj.alarm === 'function') {\n obj.alarm = wrapMethodWithSentry({ options, context, spanName: 'alarm' }, obj.alarm);\n }\n\n if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {\n obj.webSocketMessage = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketMessage' },\n obj.webSocketMessage,\n );\n }\n\n if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {\n obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose);\n }\n\n if (obj.webSocketError && typeof obj.webSocketError === 'function') {\n obj.webSocketError = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketError' },\n obj.webSocketError,\n (_, error) =>\n captureException(error, {\n mechanism: {\n type: 'auto.faas.cloudflare.durable_object_websocket',\n handled: false,\n },\n }),\n );\n }\n\n for (const method of Object.getOwnPropertyNames(obj)) {\n if (\n method === 'fetch' ||\n method === 'alarm' ||\n method === 'webSocketError' ||\n method === 'webSocketClose' ||\n method === 'webSocketMessage'\n ) {\n continue;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const value = (obj as any)[method] as unknown;\n if (typeof value === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (obj as any)[method] = wrapMethodWithSentry(\n { options, context, spanName: method, spanOp: 'rpc' },\n value as UncheckedMethod,\n );\n }\n }\n\n // Store context and options on the instance for prototype methods to access\n Object.defineProperty(obj, '__SENTRY_CONTEXT__', {\n value: context,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n Object.defineProperty(obj, '__SENTRY_OPTIONS__', {\n value: options,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n if (options?.instrumentPrototypeMethods) {\n instrumentPrototype(target, options.instrumentPrototypeMethods);\n }\n\n return obj;\n },\n });\n}\n\nfunction instrumentPrototype<T extends NewableFunction>(target: T, methodsToInstrument: boolean | string[]): void {\n const proto = target.prototype;\n\n // Get all methods from the prototype chain\n const methodNames = new Set<string>();\n let current = proto;\n\n while (current && current !== Object.prototype) {\n Object.getOwnPropertyNames(current).forEach(name => {\n if (name !== 'constructor' && typeof (current as Record<string, unknown>)[name] === 'function') {\n methodNames.add(name);\n }\n });\n current = Object.getPrototypeOf(current);\n }\n\n // Create a set for efficient lookups when methodsToInstrument is an array\n const methodsToInstrumentSet = Array.isArray(methodsToInstrument) ? new Set(methodsToInstrument) : null;\n\n // Instrument each method on the prototype\n methodNames.forEach(methodName => {\n const originalMethod = (proto as Record<string, unknown>)[methodName];\n\n if (!originalMethod || isInstrumented(originalMethod)) {\n return;\n }\n\n // If methodsToInstrument is an array, only instrument methods in that set\n if (methodsToInstrumentSet && !methodsToInstrumentSet.has(methodName)) {\n return;\n }\n\n // Create a wrapper that gets context/options from the instance at runtime\n const wrappedMethod = function (this: unknown, ...args: unknown[]): unknown {\n const thisWithSentry = this as {\n __SENTRY_CONTEXT__: DurableObjectState;\n __SENTRY_OPTIONS__: CloudflareOptions;\n };\n const instanceContext = thisWithSentry.__SENTRY_CONTEXT__;\n const instanceOptions = thisWithSentry.__SENTRY_OPTIONS__;\n\n if (!instanceOptions) {\n // Fallback to original method if no Sentry data found\n return (originalMethod as UncheckedMethod).apply(this, args);\n }\n\n // Use the existing wrapper but with instance-specific context/options\n const wrapper = wrapMethodWithSentry(\n {\n options: instanceOptions,\n context: instanceContext,\n spanName: methodName,\n spanOp: 'rpc',\n },\n originalMethod as UncheckedMethod,\n undefined,\n true, // noMark = true since we'll mark the prototype method\n );\n\n return wrapper.apply(this, args);\n };\n\n markAsInstrumented(wrappedMethod);\n\n // Replace the prototype method\n Object.defineProperty(proto, methodName, {\n value: wrappedMethod,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","isInstrumented","wrapRequestHandler","markAsInstrumented","wrapMethodWithSentry","captureException"],"mappings":";;;;;;;;;;AAAA;;AAYA;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;;AAE5C,MAAM,MAAMC,SAAA,GAAUC,uBAAe,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;;AAEhE,MAAM,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,MAAM,IAAI,GAAG,CAAC,SAAS,OAAO,GAAG,CAAC,KAAA,KAAU,UAAA,IAAc,CAACC,yBAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;AACtF,QAAQ,GAAG,CAAC,KAAA,GAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE;AACzC,UAAU,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AACvC,YAAY,OAAOC,0BAAkB,CAAC,WAAEH,SAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE;AAC9E,cAAc,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC;AAClD,aAAa;AACb,UAAU,CA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,CAAC,kBAAkB;;AAE/D,MAAM,IAAI,CAAC,eAAe,EAAE;AAC5B;AACA,QAAQ,OAAO,CAAC,cAAA,GAAmC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACpE,MAAM;;AAEN;AACA,MAAM,MAAM,OAAA,GAAUG,yCAAoB;AAC1C,QAAQ;AACR,UAAU,OAAO,EAAE,eAAe;AAClC,UAAU,OAAO,EAAE,eAAe;AAClC,UAAU,QAAQ,EAAE,UAAU;AAC9B,UAAU,MAAM,EAAE,KAAK;AACvB,SAAS;AACT,QAAQ,cAAA;AACR,QAAQ,SAAS;AACjB,QAAQ,IAAI;AACZ,OAAO;;AAEP,MAAM,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACtC,IAAI,CAAC;;AAEL,IAAID,6BAAkB,CAAC,aAAa,CAAC;;AAErC;AACA,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE;AAC7C,MAAM,KAAK,EAAE,aAAa;AAC1B,MAAM,UAAU,EAAE,KAAK;AACvB,MAAM,QAAQ,EAAE,IAAI;AACpB,MAAM,YAAY,EAAE,IAAI;AACxB,KAAK,CAAC;AACN,EAAE,CAAC,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, getInstrumented, markAsInstrumented } from './instrument';\nimport { getFinalOptions } from './options';\nimport { wrapRequestHandler } from './request';\nimport { instrumentContext } from './utils/instrumentContext';\nimport type { UncheckedMethod } from './wrapMethodWithSentry';\nimport { wrapMethodWithSentry } from './wrapMethodWithSentry';\n\n/**\n * Instruments a Durable Object class to capture errors and performance data.\n *\n * Instruments the following methods:\n * - fetch\n * - alarm\n * - webSocketMessage\n * - webSocketClose\n * - webSocketError\n *\n * as well as any other public RPC methods on the Durable Object instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param DurableObjectClass The Durable Object class to instrument.\n * @returns The instrumented Durable Object class.\n *\n * @example\n * ```ts\n * class MyDurableObjectBase extends DurableObject {\n * constructor(ctx: DurableObjectState, env: Env) {\n * super(ctx, env);\n * }\n * }\n *\n * export const MyDurableObject = instrumentDurableObjectWithSentry(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyDurableObjectBase,\n * );\n * ```\n */\nexport function instrumentDurableObjectWithSentry<\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\n const options = getFinalOptions(optionsCallback(env), env);\n\n const obj = new target(context, env);\n\n // These are the methods that are available on a Durable Object\n // ref: https://developers.cloudflare.com/durable-objects/api/base/\n // obj.alarm\n // obj.fetch\n // obj.webSocketError\n // obj.webSocketClose\n // obj.webSocketMessage\n\n // Any other public methods on the Durable Object instance are RPC calls.\n\n if (obj.fetch && typeof obj.fetch === 'function') {\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 obj.alarm = wrapMethodWithSentry({ options, context, spanName: 'alarm' }, obj.alarm);\n }\n\n if (obj.webSocketMessage && typeof obj.webSocketMessage === 'function') {\n obj.webSocketMessage = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketMessage' },\n obj.webSocketMessage,\n );\n }\n\n if (obj.webSocketClose && typeof obj.webSocketClose === 'function') {\n obj.webSocketClose = wrapMethodWithSentry({ options, context, spanName: 'webSocketClose' }, obj.webSocketClose);\n }\n\n if (obj.webSocketError && typeof obj.webSocketError === 'function') {\n obj.webSocketError = wrapMethodWithSentry(\n { options, context, spanName: 'webSocketError' },\n obj.webSocketError,\n (_, error) =>\n captureException(error, {\n mechanism: {\n type: 'auto.faas.cloudflare.durable_object_websocket',\n handled: false,\n },\n }),\n );\n }\n\n for (const method of Object.getOwnPropertyNames(obj)) {\n if (\n method === 'fetch' ||\n method === 'alarm' ||\n method === 'webSocketError' ||\n method === 'webSocketClose' ||\n method === 'webSocketMessage'\n ) {\n continue;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n const value = (obj as any)[method] as unknown;\n if (typeof value === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n (obj as any)[method] = wrapMethodWithSentry(\n { options, context, spanName: method, spanOp: 'rpc' },\n value as UncheckedMethod,\n );\n }\n }\n\n // Store context and options on the instance for prototype methods to access\n Object.defineProperty(obj, '__SENTRY_CONTEXT__', {\n value: context,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n Object.defineProperty(obj, '__SENTRY_OPTIONS__', {\n value: options,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n if (options?.instrumentPrototypeMethods) {\n instrumentPrototype(target, options.instrumentPrototypeMethods);\n }\n\n return obj;\n },\n });\n}\n\nfunction instrumentPrototype<T extends NewableFunction>(target: T, methodsToInstrument: boolean | string[]): void {\n const proto = target.prototype;\n\n // Get all methods from the prototype chain\n const methodNames = new Set<string>();\n let current = proto;\n\n while (current && current !== Object.prototype) {\n Object.getOwnPropertyNames(current).forEach(name => {\n if (name !== 'constructor' && typeof (current as Record<string, unknown>)[name] === 'function') {\n methodNames.add(name);\n }\n });\n current = Object.getPrototypeOf(current);\n }\n\n // Create a set for efficient lookups when methodsToInstrument is an array\n const methodsToInstrumentSet = Array.isArray(methodsToInstrument) ? new Set(methodsToInstrument) : null;\n\n // Instrument each method on the prototype\n methodNames.forEach(methodName => {\n const originalMethod = (proto as Record<string, unknown>)[methodName];\n\n if (!originalMethod) {\n return;\n }\n\n const existingInstrumented = getInstrumented(originalMethod);\n if (existingInstrumented) {\n Object.defineProperty(proto, methodName, {\n value: existingInstrumented,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n return;\n }\n\n // If methodsToInstrument is an array, only instrument methods in that set\n if (methodsToInstrumentSet && !methodsToInstrumentSet.has(methodName)) {\n return;\n }\n\n // Create a wrapper that gets context/options from the instance at runtime\n const wrappedMethod = function (this: unknown, ...args: unknown[]): unknown {\n const thisWithSentry = this as {\n __SENTRY_CONTEXT__: DurableObjectState;\n __SENTRY_OPTIONS__: CloudflareOptions;\n };\n const instanceContext = thisWithSentry.__SENTRY_CONTEXT__;\n const instanceOptions = thisWithSentry.__SENTRY_OPTIONS__;\n\n if (!instanceOptions) {\n // Fallback to original method if no Sentry data found\n return (originalMethod as UncheckedMethod).apply(this, args);\n }\n\n // Use the existing wrapper but with instance-specific context/options\n const wrapper = wrapMethodWithSentry(\n {\n options: instanceOptions,\n context: instanceContext,\n spanName: methodName,\n spanOp: 'rpc',\n },\n originalMethod as UncheckedMethod,\n undefined,\n true, // noMark = true since we'll mark the prototype method\n );\n\n return wrapper.apply(this, args);\n };\n\n // Only mark wrappedMethod as instrumented (not originalMethod → wrappedMethod).\n // originalMethod must stay unmapped because wrappedMethod calls\n // wrapMethodWithSentry(options, originalMethod) on each invocation to create\n // a per-instance proxy. If originalMethod mapped to wrappedMethod, that call\n // would return wrappedMethod itself, causing infinite recursion.\n markAsInstrumented(wrappedMethod);\n\n // Replace the prototype method\n Object.defineProperty(proto, methodName, {\n value: wrappedMethod,\n enumerable: false,\n writable: true,\n configurable: true,\n });\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","ensureInstrumented","wrapRequestHandler","wrapMethodWithSent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UAAU,CAAC,EAAE;AAC3E,MAAM;AACN,IAAI;;AAEJ;AACA,IAAI,MAAM,gBAAgB,WAAyB,GAAG,IAAI,EAAsB;AAChF,MAAM,MAAM,cAAA,GAAiB;;AAGvB;AACN,MAAM,MAAM,eAAA,GAAkB,cAAc,CAAC,kBAAkB;AAC/D,MAAM,MAAM,eAAA,GAAkB,cAAc,CAAC,kBAAkB;;AAE/D,MAAM,IAAI,CAAC,eAAe,EAAE;AAC5B;AACA,QAAQ,OAAO,CAAC,cAAA,GAAmC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACpE,MAAM;;AAEN;AACA,MAAM,MAAM,OAAA,GAAUF,yCAAoB;AAC1C,QAAQ;AACR,UAAU,OAAO,EAAE,eAAe;AAClC,UAAU,OAAO,EAAE,eAAe;AAClC,UAAU,QAAQ,EAAE,UAAU;AAC9B,UAAU,MAAM,EAAE,KAAK;AACvB,SAAS;AACT,QAAQ,cAAA;AACR,QAAQ,SAAS;AACjB,QAAQ,IAAI;AACZ,OAAO;;AAEP,MAAM,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC;AACtC,IAAI,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA,IAAIG,6BAAkB,CAAC,aAAa,CAAC;;AAErC;AACA,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE;AAC7C,MAAM,KAAK,EAAE,aAAa;AAC1B,MAAM,UAAU,EAAE,KAAK;AACvB,MAAM,QAAQ,EAAE,IAAI;AACpB,MAAM,YAAY,EAAE,IAAI;AACxB,KAAK,CAAC;AACN,EAAE,CAAC,CAAC;AACJ;;;;"}
@@ -58,6 +58,7 @@ exports.growthbookIntegration = core.growthbookIntegration;
58
58
  exports.inboundFiltersIntegration = core.inboundFiltersIntegration;
59
59
  exports.instrumentAnthropicAiClient = core.instrumentAnthropicAiClient;
60
60
  exports.instrumentGoogleGenAIClient = core.instrumentGoogleGenAIClient;
61
+ exports.instrumentLangChainEmbeddings = core.instrumentLangChainEmbeddings;
61
62
  exports.instrumentLangGraph = core.instrumentLangGraph;
62
63
  exports.instrumentOpenAiClient = core.instrumentOpenAiClient;
63
64
  exports.instrumentPostgresJsSql = core.instrumentPostgresJsSql;
@@ -96,6 +97,7 @@ exports.withActiveSpan = core.withActiveSpan;
96
97
  exports.withIsolationScope = core.withIsolationScope;
97
98
  exports.withMonitor = core.withMonitor;
98
99
  exports.withScope = core.withScope;
100
+ exports.withStreamedSpan = core.withStreamedSpan;
99
101
  exports.wrapMcpServerWithSentry = core.wrapMcpServerWithSentry;
100
102
  exports.zodErrorsIntegration = core.zodErrorsIntegration;
101
103
  exports.withSentry = withSentry.withSentry;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,27 +1,91 @@
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
11
+ function getInstrumentedMap() {
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const globalObj = globalThis ;
14
+ if (!globalObj[GLOBAL_KEY]) {
15
+ globalObj[GLOBAL_KEY] = new WeakMap();
16
+ }
17
+ return globalObj[GLOBAL_KEY];
18
+ }
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
+ function isWeakMapKey(value) {
25
+ return (typeof value === 'object' && value !== null) || typeof value === 'function';
26
+ }
27
+
3
28
  /**
4
- * Mark an object as instrumented.
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)
5
32
  */
6
- function markAsInstrumented(obj) {
33
+ function markAsInstrumented(original, instrumented) {
7
34
  try {
8
- (obj ).__SENTRY_INSTRUMENTED__ = true;
35
+ if (isWeakMapKey(original)) {
36
+ // Store mapping from original to instrumented version
37
+ // If instrumented is not provided, store original (for backwards compat)
38
+ getInstrumentedMap().set(original, instrumented ?? original);
39
+ }
40
+ // Also mark the instrumented version itself so we recognize it
41
+ if (isWeakMapKey(instrumented) && instrumented !== original) {
42
+ getInstrumentedMap().set(instrumented, instrumented);
43
+ }
9
44
  } catch {
10
45
  // ignore errors here
11
46
  }
12
47
  }
13
48
 
14
49
  /**
15
- * Check if an object is instrumented.
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.
16
53
  */
17
- function isInstrumented(obj) {
54
+ function getInstrumented(obj) {
18
55
  try {
19
- return (obj ).__SENTRY_INSTRUMENTED__;
56
+ if (isWeakMapKey(obj)) {
57
+ return getInstrumentedMap().get(obj) ;
58
+ }
59
+
60
+ return undefined;
20
61
  } catch {
21
- return false;
62
+ return undefined;
22
63
  }
23
64
  }
24
65
 
25
- exports.isInstrumented = isInstrumented;
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
+ function ensureInstrumented(original, instrumentFn, noMark) {
73
+ const existing = getInstrumented(original);
74
+
75
+ if (existing) {
76
+ return existing;
77
+ }
78
+
79
+ const instrumented = instrumentFn(original);
80
+
81
+ if (!noMark) {
82
+ markAsInstrumented(original, instrumented);
83
+ }
84
+
85
+ return instrumented;
86
+ }
87
+
88
+ exports.ensureInstrumented = ensureInstrumented;
89
+ exports.getInstrumented = getInstrumented;
26
90
  exports.markAsInstrumented = markAsInstrumented;
27
91
  //# sourceMappingURL=instrument.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrument.js","sources":["../../src/instrument.ts"],"sourcesContent":["type SentryInstrumented<T> = T & {\n __SENTRY_INSTRUMENTED__?: boolean;\n};\n\n/**\n * Mark an object as instrumented.\n */\nexport function markAsInstrumented<T>(obj: T): void {\n try {\n (obj as SentryInstrumented<T>).__SENTRY_INSTRUMENTED__ = true;\n } catch {\n // ignore errors here\n }\n}\n\n/**\n * Check if an object is instrumented.\n */\nexport function isInstrumented<T>(obj: T): boolean | undefined {\n try {\n return (obj as SentryInstrumented<T>).__SENTRY_INSTRUMENTED__;\n } catch {\n return false;\n }\n}\n"],"names":[],"mappings":";;AAIA;AACA;AACA;AACO,SAAS,kBAAkB,CAAI,GAAG,EAAW;AACpD,EAAE,IAAI;AACN,IAAI,CAAC,GAAA,GAA8B,uBAAA,GAA0B,IAAI;AACjE,EAAE,EAAE,MAAM;AACV;AACA,EAAE;AACF;;AAEA;AACA;AACA;AACO,SAAS,cAAc,CAAI,GAAG,EAA0B;AAC/D,EAAE,IAAI;AACN,IAAI,OAAO,CAAC,GAAA,GAA8B,uBAAuB;AACjE,EAAE,EAAE,MAAM;AACV,IAAI,OAAO,KAAK;AAChB,EAAE;AACF;;;;;"}
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;;;;;;"}
@@ -0,0 +1,101 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const async = require('../async.js');
4
+ const instrumentFetch = require('./worker/instrumentFetch.js');
5
+ const instrumentQueue = require('./worker/instrumentQueue.js');
6
+ const instrumentScheduled = require('./worker/instrumentScheduled.js');
7
+ const instrumentTail = require('./worker/instrumentTail.js');
8
+ const options = require('../options.js');
9
+ const instrumentContext = require('../utils/instrumentContext.js');
10
+
11
+ /**
12
+ * Instruments a WorkerEntrypoint class to capture errors and performance data.
13
+ *
14
+ * Instruments the following methods (same as `withSentry` for ExportedHandler):
15
+ * - fetch (HTTP requests)
16
+ * - scheduled (cron triggers)
17
+ * - queue (queue consumers)
18
+ * - email (email handlers)
19
+ * - tail (tail workers)
20
+ *
21
+ * as well as any other public RPC methods on the WorkerEntrypoint instance.
22
+ *
23
+ * @param optionsCallback Function that returns the options for the SDK initialization.
24
+ * @param WorkerEntrypointClass The WorkerEntrypoint class to instrument.
25
+ * @returns The instrumented WorkerEntrypoint class.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * class MyWorkerBase extends WorkerEntrypoint<Env> {
30
+ * async fetch(request: Request): Promise<Response> {
31
+ * return new Response('Hello World!');
32
+ * }
33
+ *
34
+ * async myRpcMethod(arg: string): Promise<string> {
35
+ * return `Hello ${arg}!`;
36
+ * }
37
+ * }
38
+ *
39
+ * export default instrumentWorkerEntrypoint(
40
+ * env => ({
41
+ * dsn: env.SENTRY_DSN,
42
+ * tracesSampleRate: 1.0,
43
+ * }),
44
+ * MyWorkerBase,
45
+ * );
46
+ * ```
47
+ */
48
+ function instrumentWorkerEntrypoint(
49
+ optionsCallback,
50
+ WorkerEntrypointClass,
51
+ ) {
52
+ // Set up AsyncLocalStorage strategy ONCE at instrumentation time, not per-request
53
+ // This is critical - calling this per-request would create a new AsyncLocalStorage
54
+ // each time, breaking scope isolation for concurrent requests
55
+ async.setAsyncLocalStorageAsyncContextStrategy();
56
+
57
+ return new Proxy(WorkerEntrypointClass, {
58
+ construct(target, [ctx, env]) {
59
+ const context = instrumentContext.instrumentContext(ctx);
60
+ const options$1 = options.getFinalOptions(optionsCallback(env), env);
61
+ const obj = new target(context, env);
62
+
63
+ // Override this.ctx to ensure the instrumented context is used
64
+ // This is necessary because the base WorkerEntrypoint class sets this.ctx
65
+ // from the constructor parameter, but we want users accessing this.ctx
66
+ // to get the instrumented version
67
+ if ('ctx' in obj) {
68
+ Object.defineProperty(obj, 'ctx', {
69
+ value: context,
70
+ writable: true,
71
+ enumerable: true,
72
+ configurable: true,
73
+ });
74
+ }
75
+
76
+ Object.defineProperty(obj, '__SENTRY_CONTEXT__', {
77
+ value: context,
78
+ enumerable: false,
79
+ writable: false,
80
+ configurable: false,
81
+ });
82
+
83
+ Object.defineProperty(obj, '__SENTRY_OPTIONS__', {
84
+ value: options$1,
85
+ enumerable: false,
86
+ writable: false,
87
+ configurable: false,
88
+ });
89
+
90
+ instrumentFetch.instrumentWorkerEntrypointFetch(obj, options$1, context);
91
+ instrumentScheduled.instrumentWorkerEntrypointScheduled(obj, options$1, context);
92
+ instrumentQueue.instrumentWorkerEntrypointQueue(obj, options$1, context);
93
+ instrumentTail.instrumentWorkerEntrypointTail(obj, options$1, context);
94
+
95
+ return obj;
96
+ },
97
+ });
98
+ }
99
+
100
+ exports.instrumentWorkerEntrypoint = instrumentWorkerEntrypoint;
101
+ //# sourceMappingURL=instrumentWorkerEntrypoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentWorkerEntrypoint.js","sources":["../../../src/instrumentations/instrumentWorkerEntrypoint.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from '../async';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport type { CloudflareOptions } from '../client';\nimport { instrumentWorkerEntrypointFetch } from './worker/instrumentFetch';\nimport { instrumentWorkerEntrypointQueue } from './worker/instrumentQueue';\nimport { instrumentWorkerEntrypointScheduled } from './worker/instrumentScheduled';\nimport { instrumentWorkerEntrypointTail } from './worker/instrumentTail';\nimport { getFinalOptions } from '../options';\nimport { instrumentContext } from '../utils/instrumentContext';\n\nexport type WorkerEntrypointConstructor<Env = typeof cloudflareEnv, Props = {}> = new (\n ctx: ExecutionContext,\n env: typeof cloudflareEnv,\n) => InstanceType<typeof WorkerEntrypoint<Env, Props>>;\n\n/**\n * Instruments a WorkerEntrypoint class to capture errors and performance data.\n *\n * Instruments the following methods (same as `withSentry` for ExportedHandler):\n * - fetch (HTTP requests)\n * - scheduled (cron triggers)\n * - queue (queue consumers)\n * - email (email handlers)\n * - tail (tail workers)\n *\n * as well as any other public RPC methods on the WorkerEntrypoint instance.\n *\n * @param optionsCallback Function that returns the options for the SDK initialization.\n * @param WorkerEntrypointClass The WorkerEntrypoint class to instrument.\n * @returns The instrumented WorkerEntrypoint class.\n *\n * @example\n * ```ts\n * class MyWorkerBase extends WorkerEntrypoint<Env> {\n * async fetch(request: Request): Promise<Response> {\n * return new Response('Hello World!');\n * }\n *\n * async myRpcMethod(arg: string): Promise<string> {\n * return `Hello ${arg}!`;\n * }\n * }\n *\n * export default instrumentWorkerEntrypoint(\n * env => ({\n * dsn: env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * }),\n * MyWorkerBase,\n * );\n * ```\n */\nexport function instrumentWorkerEntrypoint<T extends WorkerEntrypointConstructor>(\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n WorkerEntrypointClass: T,\n): T {\n // Set up AsyncLocalStorage strategy ONCE at instrumentation time, not per-request\n // This is critical - calling this per-request would create a new AsyncLocalStorage\n // each time, breaking scope isolation for concurrent requests\n setAsyncLocalStorageAsyncContextStrategy();\n\n return new Proxy(WorkerEntrypointClass, {\n construct(target, [ctx, env]) {\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n const obj = new target(context, env);\n\n // Override this.ctx to ensure the instrumented context is used\n // This is necessary because the base WorkerEntrypoint class sets this.ctx\n // from the constructor parameter, but we want users accessing this.ctx\n // to get the instrumented version\n if ('ctx' in obj) {\n Object.defineProperty(obj, 'ctx', {\n value: context,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n }\n\n Object.defineProperty(obj, '__SENTRY_CONTEXT__', {\n value: context,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n Object.defineProperty(obj, '__SENTRY_OPTIONS__', {\n value: options,\n enumerable: false,\n writable: false,\n configurable: false,\n });\n\n instrumentWorkerEntrypointFetch(obj, options, context);\n instrumentWorkerEntrypointScheduled(obj, options, context);\n instrumentWorkerEntrypointQueue(obj, options, context);\n instrumentWorkerEntrypointTail(obj, options, context);\n\n return obj;\n },\n });\n}\n"],"names":["setAsyncLocalStorageAsyncContextStrategy","instrumentContext","options","getFinalOptions","instrumentWorkerEntrypointFetch","instrumentWorkerEntrypointScheduled","instrumentWorkerEntrypointQueue","instrumentWorkerEntrypointTail"],"mappings":";;;;;;;;;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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AAC,GAAG,EAAEF,SAAO,EAAE,OAAO,CAAC;AAC5D,MAAMG,uDAAmC,CAAC,GAAG,EAAEH,SAAO,EAAE,OAAO,CAAC;AAChE,MAAMI,+CAA+B,CAAC,GAAG,EAAEJ,SAAO,EAAE,OAAO,CAAC;AAC5D,MAAMK,6CAA8B,CAAC,GAAG,EAAEL,SAAO,EAAE,OAAO,CAAC;;AAE3D,MAAM,OAAO,GAAG;AAChB,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;;;"}
@@ -57,23 +57,25 @@ function instrumentExportedHandlerEmail(
57
57
  handler,
58
58
  optionsCallback,
59
59
  ) {
60
- if (!('email' in handler) || typeof handler.email !== 'function' || instrument.isInstrumented(handler.email)) {
60
+ if (!('email' in handler) || typeof handler.email !== 'function') {
61
61
  return;
62
62
  }
63
63
 
64
- handler.email = new Proxy(handler.email, {
65
- apply(target, thisArg, args) {
66
- const [emailMessage, env, ctx] = args;
67
- const context = instrumentContext.instrumentContext(ctx);
68
- args[2] = context;
64
+ handler.email = instrument.ensureInstrumented(
65
+ handler.email,
66
+ original =>
67
+ new Proxy(original, {
68
+ apply(target, thisArg, args) {
69
+ const [emailMessage, env, ctx] = args;
70
+ const context = instrumentContext.instrumentContext(ctx);
71
+ args[2] = context;
69
72
 
70
- const options$1 = options.getFinalOptions(optionsCallback(env), env);
73
+ const options$1 = options.getFinalOptions(optionsCallback(env), env);
71
74
 
72
- return wrapEmailHandler(emailMessage, options$1, context, () => target.apply(thisArg, args));
73
- },
74
- });
75
-
76
- instrument.markAsInstrumented(handler.email);
75
+ return wrapEmailHandler(emailMessage, options$1, context, () => target.apply(thisArg, args));
76
+ },
77
+ }),
78
+ );
77
79
  }
78
80
 
79
81
  exports.instrumentExportedHandlerEmail = instrumentExportedHandlerEmail;
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentEmail.js","sources":["../../../../src/instrumentations/worker/instrumentEmail.ts"],"sourcesContent":["import type { EmailMessage, ExportedHandler } from '@cloudflare/workers-types';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { isInstrumented, markAsInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Core email handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapEmailHandler(\n emailMessage: EmailMessage,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.email',\n name: `Handle Email ${emailMessage.to}`,\n attributes: {\n 'faas.trigger': 'email',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.email',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments an email handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerEmail<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: Parameters<NonNullable<T['email']>>[1]) => CloudflareOptions | undefined,\n): void {\n if (!('email' in handler) || typeof handler.email !== 'function' || isInstrumented(handler.email)) {\n return;\n }\n\n handler.email = new Proxy(handler.email, {\n apply(target, thisArg, args: Parameters<NonNullable<T['email']>>) {\n const [emailMessage, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapEmailHandler(emailMessage, options, context, () => target.apply(thisArg, args));\n },\n });\n\n markAsInstrumented(handler.email);\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","isInstrumented","instrumentContext","options","getFinalOptions","markAsInstrumented"],"mappings":";;;;;;;;;;AAgBA;AACA;AACA;AACA,SAAS,gBAAgB;AACzB,EAAE,YAAY;AACd,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,EAAE;AACJ,EAAW;AACX,EAAE,OAAOA,uBAAkB,CAAC,cAAA,IAAkB;AAC9C,IAAI,MAAM,SAAA,GAAY,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;;AAErD,IAAI,MAAM,MAAA,GAASC,QAAI,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,OAAA,EAAS,CAAC;AACrD,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC;;AAEpC,IAAIC,kCAAuB,CAAC,cAAc,CAAC;;AAE3C,IAAI,OAAOC,cAAS;AACpB,MAAM;AACN,QAAQ,EAAE,EAAE,YAAY;AACxB,QAAQ,IAAI,EAAE,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,CAAC,CAAA;AACA,QAAA,UAAA,EAAA;AACA,UAAA,cAAA,EAAA,OAAA;AACA,UAAA,CAAAC,qCAAA,GAAA,4BAAA;AACA,UAAA,CAAAC,qCAAA,GAAA,MAAA;AACA,SAAA;AACA,OAAA;AACA,MAAA,YAAA;AACA,QAAA,IAAA;AACA,UAAA,OAAA,MAAA,EAAA,EAAA;AACA,QAAA,CAAA,CAAA,OAAA,CAAA,EAAA;AACA,UAAAC,qBAAA,CAAA,CAAA,EAAA,EAAA,SAAA,EAAA,EAAA,OAAA,EAAA,KAAA,EAAA,IAAA,EAAA,4BAAA,EAAA,EAAA,CAAA;AACA,UAAA,MAAA,CAAA;AACA,QAAA,CAAA,SAAA;AACA,UAAA,SAAA,CAAAC,qBAAA,CAAA,MAAA,CAAA,CAAA;AACA,QAAA;AACA,MAAA,CAAA;AACA,KAAA;AACA,EAAA,CAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,8BAAA;AACA,EAAA,OAAA;AACA,EAAA,eAAA;AACA,EAAA;AACA,EAAA,IAAA,EAAA,OAAA,IAAA,OAAA,CAAA,IAAA,OAAA,OAAA,CAAA,KAAA,KAAA,UAAA,IAAAC,yBAAA,CAAA,OAAA,CAAA,KAAA,CAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,CAAA,KAAA,GAAA,IAAA,KAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,IAAA,KAAA,CAAA,MAAA,EAAA,OAAA,EAAA,IAAA,EAAA;AACA,MAAA,MAAA,CAAA,YAAA,EAAA,GAAA,EAAA,GAAA,CAAA,GAAA,IAAA;AACA,MAAA,MAAA,OAAA,GAAAC,mCAAA,CAAA,GAAA,CAAA;AACA,MAAA,IAAA,CAAA,CAAA,CAAA,GAAA,OAAA;;AAEA,MAAA,MAAAC,SAAA,GAAAC,uBAAA,CAAA,eAAA,CAAA,GAAA,CAAA,EAAA,GAAA,CAAA;;AAEA,MAAA,OAAA,gBAAA,CAAA,YAAA,EAAAD,SAAA,EAAA,OAAA,EAAA,MAAA,MAAA,CAAA,KAAA,CAAA,OAAA,EAAA,IAAA,CAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA,CAAA;;AAEA,EAAAE,6BAAA,CAAA,OAAA,CAAA,KAAA,CAAA;AACA;;;;"}
1
+ {"version":3,"file":"instrumentEmail.js","sources":["../../../../src/instrumentations/worker/instrumentEmail.ts"],"sourcesContent":["import type { EmailMessage, ExportedHandler } from '@cloudflare/workers-types';\nimport type { env as cloudflareEnv } from 'cloudflare:workers';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Core email handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapEmailHandler(\n emailMessage: EmailMessage,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.email',\n name: `Handle Email ${emailMessage.to}`,\n attributes: {\n 'faas.trigger': 'email',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.email',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments an email handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerEmail<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('email' in handler) || typeof handler.email !== 'function') {\n return;\n }\n\n handler.email = ensureInstrumented(\n handler.email,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['email']>>) {\n const [emailMessage, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapEmailHandler(emailMessage, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions"],"mappings":";;;;;;;;;;AAiBA;AACA;AACA;AACA,SAAS,gBAAgB;AACzB,EAAE,YAAY;AACd,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,EAAE;AACJ,EAAW;AACX,EAAE,OAAOA,uBAAkB,CAAC,cAAA,IAAkB;AAC9C,IAAI,MAAM,SAAA,GAAY,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;;AAErD,IAAI,MAAM,MAAA,GAASC,QAAI,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,OAAA,EAAS,CAAC;AACrD,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC;;AAEpC,IAAIC,kCAAuB,CAAC,cAAc,CAAC;;AAE3C,IAAI,OAAOC,cAAS;AACpB,MAAM;AACN,QAAQ,EAAE,EAAE,YAAY;AACxB,QAAQ,IAAI,EAAE,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,CAAC,CAAA;AACA,QAAA,UAAA,EAAA;AACA,UAAA,cAAA,EAAA,OAAA;AACA,UAAA,CAAAC,qCAAA,GAAA,4BAAA;AACA,UAAA,CAAAC,qCAAA,GAAA,MAAA;AACA,SAAA;AACA,OAAA;AACA,MAAA,YAAA;AACA,QAAA,IAAA;AACA,UAAA,OAAA,MAAA,EAAA,EAAA;AACA,QAAA,CAAA,CAAA,OAAA,CAAA,EAAA;AACA,UAAAC,qBAAA,CAAA,CAAA,EAAA,EAAA,SAAA,EAAA,EAAA,OAAA,EAAA,KAAA,EAAA,IAAA,EAAA,4BAAA,EAAA,EAAA,CAAA;AACA,UAAA,MAAA,CAAA;AACA,QAAA,CAAA,SAAA;AACA,UAAA,SAAA,CAAAC,qBAAA,CAAA,MAAA,CAAA,CAAA;AACA,QAAA;AACA,MAAA,CAAA;AACA,KAAA;AACA,EAAA,CAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,8BAAA;AACA,EAAA,OAAA;AACA,EAAA,eAAA;AACA,EAAA;AACA,EAAA,IAAA,EAAA,OAAA,IAAA,OAAA,CAAA,IAAA,OAAA,OAAA,CAAA,KAAA,KAAA,UAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,CAAA,KAAA,GAAAC,6BAAA;AACA,IAAA,OAAA,CAAA,KAAA;AACA,IAAA,QAAA;AACA,MAAA,IAAA,KAAA,CAAA,QAAA,EAAA;AACA,QAAA,KAAA,CAAA,MAAA,EAAA,OAAA,EAAA,IAAA,EAAA;AACA,UAAA,MAAA,CAAA,YAAA,EAAA,GAAA,EAAA,GAAA,CAAA,GAAA,IAAA;AACA,UAAA,MAAA,OAAA,GAAAC,mCAAA,CAAA,GAAA,CAAA;AACA,UAAA,IAAA,CAAA,CAAA,CAAA,GAAA,OAAA;;AAEA,UAAA,MAAAC,SAAA,GAAAC,uBAAA,CAAA,eAAA,CAAA,GAAA,CAAA,EAAA,GAAA,CAAA;;AAEA,UAAA,OAAA,gBAAA,CAAA,YAAA,EAAAD,SAAA,EAAA,OAAA,EAAA,MAAA,MAAA,CAAA,KAAA,CAAA,OAAA,EAAA,IAAA,CAAA,CAAA;AACA,QAAA,CAAA;AACA,OAAA,CAAA;AACA,GAAA;AACA;;;;"}
@@ -13,24 +13,49 @@ function instrumentExportedHandlerFetch(
13
13
  handler,
14
14
  optionsCallback,
15
15
  ) {
16
- if (!('fetch' in handler) || typeof handler.fetch !== 'function' || instrument.isInstrumented(handler.fetch)) {
16
+ if (!('fetch' in handler) || typeof handler.fetch !== 'function') {
17
17
  return;
18
18
  }
19
19
 
20
- handler.fetch = new Proxy(handler.fetch, {
21
- apply(target, thisArg, args) {
22
- const [request$1, env, ctx] = args;
23
- const context = instrumentContext.instrumentContext(ctx);
24
- args[2] = context;
20
+ handler.fetch = instrument.ensureInstrumented(
21
+ handler.fetch,
22
+ original =>
23
+ new Proxy(original, {
24
+ apply(target, thisArg, args) {
25
+ const [request$1, env, ctx] = args;
26
+ const context = instrumentContext.instrumentContext(ctx);
27
+ args[2] = context;
28
+
29
+ const options$1 = options.getFinalOptions(optionsCallback(env), env);
30
+
31
+ return request.wrapRequestHandler({ options: options$1, request: request$1, context }, () => target.apply(thisArg, args));
32
+ },
33
+ }),
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Instruments a fetch method for WorkerEntrypoint (options/context already available).
39
+ */
40
+ function instrumentWorkerEntrypointFetch(
41
+ instance,
42
+ options,
43
+ context,
44
+ ) {
45
+ if (!instance.fetch) {
46
+ return;
47
+ }
25
48
 
26
- const options$1 = options.getFinalOptions(optionsCallback(env), env);
49
+ const original = instance.fetch.bind(instance);
50
+ instance.fetch = new Proxy(original, {
51
+ apply(target, thisArg, args) {
52
+ const [request$1] = args;
27
53
 
28
- return request.wrapRequestHandler({ options: options$1, request: request$1, context }, () => target.apply(thisArg, args));
54
+ return request.wrapRequestHandler({ options, request: request$1, context }, () => Reflect.apply(target, thisArg, args));
29
55
  },
30
56
  });
31
-
32
- instrument.markAsInstrumented(handler.fetch);
33
57
  }
34
58
 
35
59
  exports.instrumentExportedHandlerFetch = instrumentExportedHandlerFetch;
60
+ exports.instrumentWorkerEntrypointFetch = instrumentWorkerEntrypointFetch;
36
61
  //# sourceMappingURL=instrumentFetch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentFetch.js","sources":["../../../../src/instrumentations/worker/instrumentFetch.ts"],"sourcesContent":["import type { ExportedHandler } from '@cloudflare/workers-types';\nimport type { CloudflareOptions } from '../../client';\nimport { isInstrumented, markAsInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { wrapRequestHandler } from '../../request';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Instruments a fetch handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerFetch<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: Parameters<NonNullable<T['fetch']>>[1]) => CloudflareOptions | undefined,\n): void {\n if (!('fetch' in handler) || typeof handler.fetch !== 'function' || isInstrumented(handler.fetch)) {\n return;\n }\n\n handler.fetch = new Proxy(handler.fetch, {\n apply(target, thisArg, args: Parameters<NonNullable<T['fetch']>>) {\n const [request, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));\n },\n });\n\n markAsInstrumented(handler.fetch);\n}\n"],"names":["isInstrumented","request","instrumentContext","options","getFinalOptions","wrapRequestHandler","markAsInstrumented"],"mappings":";;;;;;;AAOA;AACA;AACA;AACA;AACO,SAAS,8BAA8B;AAC9C,EAAE,OAAO;AACT,EAAE,eAAe;AACjB,EAAQ;AACR,EAAE,IAAI,EAAE,WAAW,OAAO,CAAA,IAAK,OAAO,OAAO,CAAC,KAAA,KAAU,cAAcA,yBAAc,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;AACrG,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,CAAC,KAAA,GAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE;AAC3C,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAuC;AACtE,MAAM,MAAM,CAACC,SAAO,EAAE,GAAG,EAAE,GAAG,CAAA,GAAI,IAAI;AACtC,MAAM,MAAM,OAAA,GAAUC,mCAAiB,CAAC,GAAG,CAAC;AAC5C,MAAM,IAAI,CAAC,CAAC,CAAA,GAAI,OAAO;;AAEvB,MAAM,MAAMC,SAAA,GAAUC,uBAAe,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;;AAEhE,MAAM,OAAOC,0BAAkB,CAAC,WAAEF,SAAO,WAAEF,SAAO,EAAE,OAAA,EAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACjG,IAAI,CAAC;AACL,GAAG,CAAC;;AAEJ,EAAEK,6BAAkB,CAAC,OAAO,CAAC,KAAK,CAAC;AACnC;;;;"}
1
+ {"version":3,"file":"instrumentFetch.js","sources":["../../../../src/instrumentations/worker/instrumentFetch.ts"],"sourcesContent":["import type { ExportedHandler } from '@cloudflare/workers-types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport type { CloudflareOptions } from '../../client';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { wrapRequestHandler } from '../../request';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Instruments a fetch handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerFetch<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('fetch' in handler) || typeof handler.fetch !== 'function') {\n return;\n }\n\n handler.fetch = ensureInstrumented(\n handler.fetch,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['fetch']>>) {\n const [request, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapRequestHandler({ options, request, context }, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a fetch method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointFetch<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.fetch) {\n return;\n }\n\n const original = instance.fetch.bind(instance);\n instance.fetch = new Proxy(original, {\n apply(target, thisArg, args: [Request]) {\n const [request] = args;\n\n return wrapRequestHandler({ options, request, context }, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":["ensureInstrumented","request","instrumentContext","options","getFinalOptions","wrapRequestHandler"],"mappings":";;;;;;;AAQA;AACA;AACA;AACA;AACO,SAAS,8BAA8B;AAC9C,EAAE,OAAO;AACT,EAAE,eAAe;AACjB,EAAQ;AACR,EAAE,IAAI,EAAE,WAAW,OAAO,CAAA,IAAK,OAAO,OAAO,CAAC,KAAA,KAAU,UAAU,EAAE;AACpE,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,CAAC,KAAA,GAAQA,6BAAkB;AACpC,IAAI,OAAO,CAAC,KAAK;AACjB,IAAI,QAAA;AACJ,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE;AAC1B,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAuC;AAC1E,UAAU,MAAM,CAACC,SAAO,EAAE,GAAG,EAAE,GAAG,CAAA,GAAI,IAAI;AAC1C,UAAU,MAAM,OAAA,GAAUC,mCAAiB,CAAC,GAAG,CAAC;AAChD,UAAU,IAAI,CAAC,CAAC,CAAA,GAAI,OAAO;;AAE3B,UAAU,MAAMC,SAAA,GAAUC,uBAAe,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;;AAEpE,UAAU,OAAOC,0BAAkB,CAAC,WAAEF,SAAO,WAAEF,SAAO,EAAE,OAAA,EAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACrG,QAAQ,CAAC;AACT,OAAO,CAAC;AACR,GAAG;AACH;;AAEA;AACA;AACA;AACO,SAAS,+BAA+B;AAC/C,EAAE,QAAQ;AACV,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAQ;AACR,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;AACvB,IAAI;AACJ,EAAE;;AAEF,EAAE,MAAM,QAAA,GAAW,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AAChD,EAAE,QAAQ,CAAC,KAAA,GAAQ,IAAI,KAAK,CAAC,QAAQ,EAAE;AACvC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAa;AAC5C,MAAM,MAAM,CAACA,SAAO,CAAA,GAAI,IAAI;;AAE5B,MAAM,OAAOI,0BAAkB,CAAC,EAAE,OAAO,WAAEJ,SAAO,EAAE,OAAA,EAAS,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;AAC1G,IAAI,CAAC;AACL,GAAG,CAAC;AACJ;;;;;"}
@@ -62,24 +62,49 @@ function instrumentExportedHandlerQueue(
62
62
  handler,
63
63
  optionsCallback,
64
64
  ) {
65
- if (!('queue' in handler) || typeof handler.queue !== 'function' || instrument.isInstrumented(handler.queue)) {
65
+ if (!('queue' in handler) || typeof handler.queue !== 'function') {
66
66
  return;
67
67
  }
68
68
 
69
- handler.queue = new Proxy(handler.queue, {
70
- apply(target, thisArg, args) {
71
- const [batch, env, ctx] = args;
72
- const context = instrumentContext.instrumentContext(ctx);
73
- args[2] = context;
69
+ handler.queue = instrument.ensureInstrumented(
70
+ handler.queue,
71
+ original =>
72
+ new Proxy(original, {
73
+ apply(target, thisArg, args) {
74
+ const [batch, env, ctx] = args;
75
+ const context = instrumentContext.instrumentContext(ctx);
76
+ args[2] = context;
77
+
78
+ const options$1 = options.getFinalOptions(optionsCallback(env), env);
74
79
 
75
- const options$1 = options.getFinalOptions(optionsCallback(env), env);
80
+ return wrapQueueHandler(batch, options$1, context, () => target.apply(thisArg, args));
81
+ },
82
+ }),
83
+ );
84
+ }
76
85
 
77
- return wrapQueueHandler(batch, options$1, context, () => target.apply(thisArg, args));
86
+ /**
87
+ * Instruments a queue method for WorkerEntrypoint (options/context already available).
88
+ */
89
+ function instrumentWorkerEntrypointQueue(
90
+ instance,
91
+ options,
92
+ context,
93
+ ) {
94
+ if (!instance.queue) {
95
+ return;
96
+ }
97
+
98
+ const original = instance.queue.bind(instance);
99
+ instance.queue = new Proxy(original, {
100
+ apply(target, thisArg, args) {
101
+ const [batch] = args;
102
+
103
+ return wrapQueueHandler(batch, options, context, () => Reflect.apply(target, thisArg, args));
78
104
  },
79
105
  });
80
-
81
- instrument.markAsInstrumented(handler.queue);
82
106
  }
83
107
 
84
108
  exports.instrumentExportedHandlerQueue = instrumentExportedHandlerQueue;
109
+ exports.instrumentWorkerEntrypointQueue = instrumentWorkerEntrypointQueue;
85
110
  //# sourceMappingURL=instrumentQueue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentQueue.js","sources":["../../../../src/instrumentations/worker/instrumentQueue.ts"],"sourcesContent":["import type { ExportedHandler, MessageBatch } from '@cloudflare/workers-types';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { isInstrumented, markAsInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Core queue handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapQueueHandler(\n batch: MessageBatch,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.queue',\n name: `process ${batch.queue}`,\n attributes: {\n 'faas.trigger': 'pubsub',\n 'messaging.destination.name': batch.queue,\n 'messaging.system': 'cloudflare',\n 'messaging.batch.message_count': batch.messages.length,\n 'messaging.message.retry.count': batch.messages.reduce((acc, message) => acc + message.attempts - 1, 0),\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'queue.process',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.queue',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a queue handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerQueue<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: Parameters<NonNullable<T['queue']>>[1]) => CloudflareOptions | undefined,\n): void {\n if (!('queue' in handler) || typeof handler.queue !== 'function' || isInstrumented(handler.queue)) {\n return;\n }\n\n handler.queue = new Proxy(handler.queue, {\n apply(target, thisArg, args: Parameters<NonNullable<T['queue']>>) {\n const [batch, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapQueueHandler(batch, options, context, () => target.apply(thisArg, args));\n },\n });\n\n markAsInstrumented(handler.queue);\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","isInstrumented","instrumentContext","options","getFinalOptions","markAsInstrumented"],"mappings":";;;;;;;;;;AAiBA;AACA;AACA;AACA,SAAS,gBAAgB;AACzB,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,OAAO;AACT,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,SAAA,CAAAC,qBAAA,CAAA,MAAA,CAAA,CAAA;AACA,QAAA;AACA,MAAA,CAAA;AACA,KAAA;AACA,EAAA,CAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,8BAAA;AACA,EAAA,OAAA;AACA,EAAA,eAAA;AACA,EAAA;AACA,EAAA,IAAA,EAAA,OAAA,IAAA,OAAA,CAAA,IAAA,OAAA,OAAA,CAAA,KAAA,KAAA,UAAA,IAAAC,yBAAA,CAAA,OAAA,CAAA,KAAA,CAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,OAAA,CAAA,KAAA,GAAA,IAAA,KAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,IAAA,KAAA,CAAA,MAAA,EAAA,OAAA,EAAA,IAAA,EAAA;AACA,MAAA,MAAA,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,CAAA,GAAA,IAAA;AACA,MAAA,MAAA,OAAA,GAAAC,mCAAA,CAAA,GAAA,CAAA;AACA,MAAA,IAAA,CAAA,CAAA,CAAA,GAAA,OAAA;;AAEA,MAAA,MAAAC,SAAA,GAAAC,uBAAA,CAAA,eAAA,CAAA,GAAA,CAAA,EAAA,GAAA,CAAA;;AAEA,MAAA,OAAA,gBAAA,CAAA,KAAA,EAAAD,SAAA,EAAA,OAAA,EAAA,MAAA,MAAA,CAAA,KAAA,CAAA,OAAA,EAAA,IAAA,CAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA,CAAA;;AAEA,EAAAE,6BAAA,CAAA,OAAA,CAAA,KAAA,CAAA;AACA;;;;"}
1
+ {"version":3,"file":"instrumentQueue.js","sources":["../../../../src/instrumentations/worker/instrumentQueue.ts"],"sourcesContent":["import type { ExportedHandler, MessageBatch } from '@cloudflare/workers-types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n captureException,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n startSpan,\n withIsolationScope,\n} from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\n\n/**\n * Core queue handler logic - wraps execution with Sentry instrumentation.\n */\nfunction wrapQueueHandler(\n batch: MessageBatch,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n return startSpan(\n {\n op: 'faas.queue',\n name: `process ${batch.queue}`,\n attributes: {\n 'faas.trigger': 'pubsub',\n 'messaging.destination.name': batch.queue,\n 'messaging.system': 'cloudflare',\n 'messaging.batch.message_count': batch.messages.length,\n 'messaging.message.retry.count': batch.messages.reduce((acc, message) => acc + message.attempts - 1, 0),\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'queue.process',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.queue',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n return await fn();\n } catch (e) {\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a queue handler for ExportedHandler (env/ctx come from args).\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function instrumentExportedHandlerQueue<T extends ExportedHandler<any, any, any>>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('queue' in handler) || typeof handler.queue !== 'function') {\n return;\n }\n\n handler.queue = ensureInstrumented(\n handler.queue,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['queue']>>) {\n const [batch, env, ctx] = args;\n const context = instrumentContext(ctx);\n args[2] = context;\n\n const options = getFinalOptions(optionsCallback(env), env);\n\n return wrapQueueHandler(batch, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a queue method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointQueue<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.queue) {\n return;\n }\n\n const original = instance.queue.bind(instance);\n instance.queue = new Proxy(original, {\n apply(target, thisArg, args: [MessageBatch]) {\n const [batch] = args;\n\n return wrapQueueHandler(batch, options, context, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":["withIsolationScope","init","addCloudResourceContext","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions"],"mappings":";;;;;;;;;;AAkBA;AACA;AACA;AACA,SAAS,gBAAgB;AACzB,EAAE,KAAK;AACP,EAAE,OAAO;AACT,EAAE,OAAO;AACT,EAAE,EAAE;AACJ,EAAW;AACX,EAAE,OAAOA,uBAAkB,CAAC,cAAA,IAAkB;AAC9C,IAAI,MAAM,SAAA,GAAY,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;;AAErD,IAAI,MAAM,MAAA,GAASC,QAAI,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,OAAA,EAAS,CAAC;AACrD,IAAI,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC;;AAEpC,IAAIC,kCAAuB,CAAC,cAAc,CAAC;;AAE3C,IAAI,OAAOC,cAAS;AACpB,MAAM;AACN,QAAQ,EAAE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