Skip to content

Commit

Permalink
feat: add message to warn users about metrics collection (asyncapi#6)
Browse files Browse the repository at this point in the history
* Add message to warn users about metrics collection

* Improve warning message

* Apply changes to use the logger configured in oclif
  • Loading branch information
peter-rr authored Dec 18, 2023
1 parent e855ab3 commit e6f4917
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DiscardSink implements Sink {
}

export default abstract class extends Command {
recorder = recorderFromEnv('asyncapi_adoption');
recorder = this.recorderFromEnv('asyncapi_adoption');
parser = new Parser();

async catch(err: Error & { exitCode?: number; }): Promise<any> {
Expand Down Expand Up @@ -68,25 +68,27 @@ export default abstract class extends Command {
const commandName : string = this.id || '';
await this.recordActionInvoked(commandName);
}
}

function recorderFromEnv(prefix: string): Recorder {
let sink: Sink = new DiscardSink();
if (process.env.ASYNCAPI_METRICS !== 'false') {
switch (process.env.NODE_ENV) {
case 'development':
// NODE_ENV set to `development` in bin/run
if (!process.env.TEST) {
// Do not pollute stdout when running tests
sink = new StdOutSink();
recorderFromEnv(prefix: string): Recorder {
let sink: Sink = new DiscardSink();
if (process.env.ASYNCAPI_METRICS !== 'false') {
switch (process.env.NODE_ENV) {
case 'development':
// NODE_ENV set to `development` in bin/run
if (!process.env.TEST) {
// Do not pollute stdout when running tests
sink = new StdOutSink();
}
break;
case 'production':
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
sink = new NewRelicSink('eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
this.warn('AsyncAPI anonymously tracks command executions to improve the specification and tools, ensuring no sensitive data reaches our servers. It aids in comprehending how AsyncAPI tools are used and adopted, facilitating ongoing improvements to our specifications and tools.\n\nTo disable tracking, set the "ASYNCAPI_METRICS" env variable to "false" when executing the command. For instance:\n\nASYNCAPI_METRICS=false asyncapi validate spec_file.yaml');
break;
}
break;
case 'production':
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
sink = new NewRelicSink('eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
break;
}

return new Recorder(prefix, sink);
}

return new Recorder(prefix, sink);
}

0 comments on commit e6f4917

Please sign in to comment.