-
Notifications
You must be signed in to change notification settings - Fork 912
Closed
Labels
Description
I have to rewrite this in every project. Is there somewhere this can fit?
function withSpan<T>(span: Span, f: () => T): T {
try {
return context.with(setSpan(context.active(), span), f);
} catch (e) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: (e && (e.stack || e.message)) || String(e),
});
throw e;
} finally {
span.end();
}
}
async function withSpanAsync<T>(span: Span, f: () => Promise<T>): Promise<T> {
try {
return await context.with(setSpan(context.active(), span), f);
} catch (e) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: (e && (e.stack || e.message)) || String(e),
});
throw e;
} finally {
span.end();
}
}