Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated analytics to be passive yet guaranteed to complete before exit #3085

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading