autotel-cloudflare 2.18.18 → 2.18.19

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 (56) hide show
  1. package/dist/actors.d.ts +54 -89
  2. package/dist/actors.d.ts.map +1 -0
  3. package/dist/actors.js +990 -986
  4. package/dist/actors.js.map +1 -1
  5. package/dist/agents.d.ts +102 -128
  6. package/dist/agents.d.ts.map +1 -0
  7. package/dist/agents.js +275 -259
  8. package/dist/agents.js.map +1 -1
  9. package/dist/bindings-D3lNJZmq.js +975 -0
  10. package/dist/bindings-D3lNJZmq.js.map +1 -0
  11. package/dist/bindings-xEZcXo5r.d.ts +149 -0
  12. package/dist/bindings-xEZcXo5r.d.ts.map +1 -0
  13. package/dist/bindings.d.ts +2 -139
  14. package/dist/bindings.js +3 -4
  15. package/dist/common-DiWH6nmG.js +63 -0
  16. package/dist/common-DiWH6nmG.js.map +1 -0
  17. package/dist/events.d.ts +1 -1
  18. package/dist/events.js +3 -3
  19. package/dist/execution-logger-BxmgP8jF.js +65 -0
  20. package/dist/execution-logger-BxmgP8jF.js.map +1 -0
  21. package/dist/{logger-Cm_73k3-.d.ts → execution-logger-tgQmJeeU.d.ts} +9 -7
  22. package/dist/execution-logger-tgQmJeeU.d.ts.map +1 -0
  23. package/dist/handlers-CMg9l_T-.js +378 -0
  24. package/dist/handlers-CMg9l_T-.js.map +1 -0
  25. package/dist/handlers-C_VojUeA.d.ts +96 -0
  26. package/dist/handlers-C_VojUeA.d.ts.map +1 -0
  27. package/dist/handlers.d.ts +2 -112
  28. package/dist/handlers.js +3 -4
  29. package/dist/index.d.ts +20 -99
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +644 -600
  32. package/dist/index.js.map +1 -1
  33. package/dist/logger.d.ts +3 -3
  34. package/dist/logger.js +5 -4
  35. package/dist/parse-error.d.ts +2 -1
  36. package/dist/parse-error.js +3 -3
  37. package/dist/sampling.d.ts +1 -4
  38. package/dist/sampling.js +3 -3
  39. package/dist/testing.d.ts +1 -1
  40. package/dist/testing.js +3 -3
  41. package/package.json +6 -6
  42. package/dist/bindings.js.map +0 -1
  43. package/dist/chunk-KAUHT25H.js +0 -1084
  44. package/dist/chunk-KAUHT25H.js.map +0 -1
  45. package/dist/chunk-MIDMNKDC.js +0 -333
  46. package/dist/chunk-MIDMNKDC.js.map +0 -1
  47. package/dist/chunk-O4IYKWPJ.js +0 -55
  48. package/dist/chunk-O4IYKWPJ.js.map +0 -1
  49. package/dist/chunk-RVVMMPWN.js +0 -63
  50. package/dist/chunk-RVVMMPWN.js.map +0 -1
  51. package/dist/events.js.map +0 -1
  52. package/dist/handlers.js.map +0 -1
  53. package/dist/logger.js.map +0 -1
  54. package/dist/parse-error.js.map +0 -1
  55. package/dist/sampling.js.map +0 -1
  56. package/dist/testing.js.map +0 -1
@@ -1,10 +1,11 @@
1
- import { TraceContext, ExecutionLogger, ExecutionLoggerOptions } from 'autotel-edge/logger';
1
+ import { ExecutionLogSnapshot, ExecutionLogger, ExecutionLoggerOptions, TraceContext } from "autotel-edge/logger";
2
2
 
3
+ //#region src/execution-logger.d.ts
3
4
  interface WorkersLoggerOptions {
4
- /** Override derived request id (default: cf-ray header value when present). */
5
- requestId?: string;
6
- /** Optional request header allowlist to include in logger context. */
7
- headers?: string[];
5
+ /** Override derived request id (default: cf-ray header value when present). */
6
+ requestId?: string;
7
+ /** Optional request header allowlist to include in logger context. */
8
+ headers?: string[];
8
9
  }
