type SpanLike = { setAttribute: (key: string, value: unknown) => void; }; type SpanOptions = { tracer?: string; attributes?: Record; }; export function setSpanAttributes( span: SpanLike | null | undefined, attributes: Record, ): void { for (const [key, value] of Object.entries(attributes)) { span?.setAttribute?.(key, value); } } export async function withActiveSpan( _name: string, options: SpanOptions, fn: (span: SpanLike) => Promise, ): Promise { const attributes = new Map( Object.entries(options.attributes ?? {}), ); const span: SpanLike = { setAttribute(key, value) { attributes.set(key, value); }, }; return await fn(span); }