Skip to content

Commit 76c4422

Browse files
add debug module
1 parent 093ae33 commit 76c4422

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

v-next/hardhat/src/internal/cli/telemetry/analytics/analytics.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
import os from "node:os";
99

1010
import { spawnDetachedSubProcess } from "@ignored/hardhat-vnext-utils/subprocess";
11+
import debug from "debug";
1112

1213
import { getHardhatVersion } from "../../../utils/package.js";
1314
import {
@@ -17,7 +18,7 @@ import {
1718

1819
import { getAnalyticsClientId } from "./utils.js";
1920

20-
// TODO:log const log = debug("hardhat:core:global-dir");
21+
const log = debug("hardhat:cli:telemetry:analytics");
2122

2223
const SESSION_ID = Math.random().toString();
2324
const ENGAGEMENT_TIME_MSEC = "10000";
@@ -79,6 +80,10 @@ async function sendAnalytics(
7980
async function createSubprocessToSendAnalytics(
8081
payload: TelemetryConsentPayload | Payload,
8182
): Promise<void> {
83+
log(
84+
`Sending analytics for '${payload.events[0].name}'. Payload: ${JSON.stringify(payload)}`,
85+
);
86+
8287
// The HARDHAT_TEST_SUBPROCESS_RESULT_PATH env variable is used in the tests to instruct the subprocess to write the payload to a file
8388
// instead of sending it.
8489
// During testing, the subprocess file is a ts file, whereas in production, it is a js file (compiled code).

v-next/hardhat/src/internal/cli/telemetry/analytics/utils.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import {
88
readJsonFile,
99
writeJsonFile,
1010
} from "@ignored/hardhat-vnext-utils/fs";
11+
import debug from "debug";
12+
13+
const log = debug("hardhat:cli:telemetry:analytics:utils");
1114

1215
const ANALYTICS_FILE_NAME = "analytics.json";
1316

1417
export async function getAnalyticsClientId(): Promise<string> {
1518
let clientId = await readAnalyticsClientId();
1619

1720
if (clientId === undefined) {
18-
// TODO:log log("Client Id not found, generating a new one");
19-
clientId = crypto.randomUUID();
21+
log("Client Id not found, generating a new one");
2022

23+
clientId = crypto.randomUUID();
2124
await writeAnalyticsClientId(clientId);
2225
}
2326

@@ -28,15 +31,16 @@ async function readAnalyticsClientId(): Promise<string | undefined> {
2831
const globalTelemetryDir = await getTelemetryDir();
2932
const filePath = path.join(globalTelemetryDir, ANALYTICS_FILE_NAME);
3033

31-
// TODO:log log(`Looking up Client Id at ${filePath}`);
34+
log(`Looking up Client Id at '${filePath}'`);
3235

3336
if ((await exists(filePath)) === false) {
3437
return undefined;
3538
}
3639

3740
const data: AnalyticsFile = await readJsonFile(filePath);
3841
const clientId = data.analytics.clientId;
39-
// TODO:log log(`Client Id found: ${clientId}`);
42+
43+
log(`Client Id found: ${clientId}`);
4044

4145
return clientId;
4246
}
@@ -50,5 +54,5 @@ async function writeAnalyticsClientId(clientId: string): Promise<void> {
5054
},
5155
});
5256

53-
// TODO:log log(`Stored clientId ${clientId}`);
57+
log(`Stored clientId '${clientId}'`);
5458
}

0 commit comments

Comments
 (0)