Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(packages/sui-decorators): add error reporter to tracer decorator #1860

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/sui-decorators/src/decorators/tracer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -76,6 +88,7 @@ export default ({metric = null} = {}) => {
status: statusCodes.FAIL,
value: endTime - startTime
})
getErrorReporter()(error, metricName)

return Promise.reject(error)
})
Expand Down
Loading