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 message to warn users about metrics collection #6

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
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
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);
}

Loading