File transform events

Summary: Correctly generate log entries for file transforms and ping telemetry using the new Logger API.

Reviewed By: bestander, cpojer

Differential Revision: D4081325

fbshipit-source-id: 7d50d54eb673a0276512db6ad5ff21c344495612
This commit is contained in:
Ovidiu Viorel Iepure 2016-11-03 07:41:57 -07:00 committed by Facebook Github Bot
parent 4d23c1f423
commit 1ac86b2304
2 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,7 @@
*/
'use strict';
const Logger = require('../Logger');
const Promise = require('promise');
const declareOpts = require('../lib/declareOpts');
@ -115,6 +116,8 @@ class Transformer {
return this
._transform(this._transformModulePath, fileName, code, options)
.then(result => {
Logger.log(result.transformFileStartLogEntry);
Logger.log(result.transformFileEndLogEntry);
debug('done transforming file', fileName);
return result;
})

View File

@ -24,6 +24,14 @@ function transformCode(transform, filename, sourceCode, options, callback) {
const params = makeTransformParams(filename, sourceCode, options.transform);
const isJson = filename.endsWith('.json');
const transformFileStartLogEntry = {
action_name: 'Transforming file',
action_phase: 'start',
file_name: filename,
log_entry_label: 'Transforming file',
start_timestamp: process.hrtime(),
};
transform(params, (error, transformed) => {
if (error) {
callback(error);
@ -52,8 +60,20 @@ function transformCode(transform, filename, sourceCode, options, callback) {
? {dependencies: [], dependencyOffsets: []}
: extractDependencies(code);
const timeDelta = process.hrtime(transformFileStartLogEntry.start_timestamp);
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
const transformFileEndLogEntry = {
action_name: 'Transforming file',
action_phase: 'end',
file_name: filename,
duration_ms: duration_ms,
log_entry_label: 'Transforming file',
};
result.code = code;
result.map = map;
result.transformFileStartLogEntry = transformFileStartLogEntry;
result.transformFileEndLogEntry = transformFileEndLogEntry;
callback(null, result);
});