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.
@@ -1,2 +1,2 @@
1
- import { a as instrumentQueueProducer, c as instrumentAI, d as instrumentKV, f as instrumentR2, i as instrumentAnalyticsEngine, l as instrumentBindings, n as instrumentRateLimiter, o as instrumentHyperdrive, p as instrumentServiceBinding, r as instrumentImages, s as instrumentVectorize, t as instrumentBrowserRendering, u as instrumentD1 } from "./bindings-xEZcXo5r.js";
1
+ import { a as instrumentQueueProducer, c as instrumentAI, d as instrumentKV, f as instrumentR2, i as instrumentAnalyticsEngine, l as instrumentBindings, n as instrumentRateLimiter, o as instrumentHyperdrive, p as instrumentServiceBinding, r as instrumentImages, s as instrumentVectorize, t as instrumentBrowserRendering, u as instrumentD1 } from "./bindings-BcSPZDWF.js";
2
2
  export { instrumentAI, instrumentAnalyticsEngine, instrumentBindings, instrumentBrowserRendering, instrumentD1, instrumentHyperdrive, instrumentImages, instrumentKV, instrumentQueueProducer, instrumentR2, instrumentRateLimiter, instrumentServiceBinding, instrumentVectorize };
package/dist/bindings.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as instrumentKV, c as instrumentImages, d as instrumentHyperdrive, f as instrumentVectorize, i as instrumentD1, l as instrumentAnalyticsEngine, n as instrumentRateLimiter, o as instrumentR2, p as instrumentAI, r as instrumentBindings, s as instrumentServiceBinding, t as instrumentBrowserRendering, u as instrumentQueueProducer } from "./bindings-DznsCwCn.js";
1
+ import { a as instrumentKV, c as instrumentImages, d as instrumentHyperdrive, f as instrumentVectorize, i as instrumentD1, l as instrumentAnalyticsEngine, n as instrumentRateLimiter, o as instrumentR2, p as instrumentAI, r as instrumentBindings, s as instrumentServiceBinding, t as instrumentBrowserRendering, u as instrumentQueueProducer } from "./bindings-s6W9szMm.js";
2
2
 
3
3
  export { instrumentAI, instrumentAnalyticsEngine, instrumentBindings, instrumentBrowserRendering, instrumentD1, instrumentHyperdrive, instrumentImages, instrumentKV, instrumentQueueProducer, instrumentR2, instrumentRateLimiter, instrumentServiceBinding, instrumentVectorize };
@@ -1,3 +1,5 @@
1
+ import { f as member } from "./values-BC6rdpGG.js";
2
+
1
3
  //#region src/bindings/common.ts
2
4
  /**
3
5
  * Common instrumentation utilities
@@ -25,7 +27,7 @@ function proxyExecutionContext(ctx) {
25
27
  tracker.track(promise);
26
28
  return target.waitUntil(promise);
27
29
  };
28
- return Reflect.get(target, prop);
30
+ return member(target, prop);
29
31
  } }),
30
32
  tracker
31
33
  };
@@ -59,4 +61,11 @@ function wrap(item, handler) {
59
61
  }
60
62
 
61
63
  //#endregion
62
- export { wrap as a, unwrap as i, proxyExecutionContext as n, setAttr as r, isWrapped as t };
64
+ //#region src/exception.ts
65
+ /** The caught value, in a form a span can record. */
66
+ function toException(cause) {
67
+ return cause instanceof Error ? cause : String(cause);
68
+ }
69
+
70
+ //#endregion
71
+ export { unwrap as a, setAttr as i, isWrapped as n, wrap as o, proxyExecutionContext as r, toException as t };
@@ -1,3 +1,4 @@
1
+ import { f as member } from "./values-BC6rdpGG.js";
1
2
  import { getExecutionLogger } from "autotel-edge/logger";
2
3
 
3
4
  //#region src/execution-logger.ts
@@ -14,7 +15,7 @@ function collectHeaders(headers, include) {
14
15
  return Object.keys(out).length > 0 ? out : void 0;
15
16
  }
