Skip to content

Commit 0909db9

Browse files
authored
feat: make analytics config file's path configurable (#1451)
1 parent 38eb04c commit 0909db9

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

docs/metrics_collection.md

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ We are making use of [New Relic API](https://docs.newrelic.com/docs/apis/intro-a
3939

4040
Metrics won't be collected in CI environments, or when the "CI" env variable is set up to "true".
4141

42+
The analytics config file will be store by default at your home directory. In case you prefer to change the file path then you should set the `ASYNCAPI_METRICS_CONFIG_PATH` env var to any specific path value when running any command. For instance:
43+
````
44+
ASYNCAPI_METRICS_CONFIG_PATH=/tmp/.asyncapi-analytics asyncapi config analytics --status
45+
````
46+
4247
## How to disable tracking
4348
To disable tracking, please run the following command:
4449
`asyncapi config analytics --disable`

src/base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default abstract class extends Command {
9898

9999
async recorderFromEnv(prefix: string): Promise<Recorder> {
100100
let sink: Sink = new DiscardSink();
101-
const analyticsConfigFile = join(homedir(), '.asyncapi-analytics');
101+
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH || join(homedir(), '.asyncapi-analytics');
102102

103103
if (!existsSync(analyticsConfigFile)) {
104104
await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' });

src/commands/config/analytics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class Analytics extends Command {
1818

1919
async run() {
2020
const { flags } = await this.parse(Analytics);
21-
const analyticsConfigFile = join(homedir(), '.asyncapi-analytics');
21+
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH || join(homedir(), '.asyncapi-analytics');
2222

2323
try {
2424
const analyticsConfigFileContent = JSON.parse(await readFile(resolve(analyticsConfigFile), { encoding: 'utf8' }));
@@ -45,7 +45,7 @@ export default class Analytics extends Command {
4545
} catch (e: any) {
4646
switch (e.code) {
4747
case 'ENOENT':
48-
this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in your user's home directory ("${homedir()}") but the file could not be found.`);
48+
this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in in the path "${analyticsConfigFile}" but the file could not be found.`);
4949
break;
5050
case 'EEXIST':
5151
this.error(`Unable to update the analytics configuration file. We tried to update your ".asyncapi-analytics" file in the path "${analyticsConfigFile}" but the file does not exist.`);

0 commit comments

Comments
 (0)