diff --git a/src/Client.js b/src/Client.js index 5d5a067c6..2aea2afb6 100644 --- a/src/Client.js +++ b/src/Client.js @@ -16,6 +16,7 @@ import {setPluginState} from './reducers/pluginStates.js'; import {ReactiveSocket, PartialResponder} from 'rsocket-core'; // $FlowFixMe perf_hooks is a new API in node import {performance} from 'perf_hooks'; +import {reportPluginFailures} from './utils/metrics'; const EventEmitter = (require('events'): any); const invariant = require('invariant'); @@ -368,7 +369,11 @@ export default class Client extends EventEmitter { } call(api: string, method: string, params?: Object): Promise { - return this.rawCall('execute', {api, method, params}); + return reportPluginFailures( + this.rawCall('execute', {api, method, params}), + `Call-${method}`, + api, + ); } send(api: string, method: string, params?: Object): void { diff --git a/src/fb-stubs/Logger.js b/src/fb-stubs/Logger.js index b57deedf7..b8d00a431 100644 --- a/src/fb-stubs/Logger.js +++ b/src/fb-stubs/Logger.js @@ -18,7 +18,7 @@ export default class LogManager { scribeLogger: ScribeLogger; - track(type: TrackType, event: string, data: ?any) {} + track(type: TrackType, event: string, data: ?any, plugin?: string) {} trackTimeSince(mark: string, eventName: ?string) {} diff --git a/src/utils/metrics.js b/src/utils/metrics.js index 99bde8c38..c6a7493e2 100644 --- a/src/utils/metrics.js +++ b/src/utils/metrics.js @@ -11,6 +11,8 @@ import {getInstance} 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. + + Use this variant to report failures in core platform (Flipper) code. */ export function reportPlatformFailures( promise: Promise<*>, @@ -27,3 +29,27 @@ export function reportPlatformFailures( }, ); } + +/* + * 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. + + Use this variant to report failures in plugin code. + */ +export function reportPluginFailures( + promise: Promise<*>, + name: string, + plugin: string, +): Promise<*> { + return promise.then( + fulfilledValue => { + getInstance().track('success-rate', name, 1, plugin); + return fulfilledValue; + }, + rejectionReason => { + getInstance().track('success-rate', name, 0, plugin); + return Promise.reject(rejectionReason); + }, + ); +}