autotel-cloudflare 6.0.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/actors.d.ts +15 -2
- package/dist/actors.js +95 -93
- package/dist/agents.d.ts +2 -1
- package/dist/agents.js +20 -28
- package/dist/{bindings-xEZcXo5r.d.ts → bindings-BcSPZDWF.d.ts} +5 -20
- package/dist/{bindings-DznsCwCn.js → bindings-s6W9szMm.js} +199 -154
- package/dist/bindings.d.ts +1 -1
- package/dist/bindings.js +1 -1
- package/dist/{common-DiWH6nmG.js → exception-D3xOCdBW.js} +11 -2
- package/dist/{execution-logger-BxmgP8jF.js → execution-logger-6IZS5fEz.js} +2 -1
- package/dist/{handlers-BePc7OJU.js → handlers-avm65CVU.js} +37 -34
- package/dist/handlers.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +60 -62
- package/dist/logger.js +1 -1
- package/dist/tracer-z8zwRBVS.js +10 -0
- package/dist/values-BC6rdpGG.js +108 -0
- package/dist/values-CRvW9g6_.d.ts +19 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
The package direction is to make Cloudflare observability feel the same across Workers, Queues, Durable Objects, alarms, and Workflows:
|
|
24
24
|
|
|
25
25
|
- use Cloudflare-native wrappers to create the root span
|
|
26
|
-
- use
|
|
26
|
+
- use `trace(fn)` for inferred-name wrappers and `trace(name, ctx => result)` for immediate named work; use `withTracing({ name })((ctx) => fn)` for reusable named business logic (`instrument(handler, config)` is the Worker handler adapter)
|
|
27
27
|
- prefer span attributes and one execution snapshot over scattered info logs
|
|
28
28
|
|
|
29
29
|
See [docs/CLOUDFLARE-DX.md](../../docs/CLOUDFLARE-DX.md) for the design target and review rules.
|
package/dist/actors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CRvW9g6_.js";
|
|
1
2
|
import { ConfigurationOption } from "autotel-edge";
|
|
2
3
|
//#region src/actors/types.d.ts
|
|
3
4
|
/**
|
|
@@ -59,9 +60,21 @@ interface ActorLike {
|
|
|
59
60
|
/**
|
|
60
61
|
* Constructor type for Actor classes
|
|
61
62
|
*/
|
|
62
|
-
type ActorConstructor<T extends ActorLike = ActorLike> = new (state: DurableObjectState, env: unknown) => T
|
|
63
|
+
type ActorConstructor<T extends ActorLike = ActorLike> = (new (state: DurableObjectState, env: Record<string, unknown>) => T) & {
|
|
64
|
+
/** A class's own name, which the instrumentation puts on the span. */
|
|
65
|
+
readonly name?: string;
|
|
66
|
+
};
|
|
63
67
|
//#endregion
|
|
64
68
|
//#region src/actors/instrument-actor.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* The Actor class being instrumented. Its own type belongs to the application,
|
|
71
|
+
* so this names only what the wrappers read off it: the class name that goes on
|
|
72
|
+
* the span, and the marker used to detect a cold start.
|
|
73
|
+
*/
|
|
74
|
+
/** What an Actor persists, and what a WebSocket carries: the app's own values. */
|
|
75
|
+
type ActorPayload = string | number | boolean | null | undefined | UnknownRecord | unknown[] | ArrayBuffer;
|
|
76
|
+
/** The env a Durable Object is constructed with: whatever wrangler bound. */
|
|
77
|
+
type ActorEnv = UnknownRecord;
|
|
65
78
|
/**
|
|
66
79
|
* Instrument an Actor class for comprehensive OpenTelemetry tracing
|
|
67
80
|
*
|
|
@@ -107,7 +120,7 @@ type ActorConstructor<T extends ActorLike = ActorLike> = new (state: DurableObje
|
|
|
107
120
|
* @param config - Configuration (static object or function)
|
|
108
121
|
* @returns Instrumented Actor class
|
|
109
122
|
*/
|
|
110
|
-
declare function instrumentActor<C extends ActorConstructor>(actorClass: C, config: ActorConfig | ((env:
|
|
123
|
+
declare function instrumentActor<C extends ActorConstructor>(actorClass: C, config: ActorConfig | ((env: ActorEnv, trigger?: ActorPayload) => ActorConfig)): C;
|
|
111
124
|
//#endregion
|
|
112
125
|
//#region src/actors/traced-handler.d.ts
|
|
113
126
|
/**
|
package/dist/actors.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as asRecord, c as asString, f as member, g as readProperty, l as describeValue, n as asBoolean, r as asFunction } from "./values-BC6rdpGG.js";
|
|
2
|
+
import { o as wrap, t as toException } from "./exception-D3xOCdBW.js";
|
|
3
|
+
import { t as workerTracer } from "./tracer-z8zwRBVS.js";
|
|
2
4
|
import { createInitialiser, setConfig } from "autotel-edge";
|
|
3
|
-
import { SpanKind, SpanStatusCode, context, propagation
|
|
5
|
+
import { SpanKind, SpanStatusCode, context, propagation } from "@opentelemetry/api";
|
|
4
6
|
|
|
5
7
|
//#region src/actors/storage.ts
|
|
6
8
|
/**
|
|
@@ -12,7 +14,7 @@ import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentele
|
|
|
12
14
|
* Get the tracer instance
|
|
13
15
|
*/
|
|
14
16
|
function getTracer$4() {
|
|
15
|
-
return
|
|
17
|
+
return workerTracer("autotel-cloudflare-actors");
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Instrument Actor storage for tracing
|
|
@@ -22,12 +24,14 @@ function getTracer$4() {
|
|
|
22
24
|
* - Key-value operations (if available)
|
|
23
25
|
*/
|
|
24
26
|
function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const storageRecord = asRecord(storage);
|
|
28
|
+
if (!storageRecord) return storage;
|
|
29
|
+
const actorClassName = asString(member(actorClass, "name")) || "Actor";
|
|
27
30
|
const actorName = actorInstance.name || actorClassName;
|
|
28
|
-
return wrap(
|
|
29
|
-
const value =
|
|
30
|
-
|
|
31
|
+
return wrap(storageRecord, { get(target, prop) {
|
|
32
|
+
const value = member(target, prop);
|
|
33
|
+
const method = asFunction(value);
|
|
34
|
+
if (prop === "exec" && method) return function instrumentedExec(query, ...params) {
|
|
31
35
|
const tracer = getTracer$4();
|
|
32
36
|
const spanName = `Actor ${actorName}: storage.exec`;
|
|
33
37
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -42,11 +46,11 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
42
46
|
}
|
|
43
47
|
}, (span) => {
|
|
44
48
|
try {
|
|
45
|
-
const result =
|
|
49
|
+
const result = method.call(target, query, ...params);
|
|
46
50
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
47
51
|
return result;
|
|
48
52
|
} catch (error) {
|
|
49
|
-
span.recordException(error);
|
|
53
|
+
span.recordException(toException(error));
|
|
50
54
|
span.setStatus({
|
|
51
55
|
code: SpanStatusCode.ERROR,
|
|
52
56
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -57,7 +61,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
57
61
|
}
|
|
58
62
|
});
|
|
59
63
|
};
|
|
60
|
-
if (prop === "query" &&
|
|
64
|
+
if (prop === "query" && method) return function instrumentedQuery(query, ...params) {
|
|
61
65
|
const tracer = getTracer$4();
|
|
62
66
|
const spanName = `Actor ${actorName}: storage.query`;
|
|
63
67
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -72,11 +76,11 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
72
76
|
}
|
|
73
77
|
}, (span) => {
|
|
74
78
|
try {
|
|
75
|
-
const result =
|
|
79
|
+
const result = method.call(target, query, ...params);
|
|
76
80
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
77
81
|
return result;
|
|
78
82
|
} catch (error) {
|
|
79
|
-
span.recordException(error);
|
|
83
|
+
span.recordException(toException(error));
|
|
80
84
|
span.setStatus({
|
|
81
85
|
code: SpanStatusCode.ERROR,
|
|
82
86
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -87,7 +91,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
87
91
|
}
|
|
88
92
|
});
|
|
89
93
|
};
|
|
90
|
-
if (prop === "get" &&
|
|
94
|
+
if (prop === "get" && method) return async function instrumentedGet(key) {
|
|
91
95
|
const tracer = getTracer$4();
|
|
92
96
|
const spanName = `Actor ${actorName}: storage.get`;
|
|
93
97
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -101,12 +105,12 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
101
105
|
}
|
|
102
106
|
}, async (span) => {
|
|
103
107
|
try {
|
|
104
|
-
const result = await
|
|
108
|
+
const result = await method.call(target, key);
|
|
105
109
|
span.setAttributes({ "db.result.found": result !== null && result !== void 0 });
|
|
106
110
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
107
111
|
return result;
|
|
108
112
|
} catch (error) {
|
|
109
|
-
span.recordException(error);
|
|
113
|
+
span.recordException(toException(error));
|
|
110
114
|
span.setStatus({
|
|
111
115
|
code: SpanStatusCode.ERROR,
|
|
112
116
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -117,7 +121,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
117
121
|
}
|
|
118
122
|
});
|
|
119
123
|
};
|
|
120
|
-
if (prop === "put" &&
|
|
124
|
+
if (prop === "put" && method) return async function instrumentedPut(key, val) {
|
|
121
125
|
const tracer = getTracer$4();
|
|
122
126
|
const spanName = `Actor ${actorName}: storage.put`;
|
|
123
127
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -132,10 +136,10 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
132
136
|
}
|
|
133
137
|
}, async (span) => {
|
|
134
138
|
try {
|
|
135
|
-
await
|
|
139
|
+
await method.call(target, key, val);
|
|
136
140
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
137
141
|
} catch (error) {
|
|
138
|
-
span.recordException(error);
|
|
142
|
+
span.recordException(toException(error));
|
|
139
143
|
span.setStatus({
|
|
140
144
|
code: SpanStatusCode.ERROR,
|
|
141
145
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -146,7 +150,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
146
150
|
}
|
|
147
151
|
});
|
|
148
152
|
};
|
|
149
|
-
if (prop === "delete" &&
|
|
153
|
+
if (prop === "delete" && method) return async function instrumentedDelete(key) {
|
|
150
154
|
const tracer = getTracer$4();
|
|
151
155
|
const spanName = `Actor ${actorName}: storage.delete`;
|
|
152
156
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -160,12 +164,13 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
160
164
|
}
|
|
161
165
|
}, async (span) => {
|
|
162
166
|
try {
|
|
163
|
-
const result = await
|
|
164
|
-
|
|
167
|
+
const result = await method.call(target, key);
|
|
168
|
+
const deleted = asBoolean(result);
|
|
169
|
+
if (deleted !== void 0) span.setAttributes({ "db.result.deleted": deleted });
|
|
165
170
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
166
171
|
return result;
|
|
167
172
|
} catch (error) {
|
|
168
|
-
span.recordException(error);
|
|
173
|
+
span.recordException(toException(error));
|
|
169
174
|
span.setStatus({
|
|
170
175
|
code: SpanStatusCode.ERROR,
|
|
171
176
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -176,8 +181,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
176
181
|
}
|
|
177
182
|
});
|
|
178
183
|
};
|
|
179
|
-
|
|
180
|
-
return value;
|
|
184
|
+
return method ? method.bind(target) : value;
|
|
181
185
|
} });
|
|
182
186
|
}
|
|
183
187
|
|
|
@@ -192,7 +196,7 @@ function instrumentActorStorage(storage, actorInstance, actorClass) {
|
|
|
192
196
|
* Get the tracer instance
|
|
193
197
|
*/
|
|
194
198
|
function getTracer$3() {
|
|
195
|
-
return
|
|
199
|
+
return workerTracer("autotel-cloudflare-actors");
|
|
196
200
|
}
|
|
197
201
|
/**
|
|
198
202
|
* Instrument Actor alarms for tracing
|
|
@@ -204,12 +208,14 @@ function getTracer$3() {
|
|
|
204
208
|
* - cancelAll: Cancel all alarms
|
|
205
209
|
*/
|
|
206
210
|
function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
const alarmsRecord = asRecord(alarms);
|
|
212
|
+
if (!alarmsRecord) return alarms;
|
|
213
|
+
const actorClassName = asString(member(actorClass, "name")) || "Actor";
|
|
209
214
|
const actorName = actorInstance.name || actorClassName;
|
|
210
|
-
return wrap(
|
|
211
|
-
const value =
|
|
212
|
-
|
|
215
|
+
return wrap(alarmsRecord, { get(target, prop) {
|
|
216
|
+
const value = member(target, prop);
|
|
217
|
+
const method = asFunction(value);
|
|
218
|
+
if (prop === "set" && method) return async function instrumentedSet(...args) {
|
|
213
219
|
const tracer = getTracer$3();
|
|
214
220
|
const spanName = `Actor ${actorName}: alarms.set`;
|
|
215
221
|
const alarmAttributes = {
|
|
@@ -228,11 +234,11 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
228
234
|
attributes: alarmAttributes
|
|
229
235
|
}, async (span) => {
|
|
230
236
|
try {
|
|
231
|
-
const result = await
|
|
237
|
+
const result = await method.apply(target, args);
|
|
232
238
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
233
239
|
return result;
|
|
234
240
|
} catch (error) {
|
|
235
|
-
span.recordException(error);
|
|
241
|
+
span.recordException(toException(error));
|
|
236
242
|
span.setStatus({
|
|
237
243
|
code: SpanStatusCode.ERROR,
|
|
238
244
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -243,7 +249,7 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
243
249
|
}
|
|
244
250
|
});
|
|
245
251
|
};
|
|
246
|
-
if (prop === "setMultiple" &&
|
|
252
|
+
if (prop === "setMultiple" && method) return async function instrumentedSetMultiple(alarmDefs) {
|
|
247
253
|
const tracer = getTracer$3();
|
|
248
254
|
const spanName = `Actor ${actorName}: alarms.setMultiple`;
|
|
249
255
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -256,11 +262,11 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
256
262
|
}
|
|
257
263
|
}, async (span) => {
|
|
258
264
|
try {
|
|
259
|
-
const result = await
|
|
265
|
+
const result = await method.call(target, alarmDefs);
|
|
260
266
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
261
267
|
return result;
|
|
262
268
|
} catch (error) {
|
|
263
|
-
span.recordException(error);
|
|
269
|
+
span.recordException(toException(error));
|
|
264
270
|
span.setStatus({
|
|
265
271
|
code: SpanStatusCode.ERROR,
|
|
266
272
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -271,7 +277,7 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
271
277
|
}
|
|
272
278
|
});
|
|
273
279
|
};
|
|
274
|
-
if (prop === "cancel" &&
|
|
280
|
+
if (prop === "cancel" && method) return async function instrumentedCancel(alarmId) {
|
|
275
281
|
const tracer = getTracer$3();
|
|
276
282
|
const spanName = `Actor ${actorName}: alarms.cancel`;
|
|
277
283
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -284,11 +290,11 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
284
290
|
}
|
|
285
291
|
}, async (span) => {
|
|
286
292
|
try {
|
|
287
|
-
const result = await
|
|
293
|
+
const result = await method.call(target, alarmId);
|
|
288
294
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
289
295
|
return result;
|
|
290
296
|
} catch (error) {
|
|
291
|
-
span.recordException(error);
|
|
297
|
+
span.recordException(toException(error));
|
|
292
298
|
span.setStatus({
|
|
293
299
|
code: SpanStatusCode.ERROR,
|
|
294
300
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -299,7 +305,7 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
299
305
|
}
|
|
300
306
|
});
|
|
301
307
|
};
|
|
302
|
-
if (prop === "cancelAll" &&
|
|
308
|
+
if (prop === "cancelAll" && method) return async function instrumentedCancelAll() {
|
|
303
309
|
const tracer = getTracer$3();
|
|
304
310
|
const spanName = `Actor ${actorName}: alarms.cancelAll`;
|
|
305
311
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -311,11 +317,11 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
311
317
|
}
|
|
312
318
|
}, async (span) => {
|
|
313
319
|
try {
|
|
314
|
-
const result = await
|
|
320
|
+
const result = await method.call(target);
|
|
315
321
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
316
322
|
return result;
|
|
317
323
|
} catch (error) {
|
|
318
|
-
span.recordException(error);
|
|
324
|
+
span.recordException(toException(error));
|
|
319
325
|
span.setStatus({
|
|
320
326
|
code: SpanStatusCode.ERROR,
|
|
321
327
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -326,8 +332,7 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
326
332
|
}
|
|
327
333
|
});
|
|
328
334
|
};
|
|
329
|
-
|
|
330
|
-
return value;
|
|
335
|
+
return method ? method.bind(target) : value;
|
|
331
336
|
} });
|
|
332
337
|
}
|
|
333
338
|
|
|
@@ -342,7 +347,7 @@ function instrumentActorAlarms(alarms, actorInstance, actorClass) {
|
|
|
342
347
|
* Get the tracer instance
|
|
343
348
|
*/
|
|
344
349
|
function getTracer$2() {
|
|
345
|
-
return
|
|
350
|
+
return workerTracer("autotel-cloudflare-actors");
|
|
346
351
|
}
|
|
347
352
|
/**
|
|
348
353
|
* Instrument Actor sockets for tracing
|
|
@@ -353,12 +358,14 @@ function getTracer$2() {
|
|
|
353
358
|
* - send: Send message to a specific socket
|
|
354
359
|
*/
|
|
355
360
|
function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
356
|
-
|
|
357
|
-
|
|
361
|
+
const socketsRecord = asRecord(sockets);
|
|
362
|
+
if (!socketsRecord) return sockets;
|
|
363
|
+
const actorClassName = asString(member(actorClass, "name")) || "Actor";
|
|
358
364
|
const actorName = actorInstance.name || actorClassName;
|
|
359
|
-
return wrap(
|
|
360
|
-
const value =
|
|
361
|
-
|
|
365
|
+
return wrap(socketsRecord, { get(target, prop) {
|
|
366
|
+
const value = member(target, prop);
|
|
367
|
+
const method = asFunction(value);
|
|
368
|
+
if (prop === "acceptWebSocket" && method) return function instrumentedAcceptWebSocket(request) {
|
|
362
369
|
const tracer = getTracer$2();
|
|
363
370
|
const spanName = `Actor ${actorName}: sockets.acceptWebSocket`;
|
|
364
371
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -371,11 +378,11 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
371
378
|
}
|
|
372
379
|
}, (span) => {
|
|
373
380
|
try {
|
|
374
|
-
const result =
|
|
381
|
+
const result = method.call(target, request);
|
|
375
382
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
376
383
|
return result;
|
|
377
384
|
} catch (error) {
|
|
378
|
-
span.recordException(error);
|
|
385
|
+
span.recordException(toException(error));
|
|
379
386
|
span.setStatus({
|
|
380
387
|
code: SpanStatusCode.ERROR,
|
|
381
388
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -386,7 +393,7 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
386
393
|
}
|
|
387
394
|
});
|
|
388
395
|
};
|
|
389
|
-
if (prop === "broadcast" &&
|
|
396
|
+
if (prop === "broadcast" && method) return function instrumentedBroadcast(message) {
|
|
390
397
|
const tracer = getTracer$2();
|
|
391
398
|
const spanName = `Actor ${actorName}: sockets.broadcast`;
|
|
392
399
|
tracer.startActiveSpan(spanName, {
|
|
@@ -400,10 +407,10 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
400
407
|
}
|
|
401
408
|
}, (span) => {
|
|
402
409
|
try {
|
|
403
|
-
|
|
410
|
+
method.call(target, message);
|
|
404
411
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
405
412
|
} catch (error) {
|
|
406
|
-
span.recordException(error);
|
|
413
|
+
span.recordException(toException(error));
|
|
407
414
|
span.setStatus({
|
|
408
415
|
code: SpanStatusCode.ERROR,
|
|
409
416
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -414,7 +421,7 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
414
421
|
}
|
|
415
422
|
});
|
|
416
423
|
};
|
|
417
|
-
if (prop === "send" &&
|
|
424
|
+
if (prop === "send" && method) return function instrumentedSend(ws, message) {
|
|
418
425
|
const tracer = getTracer$2();
|
|
419
426
|
const spanName = `Actor ${actorName}: sockets.send`;
|
|
420
427
|
tracer.startActiveSpan(spanName, {
|
|
@@ -428,10 +435,10 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
428
435
|
}
|
|
429
436
|
}, (span) => {
|
|
430
437
|
try {
|
|
431
|
-
|
|
438
|
+
method.call(target, ws, message);
|
|
432
439
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
433
440
|
} catch (error) {
|
|
434
|
-
span.recordException(error);
|
|
441
|
+
span.recordException(toException(error));
|
|
435
442
|
span.setStatus({
|
|
436
443
|
code: SpanStatusCode.ERROR,
|
|
437
444
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -442,7 +449,7 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
442
449
|
}
|
|
443
450
|
});
|
|
444
451
|
};
|
|
445
|
-
if (prop === "getConnections" &&
|
|
452
|
+
if (prop === "getConnections" && method) return function instrumentedGetConnections() {
|
|
446
453
|
const tracer = getTracer$2();
|
|
447
454
|
const spanName = `Actor ${actorName}: sockets.getConnections`;
|
|
448
455
|
return tracer.startActiveSpan(spanName, {
|
|
@@ -454,12 +461,12 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
454
461
|
}
|
|
455
462
|
}, (span) => {
|
|
456
463
|
try {
|
|
457
|
-
const result =
|
|
464
|
+
const result = method.call(target);
|
|
458
465
|
if (Array.isArray(result)) span.setAttribute("websocket.connections.count", result.length);
|
|
459
466
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
460
467
|
return result;
|
|
461
468
|
} catch (error) {
|
|
462
|
-
span.recordException(error);
|
|
469
|
+
span.recordException(toException(error));
|
|
463
470
|
span.setStatus({
|
|
464
471
|
code: SpanStatusCode.ERROR,
|
|
465
472
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -470,8 +477,7 @@ function instrumentActorSockets(sockets, actorInstance, actorClass) {
|
|
|
470
477
|
}
|
|
471
478
|
});
|
|
472
479
|
};
|
|
473
|
-
|
|
474
|
-
return value;
|
|
480
|
+
return method ? method.bind(target) : value;
|
|
475
481
|
} });
|
|
476
482
|
}
|
|
477
483
|
|
|
@@ -502,7 +508,7 @@ function isColdStart(actorClass) {
|
|
|
502
508
|
* Get the tracer instance
|
|
503
509
|
*/
|
|
504
510
|
function getTracer$1() {
|
|
505
|
-
return
|
|
511
|
+
return workerTracer("autotel-cloudflare-actors");
|
|
506
512
|
}
|
|
507
513
|
/**
|
|
508
514
|
* Default span name formatter
|
|
@@ -510,9 +516,6 @@ function getTracer$1() {
|
|
|
510
516
|
function defaultSpanNameFormatter(actorName, actorClass, lifecycle) {
|
|
511
517
|
return `Actor ${actorName || actorClass}: ${lifecycle}`;
|
|
512
518
|
}
|
|
513
|
-
/**
|
|
514
|
-
* Create base Actor span attributes
|
|
515
|
-
*/
|
|
516
519
|
function createActorAttributes(actorInstance, actorClass, lifecycle) {
|
|
517
520
|
return {
|
|
518
521
|
"actor.name": actorInstance.name || "unknown",
|
|
@@ -538,7 +541,7 @@ function instrumentOnInit(originalMethod, actorInstance, actorClass, options) {
|
|
|
538
541
|
await originalMethod.call(actorInstance);
|
|
539
542
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
540
543
|
} catch (error) {
|
|
541
|
-
span.recordException(error);
|
|
544
|
+
span.recordException(toException(error));
|
|
542
545
|
span.setStatus({
|
|
543
546
|
code: SpanStatusCode.ERROR,
|
|
544
547
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -577,7 +580,7 @@ function instrumentOnRequest(originalMethod, actorInstance, actorClass, options)
|
|
|
577
580
|
else span.setStatus({ code: SpanStatusCode.ERROR });
|
|
578
581
|
return response;
|
|
579
582
|
} catch (error) {
|
|
580
|
-
span.recordException(error);
|
|
583
|
+
span.recordException(toException(error));
|
|
581
584
|
span.setStatus({
|
|
582
585
|
code: SpanStatusCode.ERROR,
|
|
583
586
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -608,7 +611,7 @@ function instrumentOnAlarm(originalMethod, actorInstance, actorClass, options) {
|
|
|
608
611
|
await originalMethod.call(actorInstance, alarmInfo);
|
|
609
612
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
610
613
|
} catch (error) {
|
|
611
|
-
span.recordException(error);
|
|
614
|
+
span.recordException(toException(error));
|
|
612
615
|
span.setStatus({
|
|
613
616
|
code: SpanStatusCode.ERROR,
|
|
614
617
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -634,14 +637,14 @@ function instrumentOnPersist(originalMethod, actorInstance, actorClass, options)
|
|
|
634
637
|
attributes: {
|
|
635
638
|
...createActorAttributes(actorInstance, actorClass, "persist"),
|
|
636
639
|
"actor.persist.key": key,
|
|
637
|
-
"actor.persist.value_type":
|
|
640
|
+
"actor.persist.value_type": describeValue(value)
|
|
638
641
|
}
|
|
639
642
|
}, (span) => {
|
|
640
643
|
try {
|
|
641
644
|
originalMethod.call(actorInstance, key, value);
|
|
642
645
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
643
646
|
} catch (error) {
|
|
644
|
-
span.recordException(error);
|
|
647
|
+
span.recordException(toException(error));
|
|
645
648
|
span.setStatus({
|
|
646
649
|
code: SpanStatusCode.ERROR,
|
|
647
650
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -672,7 +675,7 @@ function instrumentWebSocketConnect(originalMethod, actorInstance, actorClass, o
|
|
|
672
675
|
originalMethod.call(actorInstance, ws, request);
|
|
673
676
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
674
677
|
} catch (error) {
|
|
675
|
-
span.recordException(error);
|
|
678
|
+
span.recordException(toException(error));
|
|
676
679
|
span.setStatus({
|
|
677
680
|
code: SpanStatusCode.ERROR,
|
|
678
681
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -693,15 +696,15 @@ function instrumentWebSocketMessage(originalMethod, actorInstance, actorClass, o
|
|
|
693
696
|
kind: SpanKind.SERVER,
|
|
694
697
|
attributes: {
|
|
695
698
|
...createActorAttributes(actorInstance, actorClass, "websocket.message"),
|
|
696
|
-
"websocket.message.type":
|
|
697
|
-
"websocket.message.size":
|
|
699
|
+
"websocket.message.type": describeValue(message),
|
|
700
|
+
"websocket.message.size": asString(message)?.length ?? (message instanceof ArrayBuffer ? message.byteLength : 0)
|
|
698
701
|
}
|
|
699
702
|
}, (span) => {
|
|
700
703
|
try {
|
|
701
704
|
originalMethod.call(actorInstance, ws, message);
|
|
702
705
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
703
706
|
} catch (error) {
|
|
704
|
-
span.recordException(error);
|
|
707
|
+
span.recordException(toException(error));
|
|
705
708
|
span.setStatus({
|
|
706
709
|
code: SpanStatusCode.ERROR,
|
|
707
710
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -726,7 +729,7 @@ function instrumentWebSocketDisconnect(originalMethod, actorInstance, actorClass
|
|
|
726
729
|
originalMethod.call(actorInstance, ws);
|
|
727
730
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
728
731
|
} catch (error) {
|
|
729
|
-
span.recordException(error);
|
|
732
|
+
span.recordException(toException(error));
|
|
730
733
|
span.setStatus({
|
|
731
734
|
code: SpanStatusCode.ERROR,
|
|
732
735
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -743,19 +746,19 @@ function instrumentWebSocketDisconnect(originalMethod, actorInstance, actorClass
|
|
|
743
746
|
*/
|
|
744
747
|
function instrumentActorInstance(actorInstance, _state, _env, actorClass, options) {
|
|
745
748
|
return wrap(actorInstance, { get(target, prop) {
|
|
746
|
-
const value =
|
|
747
|
-
|
|
748
|
-
if (prop === "
|
|
749
|
-
if (prop === "
|
|
750
|
-
if (prop === "
|
|
751
|
-
if (prop === "
|
|
752
|
-
if (prop === "
|
|
753
|
-
if (prop === "
|
|
749
|
+
const value = member(target, prop);
|
|
750
|
+
const method = asFunction(value);
|
|
751
|
+
if (prop === "onInit" && method) return instrumentOnInit(method.bind(target), target, actorClass, options);
|
|
752
|
+
if (prop === "onRequest" && method) return instrumentOnRequest(method.bind(target), target, actorClass, options);
|
|
753
|
+
if (prop === "onAlarm" && method) return instrumentOnAlarm(method.bind(target), target, actorClass, options);
|
|
754
|
+
if (prop === "onPersist" && method) return instrumentOnPersist(method.bind(target), target, actorClass, options);
|
|
755
|
+
if (prop === "onWebSocketConnect" && method) return instrumentWebSocketConnect(method.bind(target), target, actorClass, options);
|
|
756
|
+
if (prop === "onWebSocketMessage" && method) return instrumentWebSocketMessage(method.bind(target), target, actorClass, options);
|
|
757
|
+
if (prop === "onWebSocketDisconnect" && method) return instrumentWebSocketDisconnect(method.bind(target), target, actorClass, options);
|
|
754
758
|
if (prop === "storage" && value && options.instrumentStorage !== false) return instrumentActorStorage(value, target, actorClass);
|
|
755
759
|
if (prop === "alarms" && value && options.instrumentAlarms !== false) return instrumentActorAlarms(value, target, actorClass);
|
|
756
760
|
if (prop === "sockets" && value && options.instrumentSockets !== false) return instrumentActorSockets(value, target, actorClass);
|
|
757
|
-
|
|
758
|
-
return value;
|
|
761
|
+
return method ? method.bind(target) : value;
|
|
759
762
|
} });
|
|
760
763
|
}
|
|
761
764
|
/**
|
|
@@ -812,11 +815,10 @@ function instrumentActor(actorClass, config) {
|
|
|
812
815
|
capturePersistEvents: true
|
|
813
816
|
};
|
|
814
817
|
return wrap(actorClass, { construct(target, [state, env]) {
|
|
815
|
-
const
|
|
818
|
+
const actorOptions = readProperty(typeof config === "function" ? config(env, {
|
|
816
819
|
id: state.id.toString(),
|
|
817
820
|
name: state.id.name
|
|
818
|
-
}) : config;
|
|
819
|
-
const actorOptions = resolvedConfig && typeof resolvedConfig === "object" && "actors" in resolvedConfig ? resolvedConfig.actors : void 0;
|
|
821
|
+
}) : config, "actors");
|
|
820
822
|
const options = {
|
|
821
823
|
...defaultOptions,
|
|
822
824
|
...actorOptions
|
|
@@ -846,7 +848,7 @@ function instrumentActor(actorClass, config) {
|
|
|
846
848
|
* Get the tracer instance
|
|
847
849
|
*/
|
|
848
850
|
function getTracer() {
|
|
849
|
-
return
|
|
851
|
+
return workerTracer("autotel-cloudflare-actors");
|
|
850
852
|
}
|
|
851
853
|
/**
|
|
852
854
|
* Create a traced handler that combines Actor instrumentation with request tracing
|
|
@@ -949,7 +951,7 @@ function tracedHandler(actorClass, config) {
|
|
|
949
951
|
else span.setStatus({ code: SpanStatusCode.ERROR });
|
|
950
952
|
return response;
|
|
951
953
|
} catch (error) {
|
|
952
|
-
span.recordException(error);
|
|
954
|
+
span.recordException(toException(error));
|
|
953
955
|
span.setStatus({
|
|
954
956
|
code: SpanStatusCode.ERROR,
|
|
955
957
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -1017,7 +1019,7 @@ function wrapHandler(originalHandler, config) {
|
|
|
1017
1019
|
else span.setStatus({ code: SpanStatusCode.ERROR });
|
|
1018
1020
|
return response;
|
|
1019
1021
|
} catch (error) {
|
|
1020
|
-
span.recordException(error);
|
|
1022
|
+
span.recordException(toException(error));
|
|
1021
1023
|
span.setStatus({
|
|
1022
1024
|
code: SpanStatusCode.ERROR,
|
|
1023
1025
|
message: error instanceof Error ? error.message : String(error)
|
package/dist/agents.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CRvW9g6_.js";
|
|
1
2
|
import { ConfigurationOption } from "autotel-edge";
|
|
2
3
|
import { Attributes } from "@opentelemetry/api";
|
|
3
4
|
//#region src/agents/base.d.ts
|
|
@@ -689,6 +690,6 @@ declare class OtelObservability implements Observability {
|
|
|
689
690
|
emit(event: ObservabilityEvent, ctx?: ObservabilityExecutionContext): void;
|
|
690
691
|
}
|
|
691
692
|
declare function createOtelObservability(config: OtelObservabilityConfig): OtelObservability;
|
|
692
|
-
declare function createOtelObservabilityFromEnv(env:
|
|
693
|
+
declare function createOtelObservabilityFromEnv(env: UnknownRecord, options?: AgentInstrumentationOptions): OtelObservability;
|
|
693
694
|
//#endregion
|
|
694
695
|
export { type AgentInstrumentationOptions, type AgentObservabilityEvent, type AgentSpanAttributes, type BaseEvent, type ChannelEventMap, type MCPObservabilityEvent, type Observability, type ObservabilityEvent, OtelObservability, type OtelObservabilityConfig, channels, createOtelObservability, createOtelObservabilityFromEnv, genericObservability, subscribe };
|