16
17
  function pickCfContext(request) {
17
- const cf = Reflect.get(request, "cf");
18
+ const cf = member(request, "cf");
18
19
  if (!isRecord(cf)) return {};
19
20
  const out = {};
20
21
  if (typeof cf.colo === "string") out.colo = cf.colo;
@@ -1,6 +1,8 @@
1
- import { a as wrap } from "./common-DiWH6nmG.js";
1
+ import { _ as trapArgs, f as member, 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, trace } from "@opentelemetry/api";
5
+ import { SpanKind, SpanStatusCode, context, propagation } from "@opentelemetry/api";
4
6
 
5
7
  //#region src/handlers/durable-objects.ts
6
8
  /**
@@ -27,7 +29,7 @@ function isColdStart$1(doClass) {
27
29
  */
28
30
  function instrumentDOFetch(fetchFn, id, doClass) {
29
31
  return async function instrumentedFetch(request) {
30
- const tracer = trace.getTracer("autotel-edge");
32
+ const tracer = workerTracer("autotel-edge");
31
33
  const parentContext = propagation.extract(context.active(), request.headers);
32
34
  const url = new URL(request.url);
33
35
  const spanName = `DO ${id.name || id.toString()}: ${request.method} ${url.pathname}`;
@@ -49,7 +51,7 @@ function instrumentDOFetch(fetchFn, id, doClass) {
49
51
  else span.setStatus({ code: SpanStatusCode.ERROR });
50
52
  return response;
51
53
  } catch (error) {
52
- span.recordException(error);
54
+ span.recordException(toException(error));
53
55
  span.setStatus({
54
56
  code: SpanStatusCode.ERROR,
55
57
  message: error instanceof Error ? error.message : String(error)
@@ -66,7 +68,7 @@ function instrumentDOFetch(fetchFn, id, doClass) {
66
68
  */
67
69
  function instrumentDOAlarm(alarmFn, id, doClass) {
68
70
  return async function instrumentedAlarm() {
69
- const tracer = trace.getTracer("autotel-edge");
71
+ const tracer = workerTracer("autotel-edge");
70
72
  const spanName = `DO ${id.name || id.toString()}: alarm`;
71
73
  return tracer.startActiveSpan(spanName, {
72
74
  kind: SpanKind.INTERNAL,
@@ -81,7 +83,7 @@ function instrumentDOAlarm(alarmFn, id, doClass) {
81
83
  await alarmFn.call(this);
82
84
  span.setStatus({ code: SpanStatusCode.OK });
83
85
  } catch (error) {
84
- span.recordException(error);
86
+ span.recordException(toException(error));
85
87
  span.setStatus({
86
88
  code: SpanStatusCode.ERROR,
87
89
  message: error instanceof Error ? error.message : String(error)
@@ -98,11 +100,11 @@ function instrumentDOAlarm(alarmFn, id, doClass) {
98
100
  */
99
101
  function instrumentDOInstance(doInstance, state, _env, doClass) {
100
102
  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;
103
+ const value = member(target, prop);
104
+ const method = asFunction(value);
105
+ if (prop === "fetch" && method) return instrumentDOFetch(method.bind(target), state.id, doClass);
106
+ if (prop === "alarm" && method) return instrumentDOAlarm(method.bind(target), state.id, doClass);
107
+ return method ? method.bind(target) : value;
106
108
  } });
107
109
  }
108
110
  /**
@@ -188,10 +190,11 @@ function isColdStart(workflowClass) {
188
190
  */
189
191
  function instrumentWorkflowStep(step, workflowName) {
190
192
  return wrap(step, { get(target, prop) {
191
- const value = Reflect.get(target, prop);
192
- if (prop === "do" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
193
- const [stepName] = args;
194
- return trace.getTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: ${stepName}`, {
193
+ const value = member(target, prop);
194
+ const method = asFunction(value);
195
+ if (prop === "do" && method) return new Proxy(method, { apply: (fnTarget, thisArg, args) => {
196
+ const [stepName] = trapArgs(args);
197
+ return workerTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: ${stepName}`, {
195
198
  kind: SpanKind.INTERNAL,
196
199
  attributes: {
197
200
  "workflow.step.name": stepName,
@@ -199,11 +202,11 @@ function instrumentWorkflowStep(step, workflowName) {
199
202
  }
200
203
  }, async (span) => {
201
204
  try {
202
- const result = await Reflect.apply(fnTarget, thisArg, args);
205
+ const result = await fnTarget.apply(thisArg, args);
203
206
  span.setStatus({ code: SpanStatusCode.OK });
204
207
  return result;
205
208
  } catch (error) {
206
- span.recordException(error);
209
+ span.recordException(toException(error));
207
210
  span.setStatus({
208
211
  code: SpanStatusCode.ERROR,
209
212
  message: error instanceof Error ? error.message : String(error)
@@ -214,9 +217,9 @@ function instrumentWorkflowStep(step, workflowName) {
214
217
  }
215
218
  });
216
219
  } });
217
- if (prop === "sleep" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
218
- const [sleepName, duration] = args;
219
- return trace.getTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: sleep ${sleepName}`, {
220
+ if (prop === "sleep" && method) return new Proxy(method, { apply: (fnTarget, thisArg, args) => {
221
+ const [sleepName, duration] = trapArgs(args);
222
+ return workerTracer("autotel-edge").startActiveSpan(`Workflow ${workflowName}: sleep ${sleepName}`, {
220
223
  kind: SpanKind.INTERNAL,
221
224
  attributes: {
222
225
  "workflow.sleep.name": sleepName,
@@ -225,11 +228,11 @@ function instrumentWorkflowStep(step, workflowName) {
225
228
  }
226
229
  }, async (span) => {
227
230
  try {
228
- const result = await Reflect.apply(fnTarget, thisArg, args);
231
+ const result = await fnTarget.apply(thisArg, args);
229
232
  span.setStatus({ code: SpanStatusCode.OK });
230
233
  return result;
231
234
  } catch (error) {
232
- span.recordException(error);
235
+ span.recordException(toException(error));
233
236
  span.setStatus({
234
237
  code: SpanStatusCode.ERROR,
235
238
  message: error instanceof Error ? error.message : String(error)
@@ -240,9 +243,9 @@ function instrumentWorkflowStep(step, workflowName) {
240
243
  }
241
244
  });
242
245
  } });
243
- if (prop === "sleepUntil" && typeof value === "function") return new Proxy(value, { apply: (fnTarget, thisArg, args) => {
244
- const [sleepName, timestamp] = args;
245
- const tracer = trace.getTracer("autotel-edge");
246
+ if (prop === "sleepUntil" && method) return new Proxy(method, { apply: (fnTarget, thisArg, args) => {
247
+ const [sleepName, timestamp] = trapArgs(args);
248
+ const tracer = workerTracer("autotel-edge");
246
249
  const wakeAt = timestamp instanceof Date ? timestamp.toISOString() : new Date(timestamp).toISOString();
247
250
  return tracer.startActiveSpan(`Workflow ${workflowName}: sleepUntil ${sleepName}`, {
248
251
  kind: SpanKind.INTERNAL,
@@ -253,11 +256,11 @@ function instrumentWorkflowStep(step, workflowName) {
253
256
  }
254
257
  }, async (span) => {
255
258
  try {
256
- const result = await Reflect.apply(fnTarget, thisArg, args);
259
+ const result = await fnTarget.apply(thisArg, args);
257
260
  span.setStatus({ code: SpanStatusCode.OK });
258
261
  return result;
259
262
  } catch (error) {
260
- span.recordException(error);
263
+ span.recordException(toException(error));
261
264
  span.setStatus({
262
265
  code: SpanStatusCode.ERROR,
263
266
  message: error instanceof Error ? error.message : String(error)
@@ -268,7 +271,7 @@ function instrumentWorkflowStep(step, workflowName) {
268
271
  }
269
272
  });
270
273
  } });
271
- if (typeof value === "function") return value.bind(target);
274
+ if (method !== void 0) return method.bind(target);
272
275
  return value;
273
276
  } });
274
277
  }
@@ -277,7 +280,7 @@ function instrumentWorkflowStep(step, workflowName) {
277
280
  */
278
281
  function instrumentWorkflowRun(runFn, workflowName, workflowClass) {
279
282
  return async function instrumentedRun(event, step) {
280
- const tracer = trace.getTracer("autotel-edge");
283
+ const tracer = workerTracer("autotel-edge");
281
284
  const instrumentedStep = instrumentWorkflowStep(step, workflowName);
282
285
  const spanName = `Workflow ${workflowName}: run`;
283
286
  return tracer.startActiveSpan(spanName, {
@@ -294,7 +297,7 @@ function instrumentWorkflowRun(runFn, workflowName, workflowClass) {
294
297
  span.setStatus({ code: SpanStatusCode.OK });
295
298
  return result;
296
299
  } catch (error) {
297
- span.recordException(error);
300
+ span.recordException(toException(error));
298
301
  span.setStatus({
299
302
  code: SpanStatusCode.ERROR,
300
303
  message: error instanceof Error ? error.message : String(error)
@@ -311,10 +314,10 @@ function instrumentWorkflowRun(runFn, workflowName, workflowClass) {
311
314
  */
312
315
  function instrumentWorkflowInstance(workflowInstance, workflowName, workflowClass) {
313
316
  return wrap(workflowInstance, { get(target, prop) {
314
- const value = Reflect.get(target, prop);
315
- if (prop === "run" && typeof value === "function") return instrumentWorkflowRun(value.bind(target), workflowName, workflowClass);
316
- if (typeof value === "function") return value.bind(target);
317
- return value;
317
+ const value = member(target, prop);
318
+ const method = asFunction(value);
319
+ if (prop === "run" && method) return instrumentWorkflowRun(method.bind(target), workflowName, workflowClass);
320
+ return method ? method.bind(target) : value;
318
321
  } });
319
322
  }
320
323
  /**
package/dist/handlers.js CHANGED
@@ -1,3 +1,3 @@
1
- import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-BePc7OJU.js";
1
+ import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-avm65CVU.js";
2
2
 
3
3
  export { instrumentDO, instrumentWorkflow };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as instrumentQueueProducer, c as instrumentAI, d as instrumentKV, f as instrumentR2, i as instrumentAnalyticsEngine, l as instrumentBindings, n as instrumentRateLimiter, o as instrumentHyperdrive, p as instrumentServiceBinding, r as instrumentImages, s as instrumentVectorize, t as instrumentBrowserRendering, u as instrumentD1 } from "./bindings-xEZcXo5r.js";
1
+ import { a as instrumentQueueProducer, c as instrumentAI, d as instrumentKV, f as instrumentR2, i as instrumentAnalyticsEngine, l as instrumentBindings, n as instrumentRateLimiter, o as instrumentHyperdrive, p as instrumentServiceBinding, r as instrumentImages, s as instrumentVectorize, t as instrumentBrowserRendering, u as instrumentD1 } from "./bindings-BcSPZDWF.js";
2
2
  import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-BRfAgfP7.js";
3
3
  import { a as createWorkersLogger, c as getRequestLogger, i as WorkersLoggerOptions, l as getWorkflowLogger, n as ExecutionLogger, o as getActorLogger, r as ExecutionLoggerOptions, s as getQueueLogger, t as ExecutionLogSnapshot } from "./execution-logger-CCn9HGYC.js";
4
4
  import { n as isNativeTracingAvailable, t as getNativeTracerFromCtx } from "./native-tracing-DFaGAoR7.js";
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- import { a as getWorkflowLogger, i as getRequestLogger, n as getActorLogger, r as getQueueLogger, t as createWorkersLogger } from "./execution-logger-BxmgP8jF.js";
1
+ import { _ as trapArgs, a as asRecord, c as asString, f as member, g as readProperty, i as asNumber, n as asBoolean, r as asFunction, t as applyTrap } from "./values-BC6rdpGG.js";
2
+ import { a as getWorkflowLogger, i as getRequestLogger, n as getActorLogger, r as getQueueLogger, t as createWorkersLogger } from "./execution-logger-6IZS5fEz.js";
2
3
  import { n as isNativeTracingAvailable, t as getNativeTracerFromCtx } from "./native-tracing-D0EyAtsF.js";
3
- import { a as wrap, i as unwrap, n as proxyExecutionContext } from "./common-DiWH6nmG.js";
4
- import { a as instrumentKV, c as instrumentImages, d as instrumentHyperdrive, f as instrumentVectorize, i as instrumentD1, l as instrumentAnalyticsEngine, n as instrumentRateLimiter, o as instrumentR2, p as instrumentAI, r as instrumentBindings, s as instrumentServiceBinding, t as instrumentBrowserRendering, u as instrumentQueueProducer } from "./bindings-DznsCwCn.js";
5
- import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-BePc7OJU.js";
4
+ import { a as unwrap, o as wrap, r as proxyExecutionContext, t as toException } from "./exception-D3xOCdBW.js";
5
+ import { t as workerTracer } from "./tracer-z8zwRBVS.js";
6
+ import { a as instrumentKV, c as instrumentImages, d as instrumentHyperdrive, f as instrumentVectorize, i as instrumentD1, l as instrumentAnalyticsEngine, n as instrumentRateLimiter, o as instrumentR2, p as instrumentAI, r as instrumentBindings, s as instrumentServiceBinding, t as instrumentBrowserRendering, u as instrumentQueueProducer } from "./bindings-s6W9szMm.js";
7
+ import { n as instrumentDO, t as instrumentWorkflow } from "./handlers-avm65CVU.js";
6
8
  import { WorkerTracer, WorkerTracerProvider, createInitialiser, ensureGlobalContextManager, getActiveConfig, getServiceForPath, setConfig, shouldInstrumentPath, withNativeTracer } from "autotel-edge";
7
9
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
8
10
  import { resourceFromAttributes } from "@opentelemetry/resources";
@@ -60,7 +62,7 @@ function instrumentGlobalFetch() {
60
62
  if (!request.url.startsWith("http")) return originalFetch(input, init);
61
63
  const config = getActiveConfig();
62
64
  if (!config) return originalFetch(input, init);
63
- const tracer = trace.getTracer("autotel-edge");
65
+ const tracer = workerTracer("autotel-edge");
64
66
  const url = new URL(request.url);
65
67
  const spanName = `${request.method} ${url.host}`;
66
68
  return tracer.startActiveSpan(spanName, {
@@ -77,7 +79,7 @@ function instrumentGlobalFetch() {
77
79
  else span.setStatus({ code: SpanStatusCode.ERROR });
78
80
  return response;
79
81
  } catch (error) {
80
- span.recordException(error);
82
+ span.recordException(toException(error));
81
83
  span.setStatus({
82
84
  code: SpanStatusCode.ERROR,
83
85
  message: error instanceof Error ? error.message : String(error)
@@ -112,7 +114,7 @@ function sanitizeURL(url) {
112
114
  */
113
115
  function instrumentCacheMethod(fn, cacheName, operation) {
114
116
  return wrap(fn, { async apply(target, thisArg, argArray) {
115
- const tracer = trace.getTracer("autotel-edge");
117
+ const tracer = workerTracer("autotel-edge");
116
118
  const firstArg = argArray[0];
117
119
  const url = firstArg instanceof Request ? firstArg.url : typeof firstArg === "string" ? firstArg : void 0;
118
120
  const spanName = `Cache ${cacheName}.${operation}`;
@@ -125,12 +127,12 @@ function instrumentCacheMethod(fn, cacheName, operation) {
125
127
  }
126
128
  }, async (span) => {
127
129
  try {
128
- const result = await Reflect.apply(target, thisArg, argArray);
130
+ const result = await target.apply(thisArg, argArray);
129
131
  if (operation === "match") span.setAttribute("cache.hit", !!result);
130
132
  span.setStatus({ code: SpanStatusCode.OK });
131
133
  return result;
132
134
  } catch (error) {
133
- span.recordException(error);
135
+ span.recordException(toException(error));
134
136
  span.setStatus({
135
137
  code: SpanStatusCode.ERROR,
136
138
  message: error instanceof Error ? error.message : String(error)
@@ -147,9 +149,10 @@ function instrumentCacheMethod(fn, cacheName, operation) {
147
149
  */
148
150
  function instrumentCache(cache, cacheName) {
149
151
  return wrap(cache, { get(target, prop) {
150
- const value = Reflect.get(target, prop);
151
- if ((prop === "match" || prop === "put" || prop === "delete") && typeof value === "function") return instrumentCacheMethod(value.bind(target), cacheName, prop);
152
- if (typeof value === "function") return value.bind(target);
152
+ const value = member(target, prop);
153
+ const method = asFunction(value);
154
+ if ((prop === "match" || prop === "put" || prop === "delete") && method !== void 0) return instrumentCacheMethod(method.bind(target), cacheName, prop);
155
+ if (method !== void 0) return method.bind(target);
153
156
  return value;
154
157
  } });
155
158
  }
@@ -159,7 +162,7 @@ function instrumentCache(cache, cacheName) {
159
162
  function instrumentCachesOpen(openFn) {
160
163
  return wrap(openFn, { async apply(target, thisArg, argArray) {
161
164
  const cacheName = argArray[0];
162
- return instrumentCache(await Reflect.apply(target, thisArg, argArray), cacheName);
165
+ return instrumentCache(await applyTrap(target, thisArg, argArray), cacheName);
163
166
  } });
164
167
  }
165
168
  /**
@@ -174,10 +177,10 @@ function instrumentGlobalCache() {
174
177
  globalThis.caches = wrap(caches, { get(target, prop) {
175
178
  if (prop === "default") return instrumentCache(target.default, "default");
176
179
  else if (prop === "open") {
177
- const openFn = Reflect.get(target, prop);
180
+ const openFn = member(target, prop);
178
181
  if (typeof openFn === "function") return instrumentCachesOpen(openFn.bind(target));
179
182
  }
180
- return Reflect.get(target, prop);
183
+ return member(target, prop);
181
184
  } });
182
185
  }
183
186
 
@@ -213,11 +216,12 @@ const headersGetter = {
213
216
  * Extract Cloudflare-specific attributes from a request
214
217
  */
215
218
  function extractCfAttributes(request) {
216
- const cf = request.cf;
219
+ const cf = asRecord(member(request, "cf"));
217
220
  if (!cf) return {};
218
221
  const attrs = {};
219
222
  const set = (key, value) => {
220
- if (value !== void 0 && value !== null) attrs[key] = value;
223
+ const scalar = asString(value) ?? asNumber(value) ?? asBoolean(value);
224
+ if (scalar !== void 0) attrs[key] = scalar;
221
225
  };
222
226
  set("cloudflare.colo", cf.colo);
223
227
  const ray = request.headers.get("cf-ray");
@@ -241,7 +245,7 @@ function createFetchInstrumentation(config) {
241
245
  getInitialSpanInfo: (request) => {
242
246
  const url = new URL(request.url);
243
247
  const routeService = getServiceForPath(url.pathname, config.handlers.fetch.routes);
244
- const cfAttrs = config.extractCfAttributes === false ? {} : extractCfAttributes(request);
248
+ const cfAttrs = readProperty(config, "extractCfAttributes") === false ? {} : extractCfAttributes(request);
245
249
  return {
246
250
  name: `${request.method} ${url.pathname}`,
247
251
  options: {
@@ -344,27 +348,24 @@ function addQueueEvent(name, msg, delaySeconds) {
344
348
  */
345
349
  function proxyQueueMessage(msg, count) {
346
350
  return wrap(msg, { get: (target, prop) => {
347
- if (prop === "ack") {
348
- const ackFn = Reflect.get(target, prop);
349
- return new Proxy(ackFn, { apply: (fnTarget) => {
350
- addQueueEvent("messageAck", msg);
351
- count.ack();
352
- Reflect.apply(fnTarget, msg, []);
353
- } });
354
- } else if (prop === "retry") {
355
- const retryFn = Reflect.get(target, prop);
356
- return new Proxy(retryFn, { apply: (fnTarget, _thisArg, args) => {
357
- const retryOptions = args[0];
358
- const delaySeconds = retryOptions?.delaySeconds;
359
- addQueueEvent("messageRetry", msg, delaySeconds);
360
- if (retryOptions?.contentType) {
361
- const span = trace.getActiveSpan();
362
- if (span) span.setAttribute("queue.message.content_type", retryOptions.contentType);
363
- }
364
- count.retry();
365
- return Reflect.apply(fnTarget, msg, args);
366
- } });
367
- } else return Reflect.get(target, prop, msg);
351
+ const messageFn = asFunction(member(target, prop));
352
+ if (prop === "ack" && messageFn) return new Proxy(messageFn, { apply: (fnTarget) => {
353
+ addQueueEvent("messageAck", msg);
354
+ count.ack();
355
+ fnTarget.apply(msg, []);
356
+ } });
357
+ else if (prop === "retry" && messageFn) return new Proxy(messageFn, { apply: (fnTarget, _thisArg, args) => {
358
+ const retryOptions = trapArgs(args)[0];
359
+ const delaySeconds = retryOptions?.delaySeconds;
360
+ addQueueEvent("messageRetry", msg, delaySeconds);
361
+ if (retryOptions?.contentType) {
362
+ const span = trace.getActiveSpan();
363
+ if (span) span.setAttribute("queue.message.content_type", retryOptions.contentType);
364
+ }
365
+ count.retry();
366
+ return applyTrap(fnTarget, msg, args);
367
+ } });
368
+ else return member(target, prop);
368
369
  } });
369
370
  }
370
371
  /**
@@ -372,27 +373,24 @@ function proxyQueueMessage(msg, count) {
372
373
  */
373
374
  function proxyMessageBatch(batch, count) {
374
375
  return wrap(batch, { get: (target, prop) => {
375
- if (prop === "messages") return wrap(Reflect.get(target, prop), { get: (target, prop) => {
376
- if (typeof prop === "string" && !isNaN(parseInt(prop))) return proxyQueueMessage(Reflect.get(target, prop), count);
377
- else return Reflect.get(target, prop);
376
+ if (prop === "messages") return wrap(target.messages, { get: (target, prop) => {
377
+ const index = asString(prop);
378
+ if (index !== void 0 && !Number.isNaN(Number.parseInt(index))) return proxyQueueMessage(member(target, prop), count);
379
+ return member(target, prop);
378
380
  } });
379
- else if (prop === "ackAll") {
380
- const ackFn = Reflect.get(target, prop);
381
- return new Proxy(ackFn, { apply: (fnTarget) => {
382
- addQueueEvent("ackAll");
383
- count.ackRemaining();
384
- Reflect.apply(fnTarget, batch, []);
385
- } });
386
- } else if (prop === "retryAll") {
387
- const retryFn = Reflect.get(target, prop);
388
- return new Proxy(retryFn, { apply: (fnTarget, _thisArg, args) => {
389
- const delaySeconds = args[0]?.delaySeconds;
390
- addQueueEvent("retryAll", void 0, delaySeconds);
391
- count.retryRemaining();
392
- Reflect.apply(fnTarget, batch, args);
393
- } });
394
- }
395
- return Reflect.get(target, prop);
381
+ const batchFn = asFunction(member(target, prop));
382
+ if (prop === "ackAll" && batchFn) return new Proxy(batchFn, { apply: (fnTarget) => {
383
+ addQueueEvent("ackAll");
384
+ count.ackRemaining();
385
+ fnTarget.apply(batch, []);
386
+ } });
387
+ else if (prop === "retryAll" && batchFn) return new Proxy(batchFn, { apply: (fnTarget, _thisArg, args) => {
388
+ const delaySeconds = trapArgs(args)[0]?.delaySeconds;
389
+ addQueueEvent("retryAll", void 0, delaySeconds);
390
+ count.retryRemaining();
391
+ applyTrap(fnTarget, batch, args);
392
+ } });
393
+ return member(target, prop);
396
394
  } });
397
395
  }
398
396
  /**
@@ -485,7 +483,7 @@ async function exportSpans(traceId, tracker, ctx) {
485
483
  function createHandlerFlow(instrumentation) {
486
484
  return (handlerFn, [trigger, env, context$1]) => {
487
485
  const { ctx: proxiedCtx, tracker } = proxyExecutionContext(context$1);
488
- const tracer = trace.getTracer("autotel-edge");
486
+ const tracer = workerTracer("autotel-edge");
489
487
  const { name, options, context: spanContext } = instrumentation.getInitialSpanInfo(trigger);
490
488
  if (options.attributes) options.attributes["faas.coldstart"] = coldStart;
491
489
  else options.attributes = { "faas.coldstart": coldStart };
@@ -503,7 +501,7 @@ function createHandlerFlow(instrumentation) {
503
501
  if (instrumentation.executionSucces) instrumentation.executionSucces(span, trigger, result);
504
502
  return result;
505
503
  } catch (error) {
506
- span.recordException(error);
504
+ span.recordException(toException(error));
507
505
  span.setStatus({
508
506
  code: SpanStatusCode.ERROR,
509
507
  message: error instanceof Error ? error.message : String(error)
@@ -622,7 +620,7 @@ function initProvider(config) {
622
620
  "telemetry.sdk.language": "js"
623
621
  });
624
622
  new WorkerTracerProvider(config.spanProcessors, resource).register();
625
- trace.getTracer("autotel-edge").setHeadSampler(config.sampling.headSampler);
623
+ workerTracer("autotel-edge").setHeadSampler(config.sampling.headSampler);
626
624
  providerInitialized = true;
627
625
  }
628
626
  /**
package/dist/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as getWorkflowLogger, i as getRequestLogger, n as getActorLogger, r as getQueueLogger } from "./execution-logger-BxmgP8jF.js";
1
+ import { a as getWorkflowLogger, i as getRequestLogger, n as getActorLogger, r as getQueueLogger } from "./execution-logger-6IZS5fEz.js";
2
2
 
3
3
  export * from "autotel-edge/logger"
4
4
 
@@ -0,0 +1,10 @@
1
+ import { trace } from "@opentelemetry/api";
2
+
3
+ //#region src/tracer.ts
4
+ /** The tracer autotel-edge installs, which carries the worker's span buffer. */
5
+ function workerTracer(name = "autotel-edge") {
6
+ return trace.getTracer(name);
7
+ }
8
+
9
+ //#endregion
10
+ export { workerTracer as t };
@@ -0,0 +1,108 @@
1
+ //#region src/values.ts
2
+ /** The value as an object, or undefined when it is anything else. */
3
+ function asRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
5
+ }
6
+ /** The string the value carries, or undefined when it carries anything else. */
7
+ function asString(value) {
8
+ return typeof value === "string" ? value : void 0;
9
+ }
10
+ /** The number the value carries, or undefined when it carries anything else. */
11
+ /** A string with something in it - a blank one counts as absent. */
12
+ function nonEmptyString(value) {
13
+ const text = asString(value);
14
+ return text !== void 0 && text.trim() !== "" ? text : void 0;
15
+ }
16
+ function asNumber(value) {
17
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
18
+ }
19
+ /** The boolean the value carries, or undefined when it carries anything else. */
20
+ function asBoolean(value) {
21
+ return typeof value === "boolean" ? value : void 0;
22
+ }
23
+ /** Whether the value is callable. */
24
+ function isFunction(value) {
25
+ return typeof value === "function";
26
+ }
27
+ /** The value as a callable, or undefined when it is not one. */
28
+ function asFunction(value) {
29
+ if (typeof value !== "function") return void 0;
30
+ return value;
31
+ }
32
+ /** One field of a value, when the value is an object at all. */
33
+ function readProperty(source, key) {
34
+ return asRecord(source)?.[key];
35
+ }
36
+ /** Whether an object carries a callable under this name. */
37
+ function hasMethod(source, name) {
38
+ return isFunction(readProperty(source, name));
39
+ }
40
+ /** Whether an object carries a callable under every one of these names. */
41
+ function hasMethods(source, names) {
42
+ return names.every((name) => hasMethod(source, name));
43
+ }
44
+ /**
45
+ * Call the function a proxy trap is wrapping, with the arguments the caller
46
+ * actually passed.
47
+ *
48
+ * SAFETY: an apply trap receives the argument list of the very call it is
49
+ * intercepting, so those arguments are the wrapped function's own parameter
50
+ * tuple and its result is that function's return. TypeScript types a trap's
51
+ * `argArray` as `any[]` and cannot carry either fact, so it is stated here
52
+ * once rather than at every trap in the package.
53
+ */
54
+ function applyTrap(fn, thisArg, args) {
55
+ return fn.apply(thisArg, args);
56
+ }
57
+ /**
58
+ * Read a member off a proxy target, by whatever key the trap was asked for.
59
+ *
60
+ * SAFETY: a get trap forwards every key, including ones the target's declared
61
+ * type does not name. The value is returned as unread, so nothing here claims
62
+ * to know what it is.
63
+ */
64
+ function member(target, key) {
65
+ return target[key];
66
+ }
67
+ /**
68
+ * The arguments a proxy trap intercepted, read as the wrapped call's own
69
+ * parameters.
70
+ *
71
+ * SAFETY: as with applyTrap - an apply trap receives the argument list of the
72
+ * very call it is intercepting, which is that function's parameter tuple.
73
+ * TypeScript types a trap's `argArray` as `any[]` and cannot carry that.
74
+ */
75
+ function trapArgs(args) {
76
+ return args;
77
+ }
78
+ /** A field of a value's field - `readProperty(readProperty(v, a), b)`, said once. */
79
+ function readPath(source, ...keys) {
80
+ return keys.reduce((value, key) => readProperty(value, key), source);
81
+ }
82
+ /** The number at this path, when the value carries one there. */
83
+ function numberAt(source, ...keys) {
84
+ const value = readPath(source, ...keys);
85
+ return asNumber(value) ?? asNumber(Number(asString(value)));
86
+ }
87
+ /** The scalar the value carries - string, number or boolean - or undefined. */
88
+ function asScalar(value) {
89
+ return asString(value) ?? asNumber(value) ?? asBoolean(value);
90
+ }
91
+ /** A homogeneous list of scalars, or undefined when the value is not one. */
92
+ function asScalarArray(value) {
93
+ if (!Array.isArray(value)) return void 0;
94
+ if (value.every((v) => asString(v) !== void 0)) return value.map(String);
95
+ if (value.every((v) => asNumber(v) !== void 0)) return value.map(Number);
96
+ if (value.every((v) => asBoolean(v) !== void 0)) return value.map(Boolean);
97
+ }
98
+ /**
99
+ * What a value is, for a diagnostic attribute: the same words `typeof` uses,
100
+ * plus `null` and `array`, which are the two cases `typeof` answers uselessly.
101
+ */
102
+ function describeValue(value) {
103
+ if (value === null) return "null";
104
+ return Array.isArray(value) ? "array" : typeof value;
105
+ }
106
+
107
+ //#endregion
108
+ export { trapArgs as _, asRecord as a, asString as c, hasMethods as d, member as f, readProperty as g, readPath as h, asNumber as i, describeValue as l, numberAt as m, asBoolean as n, asScalar as o, nonEmptyString as p, asFunction as r, asScalarArray as s, applyTrap as t, hasMethod as u };
@@ -0,0 +1,19 @@
1
+ //#region src/values.d.ts
2
+ /**
3
+ * Reading values that arrive from outside: a Worker's env, a binding's
4
+ * response, an error someone threw. Nothing about them is known until one of
5
+ * these asks, and each answers with the type it looked for or `undefined`.
6
+ *
7
+ * This is the boundary. The `typeof` checks and the `unknown` parameters below
8
+ * are what a boundary is made of; past it, the package works with types.
9
+ *
10
+ * Internal - not exported from the package entry points. Deliberately local
11
+ * rather than shared with `autotel`: this package targets the edge and pulls
12
+ * in no Node-side dependency.
13
+ */
14
+ /** An object whose fields have not been read yet. */
15
+ interface UnknownRecord {
16
+ [key: string]: unknown;
17
+ }
18
+ //#endregion
19
+ export { UnknownRecord as t };