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

feat: Add Telemetry logic #605

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4efc5c8
Add telemetry helper and state function
michielmulders Feb 5, 2025
c939ee2
Update tests with new telemetry parameter
michielmulders Feb 5, 2025
510684f
Update telemetry state helper
michielmulders Feb 5, 2025
806d9ef
Add example record command function for account list
michielmulders Feb 5, 2025
bb4f60c
Add telemetry enable and disable command
michielmulders Feb 5, 2025
65df54e
Fix bug telemetry status check
michielmulders Feb 5, 2025
0a015b6
Add telemetry to all commands when enabled
michielmulders Feb 5, 2025
d14ef65
Add docs for telemetry
michielmulders Feb 5, 2025
8c88bf4
Add telemetry option to setup command
michielmulders Feb 5, 2025
f76f02d
Add docs for setup commands on telemetry
michielmulders Feb 5, 2025
9c96902
Add telemetry to all commands and add endpoint
michielmulders Feb 11, 2025
5abfcdc
Update example state in docs
michielmulders Feb 11, 2025
6fc044b
Add version to telemetry request
michielmulders Feb 11, 2025
f182588
Add telemetry headers
michielmulders Feb 12, 2025
8044b65
Add info about uuid in readme
michielmulders Feb 12, 2025
e85a677
Dynamically load telemetry server
michielmulders Feb 14, 2025
bd81a8e
Reset state to default
michielmulders Feb 14, 2025
3121195
Update version to 0.2.1
michielmulders Feb 14, 2025
1ae72b0
Merge remote-tracking branch 'upstream/main' into feat-telemetry-comm…
michielmulders Feb 14, 2025
62388ce
Handle --telemetry flag
michielmulders Feb 14, 2025
dcec490
Fix network in state
michielmulders Feb 14, 2025
74758f4
Fix async e2e tests
michielmulders Feb 14, 2025
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
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A key advantage of the Hedera CLI Tool is its potential to enhance your workflow
- [Video Guide](#video-guide)
- [Commands](#commands)
- [Setup Commands](#setup-commands)
- [Telemetry Commands](#telemetry-commands)
- [Network Commands](#network-commands)
- [Wait Command](#wait-command)
- [Account Commands](#account-commands)
Expand Down Expand Up @@ -99,10 +100,10 @@ LOCALNET_OPERATOR_ID=
LOCALNET_OPERATOR_KEY=
```

Next, set up the CLI tool with the command:
Next, set up the CLI tool with the command. **The `--telemetry` flag is optional and enables telemetry. By default, telemetry is disabled. Hedera collects anonymous data to improve the CLI tool. For example, it records the command name, not the parameters or any other sensitive information. If you don't want us to collect telemetry data, run the command without the `--telemetry` flag.**

```sh
node dist/hedera-cli.js setup init
node dist/hedera-cli.js setup init --telemetry
```

> **Note.** You can set a custom absolute path for your `.env` file by using the `--path` flag. For example, `node dist/hedera-cli.js setup init --path /Users/myUser/projects/cli/.env`. More information can be found in the [setup command](#setup-commands) section below.
Expand Down Expand Up @@ -190,6 +191,7 @@ Learn how to use the Hedera CLI Tool by watching the video below.
Let's explore the different commands, their options, and outputs.

- [Setup Commands](#setup-commands): Instantiate or reset the Hedera CLI tool
- [Telemetry Commands](#telemetry-commands): Enable or disable telemetry
- [Network Commands](#network-commands): Switch Hedera networks
- [Wait Command](#wait-command): Wait for a specified amount of seconds
- [Account Commands](#account-commands): Create and manage accounts
Expand Down Expand Up @@ -225,11 +227,12 @@ setup reload
Sets up the CLI with the operator key and ID.

```sh
hcli setup init [--path <path>]
hcli setup init [--telemetry] [--path <path>]
```

Flags:

- **Telemetry:** (optional) Enables telemetry. By default disabled. Hedera collects anonymous data to improve the CLI tool. For example, it records the command name, not the parameters or any other sensitive information.
- **Path:** (optional) Sets a custom absolute path for your `.env` file. Defaults to your homedir, e.g. `~/.hedera/.env`.

When executed, the setup command performs several key functions:
Expand All @@ -245,12 +248,41 @@ Once the localnet, previewnet, testnet, and mainnet operator key and ID are vali
Reload the operator key and ID from the `.env` file. This command is useful when you add new networks to your `.env` file and want to update the state, so you can use the new networks.

```sh
hcli setup reload [--path <path>]
hcli setup reload [--telemetry]
```

Flags:

- **Path:** (optional) Sets a custom absolute path for your `.env` file. Defaults to your homedir, e.g. `~/.hedera/.env`.
- **Telemetry:** (optional) Enables telemetry. By default disabled. Hedera collects anonymous data to improve the CLI tool. For example, it records the command name, not the parameters or any other sensitive information.

## Telemetry Commands

### Overview

The telemetry command in the Hedera CLI tool is designed to enable or disable telemetry. This feature allows users to opt-in or opt-out of telemetry data collection. Hedera **anonymizes data** and only records the command name, not the parameters or any other sensitive information. For example, it records `account create` but not the account alias or ID. The data is used to improve the CLI tool and provide better features and functionality, by trying to understand how users use the CLI. However, the CLI tool uses a UUID to identify the user, so no personal information is collected. This allows us to better understand how users interact with the CLI tool.

```sh
telemetry enable
telemetry disable
```

#### Usage

**1. Enable telemetry:**

This command enables telemetry and sets the `telemetry` variable in the state to `1`.

```sh
hcli telemetry enable
```

**2. Disable telemetry:**

This command disables telemetry and sets the `telemetry` variable in the state to `0`.

```sh
hcli telemetry disable
```

## Network Commands

Expand Down Expand Up @@ -1001,18 +1033,26 @@ Here's an example state:
```json
{
"network": "testnet",
"mirrorNodeLocalnet": "http://localhost:5551/api/v1",
"mirrorNodePreviewnet": "https://previewnet.mirrornode.hedera.com/api/v1",
"mirrorNodeTestnet": "https://testnet.mirrornode.hedera.com/api/v1",
"mirrorNodeMainnet": "https://mainnet.mirrornode.hedera.com/api/v1",
"telemetryServer": "http://localhost:3000/track",
"localNodeAddress": "127.0.0.1:50211",
"localNodeAccountId": "0.0.3",
"localNodeMirrorAddressGRPC": "127.0.0.1:5600",
"testnetOperatorKey": "",
"testnetOperatorId": "",
"mainnetOperatorKey": "",
"mainnetOperatorId": "",
"previewnetOperatorId": "",
"previewnetOperatorKey": "",
"telemetry": 0,
"recording": 0,
"recordingScriptName": "",
"scriptExecution": 0,
"scriptExecutionName": "",
"uuid": "",
"accounts": {
"bob": {
"network": "testnet",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/account/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("account view command", () => {
commands.accountCommands(program);

// Act
await program.parse([
await program.parseAsync([
"node",
"hedera-cli.ts",
"account",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/network/use.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('network use command', () => {
commands.networkCommands(program);

// Act
program.parse(['node', 'hedera-cli.ts', 'network', 'use', 'mainnet']);
await program.parseAsync(['node', 'hedera-cli.ts', 'network', 'use', 'mainnet']);

// Assert
expect(stateControllerSpy).toHaveBeenCalledWith('network', 'mainnet');
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/topic/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("topic list command", () => {
commands.topicCommands(program);

// Act
program.parse(["node", "hedera-cli.ts", "topic", "list"]);
await program.parseAsync(["node", "hedera-cli.ts", "topic", "list"]);

// Assert
expect(logSpy).toHaveBeenCalledWith(`Topics:`);
Expand Down
12 changes: 6 additions & 6 deletions __tests__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('End to end tests', () => {
commands.networkCommands(program);

// Act
program.parse(['node', 'hedera-cli.ts', 'network', 'use', 'localnet']);
await program.parseAsync(['node', 'hedera-cli.ts', 'network', 'use', 'localnet']);

// Assert
const network = stateController.get('network');
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('End to end tests', () => {
const backupName = 'e2e';

// Act
program.parse([
await program.parseAsync([
'node',
'hedera-cli.ts',
'backup',
Expand All @@ -144,7 +144,7 @@ describe('End to end tests', () => {
commands.accountCommands(program);

// Act
program.parse([
await program.parseAsync([
'node',
'hedera-cli.ts',
'account',
Expand All @@ -161,7 +161,7 @@ describe('End to end tests', () => {
commands.backupCommands(program);

// Act
program.parse([
await program.parseAsync([
'node',
'hedera-cli.ts',
'backup',
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('End to end tests', () => {

// Arrange: Delete script and verify it is deleted in state file
// Act
program.parse([
await program.parseAsync([
'node',
'hedera-cli.ts',
'script',
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('End to end tests', () => {
commands.networkCommands(program);

// Act
program.parse(['node', 'hedera-cli.ts', 'network', 'use', 'localnet']);
await program.parseAsync(['node', 'hedera-cli.ts', 'network', 'use', 'localnet']);

// Assert
const network = stateController.get('network');
Expand Down
3 changes: 3 additions & 0 deletions __tests__/helpers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const baseState: State = {
mirrorNodePreviewnet: 'https://previewnet.mirrornode.hedera.com/api/v1',
mirrorNodeTestnet: 'https://testnet.mirrornode.hedera.com/api/v1',
mirrorNodeMainnet: 'https://mainnet.mirrornode.hedera.com/api/v1',
telemetryServer: "https://hedera-cli-telemetry.onrender.com/track",
telemetry: 0,
recording: 0,
recordingScriptName: '',
scriptExecution: 0,
Expand All @@ -33,6 +35,7 @@ export const baseState: State = {
localNodeAddress: '127.0.0.1:50211',
localNodeAccountId: '0.0.3',
localNodeMirrorAddressGRPC: '127.0.0.1:5600',
uuid: '',
};

/* accounts */
Expand Down
Loading