Add recordSuccessMetric utility
Summary: Wraps a future and records the success rate. This will be stored along with the sessionId and the userId, so we can drill down and get the success rate at different levels. Reviewed By: passy Differential Revision: D13635049 fbshipit-source-id: 4e0e6bdc0f9b76b08cf37c5d9fe87909f7338534
This commit is contained in:
committed by
Facebook Github Bot
parent
4a5dae8f4f
commit
90de3c6868
30
src/utils/metrics.js
Normal file
30
src/utils/metrics.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type Logger from '../fb-stubs/Logger';
|
||||
|
||||
/*
|
||||
* Wraps a Promise, preserving it's functionality but logging the success or
|
||||
failure state of it, with a given name, based on whether it's fulfilled or
|
||||
rejected.
|
||||
*/
|
||||
export function recordSuccessMetric(
|
||||
promise: Promise<*>,
|
||||
name: string,
|
||||
logger: Logger,
|
||||
): Promise<*> {
|
||||
return promise.then(
|
||||
fulfilledValue => {
|
||||
logger.track('success-rate', name, 1);
|
||||
return fulfilledValue;
|
||||
},
|
||||
rejectionReason => {
|
||||
logger.track('success-rate', name, 0);
|
||||
return Promise.reject(rejectionReason);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user