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/dist/agents.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { c as asString, g as readProperty, h as readPath, o as asScalar, p as nonEmptyString, r as asFunction, s as asScalarArray } from "./values-BC6rdpGG.js";
|
|
2
|
+
import { t as workerTracer } from "./tracer-z8zwRBVS.js";
|
|
1
3
|
import { WorkerTracer, WorkerTracerProvider, createInitialiser } from "autotel-edge";
|
|
2
4
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
3
5
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
@@ -23,7 +25,7 @@ function initProvider(config) {
|
|
|
23
25
|
"agent.framework": "cloudflare-agents"
|
|
24
26
|
});
|
|
25
27
|
new WorkerTracerProvider(config.spanProcessors, resource).register();
|
|
26
|
-
|
|
28
|
+
workerTracer("autotel-cloudflare/agents").setHeadSampler(config.sampling.headSampler);
|
|
27
29
|
providerInitialized = true;
|
|
28
30
|
}
|
|
29
31
|
function classifyEvent(type) {
|
|
@@ -83,15 +85,15 @@ function formatTypeSegment(value) {
|
|
|
83
85
|
}
|
|
84
86
|
function getPayloadName(payload, ...keys) {
|
|
85
87
|
for (const key of keys) {
|
|
86
|
-
const value = payload[key];
|
|
87
|
-
if (
|
|
88
|
+
const value = nonEmptyString(payload[key]);
|
|
89
|
+
if (value !== void 0) return value;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
function getDefaultSpanName(event) {
|
|
91
93
|
const payload = event.payload;
|
|
92
94
|
switch (event.type) {
|
|
93
95
|
case "rpc":
|
|
94
|
-
case "rpc:error": return `agent.rpc ${payload
|
|
96
|
+
case "rpc:error": return `agent.rpc ${asString(readProperty(payload, "method"))}`;
|
|
95
97
|
case "schedule:create":
|
|
96
98
|
case "schedule:execute":
|
|
97
99
|
case "schedule:cancel":
|
|
@@ -126,14 +128,9 @@ function getDefaultSpanName(event) {
|
|
|
126
128
|
default: return `agent.${formatTypeSegment(event.type)}`;
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
|
-
function isPrimitiveAttributeValue(value) {
|
|
130
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return true;
|
|
131
|
-
if (!Array.isArray(value)) return false;
|
|
132
|
-
return value.every((entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean");
|
|
133
|
-
}
|
|
134
131
|
function setIfPresent(attrs, key, value) {
|
|
135
|
-
|
|
136
|
-
if (
|
|
132
|
+
const attribute = asScalar(value) ?? asScalarArray(value);
|
|
133
|
+
if (attribute !== void 0) attrs[key] = attribute;
|
|
137
134
|
}
|
|
138
135
|
function getDefaultAttributes(event) {
|
|
139
136
|
const attrs = { "agent.event.type": event.type };
|
|
@@ -203,21 +200,15 @@ function getSpanKind(event) {
|
|
|
203
200
|
}
|
|
204
201
|
}
|
|
205
202
|
function inferErrorMessage(event) {
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
if (event.type === "workflow:rejected") {
|
|
210
|
-
const reason = payload.reason;
|
|
211
|
-
if (typeof reason === "string" && reason.length > 0) return reason;
|
|
212
|
-
return "workflow rejected";
|
|
213
|
-
}
|
|
203
|
+
const direct = nonEmptyString(readProperty(event.payload, "error"));
|
|
204
|
+
if (direct !== void 0) return direct;
|
|
205
|
+
if (event.type === "workflow:rejected") return nonEmptyString(readProperty(event.payload, "reason")) ?? "workflow rejected";
|
|
214
206
|
if (event.type.endsWith(":failed") || event.type.endsWith(":error")) return event.type;
|
|
215
207
|
}
|
|
216
208
|
function isErrorEvent(event) {
|
|
217
209
|
if (event.type === "workflow:rejected") return true;
|
|
218
210
|
if (event.type.endsWith(":error") || event.type.endsWith(":failed")) return true;
|
|
219
|
-
|
|
220
|
-
return false;
|
|
211
|
+
return asString(readProperty(event.payload, "error")) !== void 0;
|
|
221
212
|
}
|
|
222
213
|
function applyEventStatus(span, event) {
|
|
223
214
|
if (!isErrorEvent(event)) {
|
|
@@ -235,8 +226,8 @@ function applyEventStatus(span, event) {
|
|
|
235
226
|
async function exportSpans(traceId, ctx) {
|
|
236
227
|
const tracer = trace.getTracer("autotel-cloudflare/agents");
|
|
237
228
|
if (tracer instanceof WorkerTracer) try {
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
229
|
+
const wait = asFunction(readPath(ctx, "scheduler", "wait"));
|
|
230
|
+
if (wait) await wait(1);
|
|
240
231
|
await tracer.forceFlush(traceId);
|
|
241
232
|
} catch (error) {
|
|
242
233
|
console.error("[autotel-cloudflare/agents] Failed to export spans:", error);
|
|
@@ -286,8 +277,9 @@ var OtelObservability = class {
|
|
|
286
277
|
applyEventStatus(span, event);
|
|
287
278
|
span.end(event.timestamp + 1);
|
|
288
279
|
const traceId = span.spanContext().traceId;
|
|
289
|
-
|
|
290
|
-
|
|
280
|
+
const waitUntil = asFunction(readProperty(ctx, "waitUntil"));
|
|
281
|
+
if (waitUntil) {
|
|
282
|
+
waitUntil(exportSpans(traceId, ctx));
|
|
291
283
|
return;
|
|
292
284
|
}
|
|
293
285
|
exportSpans(traceId, ctx);
|
|
@@ -297,10 +289,10 @@ function createOtelObservability(config) {
|
|
|
297
289
|
return new OtelObservability(config);
|
|
298
290
|
}
|
|
299
291
|
function createOtelObservabilityFromEnv(env, options) {
|
|
300
|
-
const endpoint = env.OTEL_EXPORTER_OTLP_ENDPOINT
|
|
301
|
-
const serviceName = env.OTEL_SERVICE_NAME
|
|
292
|
+
const endpoint = nonEmptyString(env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
293
|
+
const serviceName = nonEmptyString(env.OTEL_SERVICE_NAME) ?? "cloudflare-agent";
|
|
302
294
|
let headers;
|
|
303
|
-
const headersStr = env.OTEL_EXPORTER_OTLP_HEADERS;
|
|
295
|
+
const headersStr = nonEmptyString(env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
304
296
|
if (headersStr) {
|
|
305
297
|
headers = {};
|
|
306
298
|
for (const pair of headersStr.split(",")) {
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
+
import { t as UnknownRecord } from "./values-CRvW9g6_.js";
|
|
1
2
|
//#region src/bindings/bindings.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Auto-instrumentation for Cloudflare Workers bindings
|
|
4
|
-
*
|
|
5
|
-
* Note: This file uses Cloudflare Workers types (KVNamespace, R2Bucket, D1Database, Fetcher, etc.)
|
|
6
|
-
* which are globally available via @cloudflare/workers-types when listed in tsconfig.json.
|
|
7
|
-
* These types are devDependencies only - they're not runtime dependencies.
|
|
8
|
-
* At runtime, Cloudflare Workers runtime provides the actual implementations.
|
|
9
|
-
*
|
|
10
|
-
* This module provides automatic tracing for Cloudflare bindings:
|
|
11
|
-
* - KV (key-value operations)
|
|
12
|
-
* - R2 (object storage operations)
|
|
13
|
-
* - D1 (database operations)
|
|
14
|
-
* - Service Bindings
|
|
15
|
-
* - Events Engine
|
|
16
|
-
* - Workers AI
|
|
17
|
-
* - Vectorize
|
|
18
|
-
* - Hyperdrive
|
|
19
|
-
*/
|
|
20
3
|
/**
|
|
21
4
|
* Instrument KV namespace
|
|
22
5
|
*/
|
|
@@ -35,11 +18,13 @@ declare function instrumentD1<D extends D1Database>(d1: D, databaseName?: string
|
|
|
35
18
|
* Unlike other bindings, Fetcher objects are native Cloudflare C++ bindings
|
|
36
19
|
* whose methods throw "Illegal invocation" when called through a Proxy with
|
|
37
20
|
* a different `this` reference. We work around this by calling `target.fetch()`
|
|
38
|
-
* directly on the original binding instead of using `
|
|
21
|
+
* directly on the original binding instead of using `fn.apply` on a
|
|
39
22
|
* detached function reference.
|
|
40
23
|
*/
|
|
41
24
|
declare function instrumentServiceBinding<F extends Fetcher>(fetcher: F, serviceName?: string): F;
|
|
42
|
-
|
|
25
|
+
/** A Worker's environment: bindings by the names wrangler.toml gave them. */
|
|
26
|
+
type WorkerEnv = UnknownRecord;
|
|
27
|
+
declare function instrumentBindings(env: WorkerEnv): WorkerEnv;
|
|
43
28
|
//#endregion
|
|
44
29
|
//#region src/bindings/ai.d.ts
|
|
45
30
|
/**
|