UNPKG

@fiberplane/hono-otel

Version:

Hono middleware to forward OpenTelemetry traces to a local instance of @fiberplane/studio

23 lines (22 loc) 870 B
import { PromiseStore } from "../promiseStore.js"; /** * This returns a proxy-ed ExecutionContext which has a waitUntil method that * collects promises passed to it. It also returns an array of promises that */ export function patchWaitUntil(context, store = new PromiseStore()) { const proxyContext = new Proxy(context, { get(target, prop, receiver) { const value = Reflect.get(target, prop, receiver); if (prop === "waitUntil" && typeof value === "function") { const original = value; return function waitUntil(promise) { const scope = this === receiver ? target : this; store.add(promise); return original.apply(scope, [promise]); }; } return value; }, }); return proxyContext; }