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

docs: metrics collection markdown file #9

Merged
49 changes: 49 additions & 0 deletions docs/metrics_collection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Metrics collection guideline

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.

Even though metrics collection is enabled by default, you can always [disable tracking](#how-to-disable-tracking) if you want to.

## What we collect
We are collecting the following metrics:

- `asyncapi_adoption.action.invoked`:
With this metric we are tracking the command executed on the CLI as soon as the command is invoked, so it has already been executed but not finished yet. We just want to know which commands are used, regardless they have failed or succeeded.

Example of the data collected by this metric when the `validate` command has been executed:
```
asyncapi_adoption.action.invoked COUNTER { action: 'validate' } 1
```

- `asyncapi_adoption.action.finished`:
This metric tracks the command executed once it has already finished, carrying the result of the execution and some metadata based on the AsyncAPI document in place.

Example for `validate` command successfully executed and finished:
```
asyncapi_adoption.action.finished COUNTER {
validation_result: 'valid',
success: true,
asyncapi_version: '2.6.0',
asyncapi_servers: 2,
asyncapi_channels: 4,
asyncapi_messages: 3,
asyncapi_operations_send: 3,
asyncapi_operations_receive: 1,
asyncapi_schemas: 52,
action: 'validate'
} 1
```

## Where the data is stored
We are making use of [New Relic API](https://docs.newrelic.com/docs/apis/intro-apis/introduction-new-relic-apis/#rest-api) to send the metrics collected to _New Relic_ servers, where they are stored, and finally visualized on the AsyncAPI website.

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

## How to disable tracking
peter-rr marked this conversation as resolved.
Show resolved Hide resolved
To disable tracking, please run the following command:
`asyncapi config analytics --disable`

Once disabled, if you want to enable tracking back again then run:
`asyncapi config analytics`

Remember that keeping this tracking enabled will help AsyncAPI community to provide better specifications and tools in the future.
7 changes: 3 additions & 4 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
await this.recordActionFinished(this.id as string, this.metricsMetadata, this.specFile?.text());
}

async recorderFromEnv(prefix: string): Promise<Recorder> {

Check warning on line 83 in src/base.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
let sink: Sink = new DiscardSink();
const analyticsConfigFile = join(process.cwd(), '.asyncapi-analytics');

Expand All @@ -105,18 +105,17 @@
case 'production':
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
sink = new NewRelicSink(process.env.ASYNCAPI_METRICS_NEWRELIC_KEY || 'eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
const analyticsConfigFileContent = JSON.parse(readFileSync(resolve(analyticsConfigFile), 'utf-8'));

Check failure on line 108 in src/base.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Unexpected lexical declaration in case block

if (existsSync(analyticsConfigFile) && (analyticsConfigFileContent.infoMessageShown === 'false')) {
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, please run the following command :\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking again then run:\n asyncapi config analytics');
this.log('\nAsyncAPI 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, please run the following command:\n asyncapi config analytics --disable\n\nOnce disabled, if you want to enable tracking back again then run:\n asyncapi config analytics');
analyticsConfigFileContent.infoMessageShown = 'true';
await writeFile(analyticsConfigFile, JSON.stringify(analyticsConfigFileContent), { encoding: 'utf8' });
}
break;
}
}

return new Recorder(prefix, sink);
}
}

}

Check failure on line 121 in src/base.ts

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Newline required at end of file but not found
Loading