feat(core-shared/instrumentation): withSpan attaches runtime __instrumented marker

This commit is contained in:
2026-05-12 22:39:13 +02:00
parent a593962b3d
commit 9e21baf5fb
2 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import type { ITracer, SpanOpts } from "./tracer.interface";
import type { Instrumented } from "../conformance/brands";
import { attachBrand } from "../conformance/brand-runtime";
export function withSpan<Args extends unknown[], R, Extra extends object>(
tracer: ITracer,
@@ -20,7 +21,8 @@ export function withSpan<Args extends unknown[], R>(
const resolved = typeof opts === "function" ? opts(args) : opts;
return tracer.startSpan(resolved, () => fn(...args));
};
// Cast is the only runtime concession — the brand is a phantom type;
// there is no real `__instrumented` property at runtime.
attachBrand(wrapped, "__instrumented");
// Cast is the type-level concession — the brand is now also a non-enumerable
// runtime property attached above by `attachBrand`.
return wrapped as Instrumented<(...args: Args) => Promise<R>>;
}