Milan Panta
09/03/2024, 6:40 AMexport function traceSpan<F extends (...args: any) => ReturnType<F>>(
name: string,
func: F,
message: any,
): ReturnType<F> {
var singleSpan: Span;
if (bindingSpan) {
const ctx = trace.setSpan(context.active(), bindingSpan);
singleSpan = webTracerWithZone.startSpan(name, undefined, ctx);
// Set custom attributes
singleSpan.setAttribute('custom.name', name);
singleSpan.setAttribute('custom.message', message);
if (name === 'errorBoundary') {
singleSpan.setAttribute('custom.errorBoundary', message);
}
bindingSpan = undefined;
} else {
singleSpan = webTracerWithZone.startSpan(name);
// Set custom attributes for non-binding spans as well
singleSpan.setAttribute('custom.name', name);
singleSpan.setAttribute('custom.message', message);
}
return context.with(trace.setSpan(context.active(), singleSpan), () => {
try {
const result = func();
singleSpan.setAttribute('custom.success', true);
singleSpan.end();
return result;
} catch (error) {
singleSpan.setStatus({ code: SpanStatusCode.ERROR });
singleSpan.setAttribute('custom.error', error as AttributeValue);
singleSpan.setAttribute('custom.success', false);
singleSpan.end();
throw error;
}
});
}
Yuvraj Singh
09/03/2024, 7:04 AMSigNoz is an open-source APM. It helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc.
Powered by