Skip to content

Commit

Permalink
feat: make analytics config file's path configurable (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr authored Jun 4, 2024
1 parent 38eb04c commit 0909db9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/metrics_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ We are making use of [New Relic API](https://docs.newrelic.com/docs/apis/intro-a

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

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:
````
ASYNCAPI_METRICS_CONFIG_PATH=/tmp/.asyncapi-analytics asyncapi config analytics --status
````

## How to disable tracking
To disable tracking, please run the following command:
`asyncapi config analytics --disable`
Expand Down
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default abstract class extends Command {

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

if (!existsSync(analyticsConfigFile)) {
await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' });
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Analytics extends Command {

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

try {
const analyticsConfigFileContent = JSON.parse(await readFile(resolve(analyticsConfigFile), { encoding: 'utf8' }));
Expand All @@ -45,7 +45,7 @@ export default class Analytics extends Command {
} catch (e: any) {
switch (e.code) {
case 'ENOENT':
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.`);
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.`);
break;
case 'EEXIST':
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.`);
Expand Down

0 comments on commit 0909db9

Please sign in to comment.