Skip to content

Commit

Permalink
Updated analytics to be passive yet guaranteed to complete before exit
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Nov 12, 2024
1 parent 634e0d9 commit 6de008c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ export default class AnalyticsCommand {

http: typeof deps.HTTP

initialize: Promise<void>;

constructor(config: Interfaces.Config) {
this.config = config
this.http = deps.HTTP.create({
headers: {'user-agent': config.userAgent},
})
this.initialize = this.init()
}

async record(opts: RecordOpts) {
await this.init()
await this.initialize
const plugin = opts.Command.plugin
if (!plugin) {
debug('no plugin found for analytics')
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/hooks/postrun/performance_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const performance_analytics: Hook<'postrun'> = async function () {
const cmdStartTime = global.cliTelemetry.commandRunDuration
global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime)
global.cliTelemetry.lifecycleHookCompletion.postrun = true
await Reflect.get(globalThis, 'recordPromise')
}

export default performance_analytics
2 changes: 1 addition & 1 deletion packages/cli/src/hooks/prerun/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const analytics: Hook<'prerun'> = async function (options) {

global.cliTelemetry = telemetry.setupTelemetry(this.config, options)
const analytics = new Analytics(this.config)
await analytics.record(options)
Reflect.set(globalThis, 'recordPromise', analytics.record(options))
}

export default analytics

0 comments on commit 6de008c

Please sign in to comment.