Skip to content

Commit c3c86a5

Browse files
authored
chore: disable telemetry for local dev (#295)
1 parent 08cae8b commit c3c86a5

22 files changed

+48
-105
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
transform: {
44
'^.+\\.(t|j)sx?$': '@swc/jest'
55
},
6+
// Disable telemetry during testing to avoid polluting analytics
7+
testEnvironment: 'node',
8+
setupFiles: ['<rootDir>/test/setup.js'],
69
// The root of your source code, typically /src
710
// `<rootDir>` is a token Jest substitutes
811
roots: ['<rootDir>'],

src/PersistedConfig.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export interface GlobalConfig {
1212
telemetry: TelemetryConfig;
1313
hasShownTelemetryNotice: boolean;
1414
lastUpdated?: string;
15-
// Future extensibility:
16-
// updates?: UpdatePreferences;
17-
// preferences?: UserPreferences;
1815
}
1916

2017
/**
@@ -25,7 +22,7 @@ export interface TelemetryConfig {
2522
anonymousId: string;
2623
endpoint: string;
2724
trackingId: string;
28-
apiSecret?: string;
25+
apiSecret: string;
2926
}
3027

3128
const CONFIG_DIR = path.join(os.homedir(), '.the-codegen-project');

src/commands/telemetry.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,10 @@ export default class Telemetry extends Command {
8686
Logger.info('│ Telemetry Status │');
8787
Logger.info('└─────────────────────────────────────────────┘\n');
8888

89-
// Check environment variable overrides
90-
const envDisabled =
91-
process.env.CODEGEN_TELEMETRY_DISABLED === '1' ||
92-
process.env.DO_NOT_TRACK === '1';
93-
94-
if (envDisabled) {
95-
Logger.info('Status: ❌ DISABLED (via environment variable)');
96-
Logger.info('\nEnvironment variables:');
97-
if (process.env.CODEGEN_TELEMETRY_DISABLED === '1') {
98-
Logger.info(' CODEGEN_TELEMETRY_DISABLED=1');
99-
}
100-
if (process.env.DO_NOT_TRACK === '1') {
101-
Logger.info(' DO_NOT_TRACK=1');
102-
}
103-
} else {
104-
Logger.info(`Status: ${enabled ? '✅ ENABLED' : '❌ DISABLED'}`);
105-
}
106-
89+
Logger.info(`Status: ${enabled ? '✅ ENABLED' : '❌ DISABLED'}`);
10790
Logger.info(`\nConfig file: ${configPath}`);
108-
Logger.info(`Anonymous ID: ${config.anonymousId || 'Not set'}`);
109-
Logger.info(`Endpoint: ${config.endpoint || 'Not set'}`);
110-
111-
if (process.env.CODEGEN_TELEMETRY_ENDPOINT) {
112-
Logger.info(` (overridden by CODEGEN_TELEMETRY_ENDPOINT)`);
113-
}
91+
Logger.info(`Anonymous ID: ${config.anonymousId}`);
92+
Logger.info(`Endpoint: ${config.endpoint}`);
11493

11594
Logger.info('\nWhat we collect:');
11695
Logger.info(' ✓ Command usage and flags');

src/telemetry/config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import {ProjectTelemetryConfig} from '../codegen/types';
1313
* This function never throws - returns disabled config on any error.
1414
*
1515
* Priority order (highest to lowest):
16-
* 1. DO_NOT_TRACK or CODEGEN_TELEMETRY_DISABLED environment variables
17-
* 2. Environment variable overrides (endpoint, tracking ID, API secret)
18-
* 3. Project-level config (from codegen.config.js)
19-
* 4. Global config file (~/.the-codegen-project/config.json)
16+
* 1. Project-level config (from codegen.config.js)
17+
* 2. Global config file (~/.the-codegen-project/config.json)
18+
* 3. Environment variable overrides (CODEGEN_TELEMETRY_DISABLED, DO_NOT_TRACK)
2019
*
2120
* @param projectConfig - Optional project-level telemetry config from codegen.config.js
2221
* @returns Promise resolving to telemetry configuration
@@ -30,7 +29,8 @@ export async function getTelemetryConfig(
3029
...globalConfig.telemetry,
3130
...(projectConfig ?? {})
3231
};
33-
// 4. Apply environment variable overrides (highest priority for values)
32+
33+
// Apply environment variable overrides
3434
if (
3535
process.env.CODEGEN_TELEMETRY_DISABLED === '1' ||
3636
process.env.DO_NOT_TRACK
@@ -84,6 +84,7 @@ function createDisabledTelemetryConfig(): TelemetryConfig {
8484
enabled: false,
8585
anonymousId: '',
8686
endpoint: '',
87-
trackingId: ''
87+
trackingId: '',
88+
apiSecret: ''
8889
};
8990
}

test/commands/telemetry.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,31 @@ describe('telemetry command', () => {
5555
});
5656

5757
describe('environment variable handling', () => {
58-
it('should show DO_NOT_TRACK in status when set', async () => {
58+
it('should show DISABLED when DO_NOT_TRACK is set', async () => {
59+
// Save and clear global test setup
60+
const originalCodegenDisabled = process.env.CODEGEN_TELEMETRY_DISABLED;
61+
delete process.env.CODEGEN_TELEMETRY_DISABLED;
62+
5963
process.env.DO_NOT_TRACK = '1';
6064

6165
const {stdout, error} = await runCommand('telemetry status');
6266

6367
expect(error).toBeUndefined();
6468
expect(stdout).toContain('DISABLED');
65-
expect(stdout).toContain('DO_NOT_TRACK=1');
6669

6770
delete process.env.DO_NOT_TRACK;
71+
// Restore global test setup
72+
if (originalCodegenDisabled) {
73+
process.env.CODEGEN_TELEMETRY_DISABLED = originalCodegenDisabled;
74+
}
6875
});
6976

70-
it('should show CODEGEN_TELEMETRY_DISABLED in status when set', async () => {
71-
process.env.CODEGEN_TELEMETRY_DISABLED = '1';
72-
77+
it('should show DISABLED when CODEGEN_TELEMETRY_DISABLED is set', async () => {
78+
// CODEGEN_TELEMETRY_DISABLED is already set by test setup
7379
const {stdout, error} = await runCommand('telemetry status');
7480

7581
expect(error).toBeUndefined();
7682
expect(stdout).toContain('DISABLED');
77-
expect(stdout).toContain('CODEGEN_TELEMETRY_DISABLED=1');
78-
79-
delete process.env.CODEGEN_TELEMETRY_DISABLED;
8083
});
8184
});
8285

test/configs/config-all.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,5 @@ export default {
2323
language: 'typescript',
2424
protocols: ['nats']
2525
}
26-
],
27-
telemetry: {
28-
enabled: false
29-
}
26+
]
3027
};

test/configs/config-custom.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,5 @@ export default {
1818
return 'Hello World!';
1919
}
2020
}
21-
],
22-
telemetry: {
23-
enabled: false
24-
}
21+
]
2522
};

test/configs/config-implicit.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ export default {
1010
outputPath: './src/__gen__/',
1111
protocols: ['nats']
1212
}
13-
],
14-
telemetry: {
15-
enabled: false
16-
}
13+
]
1714
};

test/configs/config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ export default {
1010
// Not needed, as we can look in the AsyncAPI file, but we can overwrite it
1111
serializationType: 'json',
1212
}
13-
],
14-
telemetry: {
15-
enabled: false
16-
}
13+
]
1714
};

test/configs/config.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@
88
"outputPath": "./src/__gen__/",
99
"serializationType": "json"
1010
}
11-
],
12-
"telemetry": {
13-
"enabled": false
14-
}
11+
]
1512
}

0 commit comments

Comments
 (0)