feat(core-shared): add withSpan higher-order helper

This commit is contained in:
2026-05-06 23:41:54 +02:00
parent fdd4e9141b
commit 0ffda8078f
2 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import type { ITracer, SpanOpts } from "./tracer.interface";
export function withSpan<Args extends unknown[], R>(
tracer: ITracer,
opts: SpanOpts | ((args: Args) => SpanOpts),
fn: (...args: Args) => Promise<R>,
): (...args: Args) => Promise<R> {
return (...args) => {
const resolved = typeof opts === "function" ? opts(args) : opts;
return tracer.startSpan(resolved, () => fn(...args));
};
}