-
Notifications
You must be signed in to change notification settings - Fork 374
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
fix: send analytics on successful commands #4227
Conversation
📊 Benchmark resultsComparing with 71950d3 Package size: 508 MB(no change)
Legend
|
@@ -300,13 +300,14 @@ class BaseCommand extends Command { | |||
const duration = getDuration(startTime) | |||
const status = error_ === undefined ? 'success' : 'error' | |||
|
|||
debug(`${this.name()}:onEnd`)(`Status: ${status}`) | |||
debug(`${this.name()}:onEnd`)(`Duration: ${duration}ms`) | |||
const command = Array.isArray(this.args) ? this.args[0] : this.name() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems rather defensive, but I rather not have the CLI error if something changes with commander
3582efd
to
9ee00c7
Compare
@@ -49,9 +49,40 @@ test.serial('should track --telemetry-enable', async (t) => { | |||
test('should send netlify-cli/<version> user-agent', async (t) => { | |||
await withMockApi(routes, async ({ apiUrl, requests }) => { | |||
await callCli(['api', 'listSites'], getCLIOptions(apiUrl)) | |||
t.true(requests.length !== 0) | |||
const request = requests.find(({ path }) => path === '/api/v1/track') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was failing on my machine as the mock api can receive requests in a different order.
Updated the test to better search the analytics request
9ee00c7
to
0adc945
Compare
program | ||
.parseAsync(process.argv) | ||
.then(() => { | ||
program.onEnd() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: if onEnd()
throws, it will be called twice. Is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! I don't see how it can throw
cli/src/commands/base-command.js
Line 298 in c2040bb
async onEnd(error_) { |
We can put everything in onEnd
to make it clear that it shouldn't throw, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it looks pretty safe.
I think it looks good as is 👍
This PR shows a package size of 508MB for some reason. Going to open an issue to investigate |
🎉 Thanks for submitting a pull request! 🎉
Summary
Fixes #4196
Will think on how to test this and add a testDoneFor us to review and ship your PR efficiently, please perform the following steps:
passes our tests.
A picture of a cute animal (not mandatory, but encouraged)