Skip to content

Commit

Permalink
Make some adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr committed Apr 30, 2024
1 parent 8d27ec3 commit c28672e
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,56 @@ It aids in comprehending how AsyncAPI tools are used and adopted, facilitating o
## Installation
Requires NodeJS v18 or greater.
```bash
npm install @smoya/@asyncapi-adoption-metrics
yarn add @smoya/@asyncapi-adoption-metrics
npm install @smoya/asyncapi-adoption-metrics
yarn add @smoya/asyncapi-adoption-metrics
```

## Usage
The package exposes several classes, from which we can remark:
- class `Metric`:
Used to create an object containing all the properties needed to identify the metrics collected. These properties are:
```ts
```ts
name: string;
type: MetricType;
value: any;
metadata: { [key: string]: any };
```
```

- class `Recorder`:
Contains all the functions needed to record the different metrics we collect, like:
- `asyncapi_adoption.action.invoked`:
With this metric we are tracking any action started (but not finished) in a tool. For example, a command that got executed on the [CLI](https://github.com/asyncapi/cli/) but didn't finish yet. We just want to know which commands are used, regardless they have failed or succeeded.
```ts
async recordActionInvoked(actionName: string, metadata: MetricMetadata = {}) {
```ts
async recordActionInvoked(actionName: string, metadata: MetricMetadata = {}) {
metadata['action'] = actionName;
this.record(new Metric('action.invoked', MetricType.Counter, 1, metadata));
}
```
Example where this function is used:
```ts
```
Example where this function is used:
```ts
async init(): Promise<void> {
await super.init();
const commandName : string = this.id || '';
await this.recordActionInvoked(commandName, this.metricsMetadata);
}
```
```

- `asyncapi_adoption.action.finished`:
With this metric we are tracking the action executed once it has already finished, carrying the result of the execution and some metadata.
```ts
```ts
async recordActionFinished(actionName: string, metadata: MetricMetadata = {}) {
metadata['action'] = actionName;
this.record(new Metric('action.finished', MetricType.Counter, 1, metadata));
}
```
Example where this function is used:
```ts
```
Example where this function is used:
```ts
async finally(error: Error | undefined): Promise<any> {
await super.finally(error);
this.metricsMetadata['success'] = error === undefined;
await this.recordActionFinished(this.id as string, this.metricsMetadata, this.specFile?.text());
}
```
```

Utils exposed by the library to operate mainly with the `Sink` interface and the metadata retrieved from the asyncapi files:
```ts
Expand Down

0 comments on commit c28672e

Please sign in to comment.