-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add logic to send analytics data #5545
Add logic to send analytics data #5545
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
…ure/add-logic-to-send-telemetry-data
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.
Looks good, I left a couple comments
v-next/hardhat/src/internal/cli/telemetry/analytics/analytics.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/cli/telemetry/analytics/analytics.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/src/internal/cli/telemetry/analytics/analytics.ts
Outdated
Show resolved
Hide resolved
v-next/hardhat/test/internal/cli/telemetry/analytics/analytics.ts
Outdated
Show resolved
Hide resolved
* | ||
* @returns A promise that resolves to the path of the telemetry directory. | ||
*/ | ||
export async function getTelemetryDir(packageName?: string): Promise<string> { |
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.
Can we make sure that this dir is not deleted by the clean --global
task? /cc @schaable
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.
I don't think so, as the global
flag deletes the cache
path and telemetry uses the data
path.
import { postJsonRequest } from "@ignored/hardhat-vnext-utils/request"; | ||
|
||
// These keys are expected to be public | ||
const ANALYTICS_URL = "https://www.google-analytics.com/mp/collect"; |
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.
Are these the test or the production values?
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.
Production values
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.
I'll updated the code with test variables. Before merging the code, I'll replace them with production values.
DO NOT REMOVE THIS COMMENT, it works as a reminder
v-next/hardhat/src/internal/cli/telemetry/analytics/analytics-subprocess.ts
Outdated
Show resolved
Hide resolved
} | ||
|
||
export function getUserType(): string { | ||
return isCi() ? "CI" : "Developer"; |
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.
We don't send analytics hits from CIs anymore, so we should remove the userType
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.
"result.json", | ||
); | ||
|
||
(() => { |
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 lambda is not needed.
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.
f556dd2
to
3e59fa5
Compare
async function createSubprocessToSendAnalytics( | ||
payload: TelemetryConsentPayload | Payload, | ||
): Promise<void> { | ||
const fileExt = |
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.
Let's document this here with a comment because we'll forget it
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.
Done here, with other smaller fixes
await writeJsonFile(process.env.HARDHAT_TEST_SUBPROCESS_RESULT_PATH, payload); | ||
} | ||
|
||
await main(); |
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.
We have top-level-await now
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.
Done here, with other smaller fixes
@@ -0,0 +1,20 @@ | |||
// This file will be copied to the "analytics" folder so it will be executed as a subprocess. |
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.
Not used anymore
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.
Done here, with other smaller fixes
There are just a few small comments regarding the PR, but we need to actually validate that this is working as intended in analytics, and in particular, we should validate that the custom dimensions work. Note that we are using a new analytics property for testing, so no setup has been done there. |
…ure/add-logic-to-send-telemetry-data
…ure/add-logic-to-send-telemetry-data
Both Chris and I have separately done a manual test that events are coming through with the expected custom dimensions. This PR is pointing at a test Google Analytics environment. |
How it works in short:
so far there are 2 types of analytics that can be sent (like in the old hardhat).
The first one is a very specific type of analytics, so it cannot be extended or modified.
The second one is more general so other types of analytics' payloads will have the same structure.
The creation of the payload is done in the main process, then a detached subprocess is spawn to perform the http request.
In the tests I created a fake subprocess file that tests that the correct payload is received by the subprocess.
I also did a bit of a "hacky" thing to run the tests in the CI:
the analytics have a check that avoids the execution in CI environments. The check is performed on several env variables. So before the test I overwrite them, and then I reset them after the test.
TODO