feat(core-shared): add withSpan higher-order helper
This commit is contained in:
12
packages/core-shared/src/instrumentation/with-span.ts
Normal file
12
packages/core-shared/src/instrumentation/with-span.ts
Normal 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));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user