import { context, } from '@opentelemetry/api';
export function startSpan(tracer, name, cb) {
    return tracer.startActiveSpan(name, span => {
        try {
            return cb(span);
        }
        finally {
            span.end();
        }
    });
}
export function startAsyncSpan(tracer, name, cb) {
    return tracer.startActiveSpan(name, async (span) => {
        try {
            return await cb(span);
        }
        finally {
            span.end();
        }
    });
}
export function manualSpan(tracer, name, durationMs, attributes) {
    const startTime = Date.now() - durationMs;
    const span = tracer.startSpan(name, { startTime }, context.active());
    if (attributes) {
        span.setAttributes(attributes);
    }
    span.end(startTime + durationMs);
}
//# sourceMappingURL=span.js.map