UNPKG

autotel-cloudflare

Version:

The #1 OpenTelemetry package for Cloudflare Workers - complete bindings coverage, native CF OTel integration, advanced sampling

55 lines (54 loc) 1.33 kB
// src/bindings/common.ts var PromiseTracker = class { promises = []; track(promise) { this.promises.push(promise); } async wait() { await Promise.allSettled(this.promises); } }; function proxyExecutionContext(ctx) { const tracker = new PromiseTracker(); const proxied = new Proxy(ctx, { get(target, prop) { if (prop === "waitUntil") { return (promise) => { tracker.track(promise); return target.waitUntil(promise); }; } return Reflect.get(target, prop); } }); return { ctx: proxied, tracker }; } var unwrapSymbol = /* @__PURE__ */ Symbol("unwrap"); function isWrapped(item) { return item && !!item[unwrapSymbol]; } function unwrap(item) { if (item && isWrapped(item)) { return item[unwrapSymbol]; } else { return item; } } function setAttr(span, key, value) { if (value !== void 0 && value !== null) { span.setAttribute(key, value); } } function wrap(item, handler) { const proxy = new Proxy(item, handler); Object.defineProperty(proxy, unwrapSymbol, { value: item, writable: false, enumerable: false, configurable: false }); return proxy; } export { isWrapped, proxyExecutionContext, setAttr, unwrap, wrap }; //# sourceMappingURL=chunk-O4IYKWPJ.js.map //# sourceMappingURL=chunk-O4IYKWPJ.js.map