refactor(Telemetry): Move telemetry handling to scripts/serverless.js

This commit is contained in:
Piotr Grzesik 2021-04-27 11:54:52 +02:00
parent fac47cfa23
commit 4cab803ccd

View File

@ -16,6 +16,13 @@ if (require('../lib/utils/tabCompletion/isSupported') && process.argv[2] === 'co
const handleError = require('../lib/cli/handle-error');
const humanizePropertyPathKeys = require('../lib/configuration/variables/humanize-property-path-keys');
const {
storeLocally: storeTelemetryLocally,
send: sendTelemetry,
} = require('../lib/utils/telemetry');
const generateTelemetryPayload = require('../lib/utils/telemetry/generatePayload');
const processBackendNotificationRequest = require('../lib/utils/processBackendNotificationRequest');
let serverless;
process.once('uncaughtException', (error) =>
@ -634,6 +641,16 @@ const processSpanPromise = (async () => {
// Run command
await serverless.run();
}
await storeTelemetryLocally(await generateTelemetryPayload(serverless));
let backendNotificationRequest;
if (commands.join(' ') === 'deploy') {
backendNotificationRequest = await sendTelemetry({
serverlessExecutionSpan: processSpanPromise,
});
}
if (backendNotificationRequest) {
await processBackendNotificationRequest(backendNotificationRequest);
}
} catch (error) {
// If Dashboard Plugin, capture error
const dashboardPlugin =