Refactor browser connection performance tracking

Reviewed By: lblasa

Differential Revision: D51158256

fbshipit-source-id: 17e020dd3c26ac73bf2cf0ceb4c664638c6778e9
This commit is contained in:
Andrey Goncharov
2023-11-09 08:25:28 -08:00
committed by Facebook GitHub Bot
parent 54217f2c79
commit d54bd7c3ba
4 changed files with 27 additions and 16 deletions

View File

@@ -95,9 +95,25 @@ const rootPath = argv.bundler
: path.resolve(__dirname, '..'); // In pre-packaged versions of the server, static is copied inside the package.
const staticPath = path.join(rootPath, 'static');
async function start() {
const t0 = performance.now();
const t0 = performance.now();
const browserConnectionTimeout = setTimeout(() => {
tracker.track('browser-connection-created', {
successful: false,
timeMS: performance.now() - t0,
timedOut: true,
});
}, 10000);
const reportBrowserConnection = (successful: boolean) => {
clearTimeout(browserConnectionTimeout);
tracker.track('browser-connection-created', {
successful,
timeMS: performance.now() - t0,
timedOut: false,
});
};
async function start() {
const isProduction =
process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test';
const environmentInfo = await getEnvironmentInfo(
@@ -206,6 +222,10 @@ async function start() {
environmentInfo,
);
flipperServer.once('browser-connection-created', () => {
reportBrowserConnection(true);
});
const t5 = performance.now();
const serverCreatedMS = t5 - t4;
console.info(
@@ -311,6 +331,7 @@ process.on('uncaughtException', (error) => {
'[flipper-server] uncaught exception, process will exit.',
error,
);
reportBrowserConnection(false);
process.exit(1);
});
@@ -325,5 +346,6 @@ process.on('unhandledRejection', (reason, promise) => {
start().catch((e) => {
console.error(chalk.red('Server startup error: '), e);
reportBrowserConnection(false);
process.exit(1);
});