feat: improve metrics naming (#8770)

fix CLOUD-83
This commit is contained in:
darkskygit 2024-11-12 03:52:52 +00:00
parent cc9a23e424
commit 5cde590a4f
No known key found for this signature in database
GPG Key ID: 97B7D036B1566E9D

View File

@ -26,21 +26,20 @@ export const CallMetric = (
return desc;
}
desc.value = async function (...args: any[]) {
const timer = metrics[scope].histogram(name, {
description: `function call time costs of ${name}`,
unit: 'ms',
});
const count = metrics[scope].counter(`${name}_calls`, {
description: `function call counter of ${name}`,
});
const errorCount = metrics[scope].counter(`${name}_errors`, {
description: `function call error counter of ${name}`,
});
const timer = metrics[scope].histogram('function_timer', {
description: 'function call time costs',
unit: 'ms',
});
const count = metrics[scope].counter('function_calls', {
description: 'function call counter',
});
desc.value = async function (...args: any[]) {
const start = Date.now();
let error = false;
const end = () => {
timer?.record(Date.now() - start, attrs);
timer?.record(Date.now() - start, { ...attrs, name, error });
};
try {
@ -50,10 +49,11 @@ export const CallMetric = (
return await originalMethod.apply(this, args);
} catch (err) {
if (!record || !!record.error) {
errorCount.add(1, attrs);
error = true;
}
throw err;
} finally {
count.add(1, { ...attrs, name, error });
if (!record || !!record.timer) {
end();
}