9
10
  /**
10
11
  * Create an execution logger pre-populated with common request context.
@@ -15,5 +16,6 @@ declare function getRequestLogger(ctx?: TraceContext, options?: ExecutionLoggerO
15
16
  declare function getQueueLogger(ctx?: TraceContext, options?: ExecutionLoggerOptions): ExecutionLogger;
16
17
  declare function getWorkflowLogger(ctx?: TraceContext, options?: ExecutionLoggerOptions): ExecutionLogger;
17
18
  declare function getActorLogger(ctx?: TraceContext, options?: ExecutionLoggerOptions): ExecutionLogger;
18
-
19
- export { type WorkersLoggerOptions as W, getQueueLogger as a, getRequestLogger as b, createWorkersLogger as c, getWorkflowLogger as d, getActorLogger as g };
19
+ //#endregion
20
+ export { createWorkersLogger as a, getRequestLogger as c, WorkersLoggerOptions as i, getWorkflowLogger as l, ExecutionLogger as n, getActorLogger as o, ExecutionLoggerOptions as r, getQueueLogger as s, ExecutionLogSnapshot as t };
21
+ //# sourceMappingURL=execution-logger-tgQmJeeU.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-logger-tgQmJeeU.d.ts","names":[],"sources":["../src/execution-logger.ts"],"mappings":";;;UAciB,oBAAA;EAAA;EAEf,SAAA;;EAEA,OAAO;AAAA;AAyCT;;;;AAAA,iBAAgB,mBAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,GAAS,oBAAA,EACT,GAAA,GAAM,YAAA,GACL,eAAA;AAAA,iBAsBa,gBAAA,CACd,GAAA,GAAM,YAAA,EACN,OAAA,GAAU,sBAAA,GACT,eAAA;AAAA,iBAIa,cAAA,CACd,GAAA,GAAM,YAAA,EACN,OAAA,GAAU,sBAAA,GACT,eAAA;AAAA,iBAIa,iBAAA,CACd,GAAA,GAAM,YAAA,EACN,OAAA,GAAU,sBAAA,GACT,eAAA;AAAA,iBAIa,cAAA,CACd,GAAA,GAAM,YAAA,EACN,OAAA,GAAU,sBAAA,GACT,eAAA"}
@@ -0,0 +1,378 @@
1
+ import { a as wrap } from "./common-DiWH6nmG.js";
2
+ import { createInitialiser, setConfig } from "autotel-edge";
3
+ import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
4
+
5
+ //#region src/handlers/durable-objects.ts
6
+ /**
7
+ * Durable Objects instrumentation for Cloudflare Workers
8
+ *
9
+ * Note: This file uses Cloudflare Workers types (DurableObjectId, DurableObjectState, etc.)
10
+ * which are globally available via @cloudflare/workers-types when listed in tsconfig.json.
11
+ * These types are devDependencies only - they're not runtime dependencies.
12
+ * At runtime, Cloudflare Workers runtime provides the actual implementations.
13
+ */
14
+ /**
15
+ * Track cold starts per DO class
16
+ */
17
+ const coldStarts$1 = /* @__PURE__ */ new WeakMap();
18
+ function isColdStart$1(doClass) {
19
+ if (!coldStarts$1.has(doClass)) {
20
+ coldStarts$1.set(doClass, true);
21
+ return true;
22
+ }
23
+ return false;
24
+ }
25
+ /**
26
+ * Instrument a Durable Object fetch method
27
+ */
28
+ function instrumentDOFetch(fetchFn, id, doClass) {
29
+ return async function instrumentedFetch(request) {
30
+ const tracer = trace.getTracer("autotel-edge");
31
+ const parentContext = propagation.extract(context.active(), request.headers);
32
+ const url = new URL(request.url);
33
+ const spanName = `DO ${id.name || id.toString()}: ${request.method} ${url.pathname}`;
34
+ return tracer.startActiveSpan(spanName, {
35
+ kind: SpanKind.SERVER,
36
+ attributes: {
37
+ "http.request.method": request.method,
38
+ "url.full": request.url,
39
+ "do.id": id.toString(),
40
+ "do.id.name": id.name || "",
41
+ "faas.trigger": "http",
42
+ "faas.coldstart": isColdStart$1(doClass)
43
+ }
44
+ }, parentContext, async (span) => {
45
+ try {
46
+ const response = await fetchFn.call(this, request);
47
+ span.setAttributes({ "http.response.status_code": response.status });
48
+ if (response.ok) span.setStatus({ code: SpanStatusCode.OK });
49
+ else span.setStatus({ code: SpanStatusCode.ERROR });
50
+ return response;
51
+ } catch (error) {
52
+ span.recordException(error);
53
+ span.setStatus({
54
+ code: SpanStatusCode.ERROR,
55
+ message: error instanceof Error ? error.message : String(error)
56
+ });
57
+ throw error;
58
+ } finally {
59
+ span.end();
60
+ }
61
+ });
62
+ };
63
+ }
64
+ /**
65
+ * Instrument a Durable Object alarm method
66
+ */
67
+ function instrumentDOAlarm(alarmFn, id, doClass) {
68
+ return async function instrumentedAlarm() {
69
+ const tracer = trace.getTracer("autotel-edge");
70
+ const spanName = `DO ${id.name || id.toString()}: alarm`;
71
+ return tracer.startActiveSpan(spanName, {
72
+ kind: SpanKind.INTERNAL,
73
+ attributes: {
74
+ "do.id": id.toString(),
75
+ "do.id.name": id.name || "",
76
+ "faas.trigger": "timer",
77
+ "faas.coldstart": isColdStart$1(doClass)
78
+ }
79
+ }, async (span) => {
80
+ try {
81
+ await alarmFn.call(this);
82
+ span.setStatus({ code: SpanStatusCode.OK });
83
+ } catch (error) {
84
+ span.recordException(error);
85
+ span.setStatus({
86
+ code: SpanStatusCode.ERROR,
87
+ message: error instanceof Error ? error.message : String(error)
88
+ });
89
+ throw error;
90
+ } finally {
91
+ span.end();
92
+ }
93
+ });
94
+ };
95
+ }
96
+ /**
97
+ * Instrument a Durable Object instance
98
+ */
99
+ function instrumentDOInstance(doInstance, state, _env, doClass) {
100
+ return wrap(doInstance, { get(target, prop) {
101
+ const value = Reflect.get(target, prop);
102
+ if (prop === "fetch" && typeof value === "function") return instrumentDOFetch(value.bind(target), state.id, doClass);
103
+ if (prop === "alarm" && typeof value === "function") return instrumentDOAlarm(value.bind(target), state.id, doClass);
104
+ if (typeof value === "function") return value.bind(target);
105
+ return value;
106
+ } });
107
+ }
108
+ /**
109
+ * Instrument a Durable Object class
110
+ *
111
+ * This wraps the DO class to automatically trace all fetch and alarm calls,
112
+ * as well as initialize the telemetry configuration.
113
+ *
114
+ * **Usage:**
115
+ * ```typescript
116
+ * import { DurableObject } from 'cloudflare:workers'
117
+ * import { instrumentDO } from 'autotel-edge'
118
+ *
119
+ * export class Counter extends DurableObject<Env> {
120
+ * async fetch(request: Request) {
121
+ * // Your DO logic here
122
+ * return new Response('OK')
123
+ * }
124
+ * }
125
+ *
126
+ * // Wrap the class before exporting
127
+ * export const CounterDO = instrumentDO(Counter, (env: Env) => ({
128
+ * exporter: {
129
+ * url: env.OTLP_ENDPOINT,
130
+ * headers: { 'x-api-key': env.API_KEY }
131
+ * },
132
+ * service: {
133
+ * name: 'my-durable-object',
134
+ * version: '1.0.0'
135
+ * }
136
+ * }))
137
+ * ```
138
+ *
139
+ * **What you get:**
140
+ * - 🎯 Automatic spans for fetch() calls with HTTP attributes
141
+ * - ⏰ Automatic spans for alarm() calls
142
+ * - 🥶 Cold start tracking
143
+ * - 🔗 Context propagation from incoming requests
144
+ * - ⚡ Automatic span lifecycle management
145
+ *
146
+ * @param doClass - The Durable Object class to instrument
147
+ * @param config - Configuration or configuration function
148
+ * @returns Instrumented Durable Object class
149
+ */
150
+ function instrumentDO(doClass, config) {
151
+ const initialiser = createInitialiser(config);
152
+ return wrap(doClass, { construct(target, [state, env]) {
153
+ const context$2 = setConfig(initialiser(env, {
154
+ id: state.id.toString(),
155
+ name: state.id.name
156
+ }));
157
+ return instrumentDOInstance(context.with(context$2, () => {
158
+ return new target(state, env);
159
+ }), state, env, doClass);
160
+ } });
161
+ }
162
+
163
+ //#endregion
164
+ //#region src/handlers/workflows.ts
165
+ /**
166
+ * Cloudflare Workflows instrumentation for autotel-edge
167
+ *
168
+ * Instruments WorkflowEntrypoint classes to automatically trace workflow execution,
169
+ * step operations, retries, and sleeps.
170
+ *
171
+ * Based on Cloudflare Workflows API:
172
+ * https://developers.cloudflare.com/workflows/
173
+ */
174
+ /**
175
+ * Track cold starts per Workflow class
176
+ */
177
+ const coldStarts = /* @__PURE__ */ new WeakMap();
178
+ function isColdStart(workflowClass) {
179
+ if (!coldStarts.has(workflowClass)) {
180
+ coldStarts.set(workflowClass, true);
181
+ return true;
182
+ }
183
+ return false;
184
+ }
185
+ /**
186
+ * Proxy the step object to instrument step.do(), step.sleep(), and step.sleepUntil() calls
187
+ */
188
+ function instrumentWorkflowStep(step, workflowName) {
189
+ return wrap(step, { get(target, prop) {
190
+ const value = Reflect.get(target, prop);
191
+ if (prop === "do" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
192
+ const [stepName] = args;
193
+ return trace.getTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: ${stepName}`, {
194
+ kind: SpanKind.INTERNAL,
195
+ attributes: {
196
+ "workflow.step.name": stepName,
197
+ "workflow.name": workflowName
198
+ }
199
+ }, async (span) => {
200
+ try {
201
+ const result = await Reflect.apply(fnTarget, thisArg, args);
202
+ span.setStatus({ code: SpanStatusCode.OK });
203
+ return result;
204
+ } catch (error) {
205
+ span.recordException(error);
206
+ span.setStatus({
207
+ code: SpanStatusCode.ERROR,
208
+ message: error instanceof Error ? error.message : String(error)
209
+ });
210
+ throw error;
211
+ } finally {
212
+ span.end();
213
+ }
214
+ });
215
+ } });
216
+ if (prop === "sleep" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
217
+ const [sleepName, duration] = args;
218
+ return trace.getTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: sleep ${sleepName}`, {
219
+ kind: SpanKind.INTERNAL,
220
+ attributes: {
221
+ "workflow.sleep.name": sleepName,
222
+ "workflow.sleep.duration": String(duration),
223
+ "workflow.name": workflowName
224
+ }
225
+ }, async (span) => {
226
+ try {
227
+ const result = await Reflect.apply(fnTarget, thisArg, args);
228
+ span.setStatus({ code: SpanStatusCode.OK });
229
+ return result;
230
+ } catch (error) {
231
+ span.recordException(error);
232
+ span.setStatus({
233
+ code: SpanStatusCode.ERROR,
234
+ message: error instanceof Error ? error.message : String(error)
235
+ });
236
+ throw error;
237
+ } finally {
238
+ span.end();
239
+ }
240
+ });
241
+ } });
242
+ if (prop === "sleepUntil" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
243
+ const [sleepName, timestamp] = args;
244
+ const tracer = trace.getTracer("autotel-edge");
245
+ const wakeAt = timestamp instanceof Date ? timestamp.toISOString() : new Date(timestamp).toISOString();
246
+ return tracer.startActiveSpan(`Workflow ${workflowName}: sleepUntil ${sleepName}`, {
247
+ kind: SpanKind.INTERNAL,
248
+ attributes: {
249
+ "workflow.sleep.name": sleepName,
250
+ "workflow.sleep.until": wakeAt,
251
+ "workflow.name": workflowName
252
+ }
253
+ }, async (span) => {
254
+ try {
255
+ const result = await Reflect.apply(fnTarget, thisArg, args);
256
+ span.setStatus({ code: SpanStatusCode.OK });
257
+ return result;
258
+ } catch (error) {
259
+ span.recordException(error);
260
+ span.setStatus({
261
+ code: SpanStatusCode.ERROR,
262
+ message: error instanceof Error ? error.message : String(error)
263
+ });
264
+ throw error;
265
+ } finally {
266
+ span.end();
267
+ }
268
+ });
269
+ } });
270
+ if (typeof value === "function") return value.bind(target);
271
+ return value;
272
+ } });
273
+ }
274
+ /**
275
+ * Instrument a Workflow run method
276
+ */
277
+ function instrumentWorkflowRun(runFn, workflowName, workflowClass) {
278
+ return async function instrumentedRun(event, step) {
279
+ const tracer = trace.getTracer("autotel-edge");
280
+ const instrumentedStep = instrumentWorkflowStep(step, workflowName);
281
+ const spanName = `Workflow ${workflowName}: run`;
282
+ return tracer.startActiveSpan(spanName, {
283
+ kind: SpanKind.INTERNAL,
284
+ attributes: {
285
+ "workflow.name": workflowName,
286
+ "workflow.instance_id": event.instanceId,
287
+ "faas.trigger": "workflow",
288
+ "faas.coldstart": isColdStart(workflowClass)
289
+ }
290
+ }, async (span) => {
291
+ try {
292
+ const result = await runFn.call(this, event, instrumentedStep);
293
+ span.setStatus({ code: SpanStatusCode.OK });
294
+ return result;
295
+ } catch (error) {
296
+ span.recordException(error);
297
+ span.setStatus({
298
+ code: SpanStatusCode.ERROR,
299
+ message: error instanceof Error ? error.message : String(error)
300
+ });
301
+ throw error;
302
+ } finally {
303
+ span.end();
304
+ }
305
+ });
306
+ };
307
+ }
308
+ /**
309
+ * Instrument a Workflow instance
310
+ */
311
+ function instrumentWorkflowInstance(workflowInstance, workflowName, workflowClass) {
312
+ return wrap(workflowInstance, { get(target, prop) {
313
+ const value = Reflect.get(target, prop);
314
+ if (prop === "run" && typeof value === "function") return instrumentWorkflowRun(value.bind(target), workflowName, workflowClass);
315
+ if (typeof value === "function") return value.bind(target);
316
+ return value;
317
+ } });
318
+ }
319
+ /**
320
+ * Instrument a Cloudflare Workflow class
321
+ *
322
+ * This wraps the WorkflowEntrypoint class to automatically trace workflow execution,
323
+ * step operations, retries, and sleeps.
324
+ *
325
+ * **Usage:**
326
+ * ```typescript
327
+ * import { WorkflowEntrypoint } from 'cloudflare:workers'
328
+ * import { instrumentWorkflow } from 'autotel-cloudflare/handlers'
329
+ *
330
+ * class MyWorkflow extends WorkflowEntrypoint {
331
+ * async run(event, step) {
332
+ * await step.do('submit payment', async () => {
333
+ * return await submitToPaymentProcessor(event.payload.payment)
334
+ * })
335
+ *
336
+ * await step.sleep('wait for feedback', '2 days')
337
+ *
338
+ * await step.do('send feedback email', sendFeedbackEmail)
339
+ * }
340
+ * }
341
+ *
342
+ * export const CheckoutWorkflow = instrumentWorkflow(
343
+ * MyWorkflow,
344
+ * 'checkout-workflow',
345
+ * (env: Env) => ({
346
+ * exporter: {
347
+ * url: env.OTLP_ENDPOINT,
348
+ * headers: { 'x-api-key': env.API_KEY }
349
+ * },
350
+ * service: {
351
+ * name: 'checkout-workflow',
352
+ * version: '1.0.0'
353
+ * }
354
+ * })
355
+ * )
356
+ * ```
357
+ *
358
+ * @param workflowClass - The WorkflowEntrypoint class to instrument
359
+ * @param workflowName - The name of the workflow (used in span names)
360
+ * @param config - Configuration or configuration function
361
+ * @returns Instrumented Workflow class
362
+ */
363
+ function instrumentWorkflow(workflowClass, workflowName, config) {
364
+ const initialiser = createInitialiser(config);
365
+ return wrap(workflowClass, { construct(target, args) {
366
+ const context$1 = setConfig(initialiser(args[args.length - 1] || {}, {
367
+ type: "workflow",
368
+ name: workflowName
369
+ }));
370
+ return instrumentWorkflowInstance(context.with(context$1, () => {
371
+ return new target(...args);
372
+ }), workflowName, workflowClass);
373
+ } });
374
+ }
375
+
376
+ //#endregion
377
+ export { instrumentDO as n, instrumentWorkflow as t };
378
+ //# sourceMappingURL=handlers-CMg9l_T-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers-CMg9l_T-.js","names":["coldStarts","isColdStart","api_context","context","context","api_context"],"sources":["../src/handlers/durable-objects.ts","../src/handlers/workflows.ts"],"sourcesContent":["/**\n * Durable Objects instrumentation for Cloudflare Workers\n * \n * Note: This file uses Cloudflare Workers types (DurableObjectId, DurableObjectState, etc.)\n * which are globally available via @cloudflare/workers-types when listed in tsconfig.json.\n * These types are devDependencies only - they're not runtime dependencies.\n * At runtime, Cloudflare Workers runtime provides the actual implementations.\n */\n\nimport {\n trace,\n context as api_context,\n propagation,\n SpanStatusCode,\n SpanKind,\n} from '@opentelemetry/api';\nimport type { ConfigurationOption } from 'autotel-edge';\nimport { createInitialiser, setConfig, WorkerTracer } from 'autotel-edge';\nimport { wrap } from '../bindings/common';\n\n// Durable Object types\ntype DOFetchFn = (request: Request) => Response | Promise<Response>;\ntype DOAlarmFn = () => void | Promise<void>;\n\n/**\n * Track cold starts per DO class\n */\nconst coldStarts = new WeakMap<any, boolean>();\n\nfunction isColdStart(doClass: any): boolean {\n if (!coldStarts.has(doClass)) {\n coldStarts.set(doClass, true);\n return true;\n }\n return false;\n}\n\n/**\n * Instrument a Durable Object fetch method\n */\nfunction instrumentDOFetch(\n fetchFn: DOFetchFn,\n id: DurableObjectId,\n doClass: any,\n): DOFetchFn {\n return async function instrumentedFetch(\n this: any,\n request: Request,\n ): Promise<Response> {\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n\n // Extract parent context from request headers\n const parentContext = propagation.extract(\n api_context.active(),\n request.headers,\n );\n\n const url = new URL(request.url);\n const spanName = `DO ${id.name || id.toString()}: ${request.method} ${url.pathname}`;\n\n return tracer.startActiveSpan(\n spanName,\n {\n kind: SpanKind.SERVER,\n attributes: {\n 'http.request.method': request.method,\n 'url.full': request.url,\n 'do.id': id.toString(),\n 'do.id.name': id.name || '',\n 'faas.trigger': 'http',\n 'faas.coldstart': isColdStart(doClass),\n },\n },\n parentContext,\n async (span) => {\n try {\n const response = await fetchFn.call(this, request);\n\n span.setAttributes({\n 'http.response.status_code': response.status,\n });\n\n if (response.ok) {\n span.setStatus({ code: SpanStatusCode.OK });\n } else {\n span.setStatus({ code: SpanStatusCode.ERROR });\n }\n\n return response;\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n };\n}\n\n/**\n * Instrument a Durable Object alarm method\n */\nfunction instrumentDOAlarm(\n alarmFn: DOAlarmFn,\n id: DurableObjectId,\n doClass: any,\n): DOAlarmFn {\n return async function instrumentedAlarm(this: any): Promise<void> {\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n\n const spanName = `DO ${id.name || id.toString()}: alarm`;\n\n return tracer.startActiveSpan(\n spanName,\n {\n kind: SpanKind.INTERNAL,\n attributes: {\n 'do.id': id.toString(),\n 'do.id.name': id.name || '',\n 'faas.trigger': 'timer',\n 'faas.coldstart': isColdStart(doClass),\n },\n },\n async (span) => {\n try {\n await alarmFn.call(this);\n span.setStatus({ code: SpanStatusCode.OK });\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n };\n}\n\n/**\n * Instrument a Durable Object instance\n */\nfunction instrumentDOInstance(\n doInstance: any,\n state: DurableObjectState,\n _env: any,\n doClass: any,\n): any {\n const instanceHandler: ProxyHandler<any> = {\n get(target, prop) {\n const value = Reflect.get(target, prop);\n\n if (prop === 'fetch' && typeof value === 'function') {\n return instrumentDOFetch(value.bind(target), state.id, doClass);\n }\n\n if (prop === 'alarm' && typeof value === 'function') {\n return instrumentDOAlarm(value.bind(target), state.id, doClass);\n }\n\n // Bind other methods to the target\n if (typeof value === 'function') {\n return value.bind(target);\n }\n\n return value;\n },\n };\n\n return wrap(doInstance, instanceHandler);\n}\n\n/**\n * Instrument a Durable Object class\n *\n * This wraps the DO class to automatically trace all fetch and alarm calls,\n * as well as initialize the telemetry configuration.\n *\n * **Usage:**\n * ```typescript\n * import { DurableObject } from 'cloudflare:workers'\n * import { instrumentDO } from 'autotel-edge'\n *\n * export class Counter extends DurableObject<Env> {\n * async fetch(request: Request) {\n * // Your DO logic here\n * return new Response('OK')\n * }\n * }\n *\n * // Wrap the class before exporting\n * export const CounterDO = instrumentDO(Counter, (env: Env) => ({\n * exporter: {\n * url: env.OTLP_ENDPOINT,\n * headers: { 'x-api-key': env.API_KEY }\n * },\n * service: {\n * name: 'my-durable-object',\n * version: '1.0.0'\n * }\n * }))\n * ```\n *\n * **What you get:**\n * - 🎯 Automatic spans for fetch() calls with HTTP attributes\n * - ⏰ Automatic spans for alarm() calls\n * - 🥶 Cold start tracking\n * - 🔗 Context propagation from incoming requests\n * - ⚡ Automatic span lifecycle management\n *\n * @param doClass - The Durable Object class to instrument\n * @param config - Configuration or configuration function\n * @returns Instrumented Durable Object class\n */\nexport function instrumentDO<C extends new (state: DurableObjectState, env: any) => any>(\n doClass: C,\n config: ConfigurationOption,\n): C {\n const initialiser = createInitialiser(config);\n\n const classHandler: ProxyHandler<C> = {\n construct(target, [state, env]: [DurableObjectState, any]) {\n // Initialize config for this DO instance\n const trigger = {\n id: state.id.toString(),\n name: state.id.name,\n };\n const doConfig = initialiser(env, trigger);\n const context = setConfig(doConfig);\n\n // Create the DO instance within the config context\n const doInstance = api_context.with(context, () => {\n return new target(state, env);\n });\n\n // Instrument the instance\n return instrumentDOInstance(doInstance, state, env, doClass);\n },\n };\n\n return wrap(doClass, classHandler);\n}\n","/**\n * Cloudflare Workflows instrumentation for autotel-edge\n *\n * Instruments WorkflowEntrypoint classes to automatically trace workflow execution,\n * step operations, retries, and sleeps.\n *\n * Based on Cloudflare Workflows API:\n * https://developers.cloudflare.com/workflows/\n */\n\nimport {\n trace,\n context as api_context,\n SpanStatusCode,\n SpanKind,\n} from '@opentelemetry/api';\nimport type { WorkflowEvent, WorkflowStep } from 'cloudflare:workers';\nimport type { ConfigurationOption, WorkflowTrigger } from 'autotel-edge';\nimport { createInitialiser, setConfig, WorkerTracer } from 'autotel-edge';\nimport { wrap } from '../bindings/common';\n\ntype WorkflowRunFn = (\n event: Readonly<WorkflowEvent<unknown>>,\n step: WorkflowStep,\n) => Promise<unknown> | void;\n\n/**\n * Track cold starts per Workflow class\n */\nconst coldStarts = new WeakMap<object, boolean>();\n\nfunction isColdStart(workflowClass: object): boolean {\n if (!coldStarts.has(workflowClass)) {\n coldStarts.set(workflowClass, true);\n return true;\n }\n return false;\n}\n\n/**\n * Proxy the step object to instrument step.do(), step.sleep(), and step.sleepUntil() calls\n */\nfunction instrumentWorkflowStep(\n step: WorkflowStep,\n workflowName: string,\n): WorkflowStep {\n const stepHandler: ProxyHandler<WorkflowStep> = {\n get(target, prop) {\n const value = Reflect.get(target, prop);\n\n // Instrument step.do() to create spans for each workflow step\n if (prop === 'do' && typeof value === 'function') {\n return new Proxy(value, {\n apply: (fnTarget, thisArg, args) => {\n const [stepName] = args as [string, ...unknown[]];\n\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n\n return tracer.startActiveSpan(\n `Workflow ${workflowName}: ${stepName}`,\n {\n kind: SpanKind.INTERNAL,\n attributes: {\n 'workflow.step.name': stepName,\n 'workflow.name': workflowName,\n },\n },\n async (span) => {\n try {\n const result = await Reflect.apply(fnTarget, thisArg, args);\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message:\n error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n },\n });\n }\n\n // Instrument step.sleep() to track workflow delays\n if (prop === 'sleep' && typeof value === 'function') {\n return new Proxy(value, {\n apply: (fnTarget, thisArg, args) => {\n const [sleepName, duration] = args as [string, string | number];\n\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n\n return tracer.startActiveSpan(\n `Workflow ${workflowName}: sleep ${sleepName}`,\n {\n kind: SpanKind.INTERNAL,\n attributes: {\n 'workflow.sleep.name': sleepName,\n 'workflow.sleep.duration': String(duration),\n 'workflow.name': workflowName,\n },\n },\n async (span) => {\n try {\n const result = await Reflect.apply(fnTarget, thisArg, args);\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message:\n error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n },\n });\n }\n\n if (prop === 'sleepUntil' && typeof value === 'function') {\n return new Proxy(value, {\n apply: (fnTarget, thisArg, args) => {\n const [sleepName, timestamp] = args as [string, Date | number];\n\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n const wakeAt =\n timestamp instanceof Date\n ? timestamp.toISOString()\n : new Date(timestamp).toISOString();\n\n return tracer.startActiveSpan(\n `Workflow ${workflowName}: sleepUntil ${sleepName}`,\n {\n kind: SpanKind.INTERNAL,\n attributes: {\n 'workflow.sleep.name': sleepName,\n 'workflow.sleep.until': wakeAt,\n 'workflow.name': workflowName,\n },\n },\n async (span) => {\n try {\n const result = await Reflect.apply(fnTarget, thisArg, args);\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message:\n error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n },\n });\n }\n\n // Pass through other step methods\n if (typeof value === 'function') {\n return value.bind(target);\n }\n\n return value;\n },\n };\n\n return wrap(step, stepHandler);\n}\n\n/**\n * Instrument a Workflow run method\n */\nfunction instrumentWorkflowRun(\n runFn: WorkflowRunFn,\n workflowName: string,\n workflowClass: object,\n): WorkflowRunFn {\n return async function instrumentedRun(\n this: unknown,\n event: Readonly<WorkflowEvent<unknown>>,\n step: WorkflowStep,\n ): Promise<unknown> {\n const tracer = trace.getTracer('autotel-edge') as WorkerTracer;\n\n // Instrument the step object to track individual operations\n const instrumentedStep = instrumentWorkflowStep(step, workflowName);\n\n const spanName = `Workflow ${workflowName}: run`;\n\n return tracer.startActiveSpan(\n spanName,\n {\n kind: SpanKind.INTERNAL,\n attributes: {\n 'workflow.name': workflowName,\n 'workflow.instance_id': event.instanceId,\n 'faas.trigger': 'workflow',\n 'faas.coldstart': isColdStart(workflowClass),\n },\n },\n async (span) => {\n try {\n const result = await runFn.call(this, event, instrumentedStep);\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: error instanceof Error ? error.message : String(error),\n });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n };\n}\n\n/**\n * Instrument a Workflow instance\n */\nfunction instrumentWorkflowInstance(\n workflowInstance: Record<string, unknown>,\n workflowName: string,\n workflowClass: object,\n): Record<string, unknown> {\n const instanceHandler: ProxyHandler<Record<string, unknown>> = {\n get(target, prop) {\n const value = Reflect.get(target, prop);\n\n if (prop === 'run' && typeof value === 'function') {\n return instrumentWorkflowRun(\n value.bind(target) as WorkflowRunFn,\n workflowName,\n workflowClass,\n );\n }\n\n // Bind other methods to the target\n if (typeof value === 'function') {\n return value.bind(target);\n }\n\n return value;\n },\n };\n\n return wrap(workflowInstance, instanceHandler);\n}\n\n/**\n * Instrument a Cloudflare Workflow class\n *\n * This wraps the WorkflowEntrypoint class to automatically trace workflow execution,\n * step operations, retries, and sleeps.\n *\n * **Usage:**\n * ```typescript\n * import { WorkflowEntrypoint } from 'cloudflare:workers'\n * import { instrumentWorkflow } from 'autotel-cloudflare/handlers'\n *\n * class MyWorkflow extends WorkflowEntrypoint {\n * async run(event, step) {\n * await step.do('submit payment', async () => {\n * return await submitToPaymentProcessor(event.payload.payment)\n * })\n *\n * await step.sleep('wait for feedback', '2 days')\n *\n * await step.do('send feedback email', sendFeedbackEmail)\n * }\n * }\n *\n * export const CheckoutWorkflow = instrumentWorkflow(\n * MyWorkflow,\n * 'checkout-workflow',\n * (env: Env) => ({\n * exporter: {\n * url: env.OTLP_ENDPOINT,\n * headers: { 'x-api-key': env.API_KEY }\n * },\n * service: {\n * name: 'checkout-workflow',\n * version: '1.0.0'\n * }\n * })\n * )\n * ```\n *\n * @param workflowClass - The WorkflowEntrypoint class to instrument\n * @param workflowName - The name of the workflow (used in span names)\n * @param config - Configuration or configuration function\n * @returns Instrumented Workflow class\n */\nexport function instrumentWorkflow<\n C extends new (...args: any[]) => any,\n>(\n workflowClass: C,\n workflowName: string,\n config: ConfigurationOption,\n): C {\n const initialiser = createInitialiser(config);\n\n const classHandler: ProxyHandler<C> = {\n construct(target, args: any[]) {\n // Extract env from constructor args (typically last arg)\n const env = args[args.length - 1] || {};\n\n const trigger: WorkflowTrigger = { type: 'workflow', name: workflowName };\n const workflowConfig = initialiser(env, trigger);\n const context = setConfig(workflowConfig);\n\n // Create the workflow instance within the config context\n const workflowInstance = api_context.with(context, () => {\n return new target(...args);\n });\n\n // Instrument the instance\n return instrumentWorkflowInstance(\n workflowInstance,\n workflowName,\n workflowClass,\n );\n },\n };\n\n return wrap(workflowClass, classHandler);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,MAAMA,+BAAa,IAAI,QAAsB;AAE7C,SAASC,cAAY,SAAuB;CAC1C,IAAI,CAACD,aAAW,IAAI,OAAO,GAAG;EAC5B,aAAW,IAAI,SAAS,IAAI;EAC5B,OAAO;CACT;CACA,OAAO;AACT;;;;AAKA,SAAS,kBACP,SACA,IACA,SACW;CACX,OAAO,eAAe,kBAEpB,SACmB;EACnB,MAAM,SAAS,MAAM,UAAU,cAAc;EAG7C,MAAM,gBAAgB,YAAY,QAChCE,QAAY,OAAO,GACnB,QAAQ,OACV;EAEA,MAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;EAC/B,MAAM,WAAW,MAAM,GAAG,QAAQ,GAAG,SAAS,EAAE,IAAI,QAAQ,OAAO,GAAG,IAAI;EAE1E,OAAO,OAAO,gBACZ,UACA;GACE,MAAM,SAAS;GACf,YAAY;IACV,uBAAuB,QAAQ;IAC/B,YAAY,QAAQ;IACpB,SAAS,GAAG,SAAS;IACrB,cAAc,GAAG,QAAQ;IACzB,gBAAgB;IAChB,kBAAkBD,cAAY,OAAO;GACvC;EACF,GACA,eACA,OAAO,SAAS;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,OAAO,KAAK;IAChE,CAAC;IACD,MAAM;GACR,UAAU;IACR,KAAK,IAAI;GACX;EACF,CACF;CACF;AACF;;;;AAKA,SAAS,2BACP,kBACA,cACA,eACyB;CAsBzB,OAAO,KAAK,kBAAkB,EApB5B,IAAI,QAAQ,MAAM;EAChB,MAAM,QAAQ,QAAQ,IAAI,QAAQ,IAAI;EAEtC,IAAI,SAAS,SAAS,OAAO,UAAU,YACrC,OAAO,sBACL,MAAM,KAAK,MAAM,GACjB,cACA,aACF;EAIF,IAAI,OAAO,UAAU,YACnB,OAAO,MAAM,KAAK,MAAM;EAG1B,OAAO;CACT,EAG0C,CAAC;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgB,mBAGd,eACA,cACA,QACG;CACH,MAAM,cAAc,kBAAkB,MAAM;CAyB5C,OAAO,KAAK,eAAe,EAtBzB,UAAU,QAAQ,MAAa;EAM7B,MAAMC,YAAU,UADO,YAHX,KAAK,KAAK,SAAS,MAAM,CAAC,GAGE;GADL,MAAM;GAAY,MAAM;EACb,CACP,CAAC;EAQxC,OAAO,2BALkBC,QAAY,KAAKD,iBAAe;GACvD,OAAO,IAAI,OAAO,GAAG,IAAI;EAC3B,CAIiB,GACf,cACA,aACF;CACF,EAGoC,CAAC;AACzC"}
@@ -0,0 +1,96 @@
1
+ import { ConfigurationOption } from "autotel-edge";
2
+
3
+ //#region src/handlers/durable-objects.d.ts
4
+ /**
5
+ * Instrument a Durable Object class
6
+ *
7
+ * This wraps the DO class to automatically trace all fetch and alarm calls,
8
+ * as well as initialize the telemetry configuration.
9
+ *
10
+ * **Usage:**
11
+ * ```typescript
12
+ * import { DurableObject } from 'cloudflare:workers'
13
+ * import { instrumentDO } from 'autotel-edge'
14
+ *
15
+ * export class Counter extends DurableObject<Env> {
16
+ * async fetch(request: Request) {
17
+ * // Your DO logic here
18
+ * return new Response('OK')
19
+ * }
20
+ * }
21
+ *
22
+ * // Wrap the class before exporting
23
+ * export const CounterDO = instrumentDO(Counter, (env: Env) => ({
24
+ * exporter: {
25
+ * url: env.OTLP_ENDPOINT,
26
+ * headers: { 'x-api-key': env.API_KEY }
27
+ * },
28
+ * service: {
29
+ * name: 'my-durable-object',
30
+ * version: '1.0.0'
31
+ * }
32
+ * }))
33
+ * ```
34
+ *
35
+ * **What you get:**
36
+ * - 🎯 Automatic spans for fetch() calls with HTTP attributes
37
+ * - ⏰ Automatic spans for alarm() calls
38
+ * - 🥶 Cold start tracking
39
+ * - 🔗 Context propagation from incoming requests
40
+ * - ⚡ Automatic span lifecycle management
41
+ *
42
+ * @param doClass - The Durable Object class to instrument
43
+ * @param config - Configuration or configuration function
44
+ * @returns Instrumented Durable Object class
45
+ */
46
+ declare function instrumentDO<C extends new (state: DurableObjectState, env: any) => any>(doClass: C, config: ConfigurationOption): C;
47
+ //#endregion
48
+ //#region src/handlers/workflows.d.ts
49
+ /**
50
+ * Instrument a Cloudflare Workflow class
51
+ *
52
+ * This wraps the WorkflowEntrypoint class to automatically trace workflow execution,
53
+ * step operations, retries, and sleeps.
54
+ *
55
+ * **Usage:**
56
+ * ```typescript
57
+ * import { WorkflowEntrypoint } from 'cloudflare:workers'
58
+ * import { instrumentWorkflow } from 'autotel-cloudflare/handlers'
59
+ *
60
+ * class MyWorkflow extends WorkflowEntrypoint {
61
+ * async run(event, step) {
62
+ * await step.do('submit payment', async () => {
63
+ * return await submitToPaymentProcessor(event.payload.payment)
64
+ * })
65
+ *
66
+ * await step.sleep('wait for feedback', '2 days')
67
+ *
68
+ * await step.do('send feedback email', sendFeedbackEmail)
69
+ * }
70
+ * }
71
+ *
72
+ * export const CheckoutWorkflow = instrumentWorkflow(
73
+ * MyWorkflow,
74
+ * 'checkout-workflow',
75
+ * (env: Env) => ({
76
+ * exporter: {
77
+ * url: env.OTLP_ENDPOINT,
78
+ * headers: { 'x-api-key': env.API_KEY }
79
+ * },
80
+ * service: {
81
+ * name: 'checkout-workflow',
82
+ * version: '1.0.0'
83
+ * }
84
+ * })
85
+ * )
86
+ * ```
87
+ *
88
+ * @param workflowClass - The WorkflowEntrypoint class to instrument
89
+ * @param workflowName - The name of the workflow (used in span names)
90
+ * @param config - Configuration or configuration function
91
+ * @returns Instrumented Workflow class
92
+ */
93
+ declare function instrumentWorkflow<C extends new (...args: any[]) => any>(workflowClass: C, workflowName: string, config: ConfigurationOption): C;
94
+ //#endregion
95
+ export { instrumentDO as n, instrumentWorkflow as t };
96
+ //# sourceMappingURL=handlers-C_VojUeA.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers-C_VojUeA.d.ts","names":[],"sources":["../src/handlers/durable-objects.ts","../src/handlers/workflows.ts"],"mappings":";;;;;;;;;;;;;;;;AAiOI;;;;ACsFJ;;;;;;;;;;;;;;;;;AAMI;;;;;;;;iBD/FY,YAAA,gBAA4B,KAAA,EAAO,kBAAA,EAAoB,GAAA,eACrE,OAAA,EAAS,CAAA,EACT,MAAA,EAAQ,mBAAA,GACP,CAAA;;;;;;;;;;;;;;;AAAC;;;;ACsFJ;;;;;;;;;;;;;;;;;AAMI;;;;;;;;;;;iBANY,kBAAA,mBACI,IAAA,iBAElB,aAAA,EAAe,CAAA,EACf,YAAA,UACA,MAAA,EAAQ,mBAAA,GACP,CAAA"}
@@ -1,112 +1,2 @@
1
- import { ConfigurationOption } from 'autotel-edge';
2
-
3
- /**
4
- * Durable Objects instrumentation for Cloudflare Workers
5
- *
6
- * Note: This file uses Cloudflare Workers types (DurableObjectId, DurableObjectState, etc.)
7
- * which are globally available via @cloudflare/workers-types when listed in tsconfig.json.
8
- * These types are devDependencies only - they're not runtime dependencies.
9
- * At runtime, Cloudflare Workers runtime provides the actual implementations.
10
- */
11
-
12
- /**
13
- * Instrument a Durable Object class
14
- *
15
- * This wraps the DO class to automatically trace all fetch and alarm calls,
16
- * as well as initialize the telemetry configuration.
17
- *
18
- * **Usage:**
19
- * ```typescript
20
- * import { DurableObject } from 'cloudflare:workers'
21
- * import { instrumentDO } from 'autotel-edge'
22
- *
23
- * export class Counter extends DurableObject<Env> {
24
- * async fetch(request: Request) {
25
- * // Your DO logic here
26
- * return new Response('OK')
27
- * }
28
- * }
29
- *
30
- * // Wrap the class before exporting
31
- * export const CounterDO = instrumentDO(Counter, (env: Env) => ({
32
- * exporter: {
33
- * url: env.OTLP_ENDPOINT,
34
- * headers: { 'x-api-key': env.API_KEY }
35
- * },
36
- * service: {
37
- * name: 'my-durable-object',
38
- * version: '1.0.0'
39
- * }
40
- * }))
41
- * ```
42
- *
43
- * **What you get:**
44
- * - 🎯 Automatic spans for fetch() calls with HTTP attributes
45
- * - ⏰ Automatic spans for alarm() calls
46
- * - 🥶 Cold start tracking
47
- * - 🔗 Context propagation from incoming requests
48
- * - ⚡ Automatic span lifecycle management
49
- *
50
- * @param doClass - The Durable Object class to instrument
51
- * @param config - Configuration or configuration function
52
- * @returns Instrumented Durable Object class
53
- */
54
- declare function instrumentDO<C extends new (state: DurableObjectState, env: any) => any>(doClass: C, config: ConfigurationOption): C;
55
-
56
- /**
57
- * Cloudflare Workflows instrumentation for autotel-edge
58
- *
59
- * Instruments WorkflowEntrypoint classes to automatically trace workflow execution,
60
- * step operations, retries, and sleeps.
61
- *
62
- * Based on Cloudflare Workflows API:
63
- * https://developers.cloudflare.com/workflows/
64
- */
65
-
66
- /**
67
- * Instrument a Cloudflare Workflow class
68
- *
69
- * This wraps the WorkflowEntrypoint class to automatically trace workflow execution,
70
- * step operations, retries, and sleeps.
71
- *
72
- * **Usage:**
73
- * ```typescript
74
- * import { WorkflowEntrypoint } from 'cloudflare:workers'
75
- * import { instrumentWorkflow } from 'autotel-cloudflare/handlers'
76
- *
77
- * class MyWorkflow extends WorkflowEntrypoint {
78
- * async run(event, step) {
79
- * await step.do('submit payment', async () => {
80
- * return await submitToPaymentProcessor(event.payload.payment)
81
- * })
82
- *
83
- * await step.sleep('wait for feedback', '2 days')
84
- *
85
- * await step.do('send feedback email', sendFeedbackEmail)
86
- * }
87
- * }
88
- *
89
- * export const CheckoutWorkflow = instrumentWorkflow(
90
- * MyWorkflow,
91
- * 'checkout-workflow',
92
- * (env: Env) => ({
93
- * exporter: {
94
- * url: env.OTLP_ENDPOINT,
95
- * headers: { 'x-api-key': env.API_KEY }
96
- * },
97
- * service: {
98
- * name: 'checkout-workflow',
99
- * version: '1.0.0'
100
- * }
101
- * })
102
- * )
103
- * ```
104
- *
105
- * @param workflowClass - The WorkflowEntrypoint class to instrument
106
- * @param workflowName - The name of the workflow (used in span names)
107
- * @param config - Configuration or configuration function
108
- * @returns Instrumented Workflow class
109
- */
110
- declare function instrumentWorkflow<C extends new (...args: any[]) => any>(workflowClass: C, workflowName: string, config: ConfigurationOption): C;
111
-
112
- export { instrumentDO, instrumentWorkflow };
1
+ import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-C_VojUeA.js";
2
+ export { instrumentDO, instrumentWorkflow };