From 200da4ee83e1cfbf830eb326a47e0a0c641443ed Mon Sep 17 00:00:00 2001 From: Javier Auso Date: Wed, 6 Nov 2024 13:33:36 +0100 Subject: [PATCH] feat(packages/sui-decorators): add error reporter to tracer decorator --- .../sui-decorators/src/decorators/tracer/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/sui-decorators/src/decorators/tracer/index.js b/packages/sui-decorators/src/decorators/tracer/index.js index b8fc7df41..91175692e 100644 --- a/packages/sui-decorators/src/decorators/tracer/index.js +++ b/packages/sui-decorators/src/decorators/tracer/index.js @@ -14,6 +14,15 @@ const getReporter = () => { return customReporter || new ConsoleReporter() } +const getErrorReporter = () => { + const defaultErrorReporter = () => undefined + const customErrorReporter = isNode + ? global.__SUI_DECORATOR_TRACER_ERROR_REPORTER__ + : window.__SUI_DECORATOR_TRACER_ERROR_REPORTER__ + + return customErrorReporter || defaultErrorReporter +} + export default ({metric = null} = {}) => { return (target, fnName, descriptor) => { const {configurable, enumerable, writable} = descriptor @@ -58,6 +67,9 @@ export default ({metric = null} = {}) => { status: error ? statusCodes.FAIL : statusCodes.SUCCESS, value: endTime - startTime }) + if (error) { + getErrorReporter()(error, metricName) + } } else { reporter.send({ metricName, @@ -76,6 +88,7 @@ export default ({metric = null} = {}) => { status: statusCodes.FAIL, value: endTime - startTime }) + getErrorReporter()(error, metricName) return Promise.reject(error) })