Skip to content

Commit

Permalink
chore(telemetry): collect bootstrap times (#15659)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamo authored and GatsbyJS Bot committed Jul 15, 2019
1 parent 651a9b9 commit d18a9e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/gatsby-cli/src/reporter/index.js
Expand Up @@ -8,6 +8,8 @@ const { getErrorFormatter } = require(`./errors`)
const reporterInstance = require(`./reporters`)
const constructError = require(`../structured-errors/construct-error`)
const errorFormatter = getErrorFormatter()
const { trackCli } = require(`gatsby-telemetry`)
const convertHrtime = require(`convert-hrtime`)

import type { ActivityTracker, ActivityArgs, Reporter } from "./types"

Expand Down Expand Up @@ -120,6 +122,7 @@ const reporter: Reporter = {
const { parentSpan } = activityArgs
const spanArgs = parentSpan ? { childOf: parentSpan } : {}
const span = tracer.startSpan(name, spanArgs)
let startTime = 0

const activity = reporterInstance.createActivity({
type: `spinner`,
Expand All @@ -129,8 +132,9 @@ const reporter: Reporter = {

return {
start() {
startTime = process.hrtime()
activity.update({
startTime: process.hrtime(),
startTime: startTime,
})
},
setStatus(status) {
Expand All @@ -139,6 +143,13 @@ const reporter: Reporter = {
})
},
end() {
trackCli(`ACTIVITY_DURATION`, {
name: name,
duration: Math.round(
convertHrtime(process.hrtime(startTime))[`milliseconds`]
),
})

span.finish()
activity.done()
},
Expand Down

0 comments on commit d18a9e6

Please sign in to comment.