-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update readme with examples and installation instructions (#7)
- Loading branch information
1 parent
6dd8446
commit f59edb3
Showing
4 changed files
with
87 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,58 @@ | ||
# Goodmetrics Nodejs | ||
|
||
example usage | ||
Nodejs metrics client to be used with either the goodmetrics protocol, or any open telemetry compliant protocol. | ||
Currently has a built in lightstep open telemetry client. | ||
|
||
This library is based off of the opensource [kotlin goodmetrics library](https://github.com/kvc0/goodmetrics_kotlin) | ||
|
||
## Installing | ||
```bash | ||
npm i goodmetrics-nodejs | ||
``` | ||
|
||
example usages | ||
```javascript | ||
import {Dimension, MetricsSetups} from 'goodmetrics-nodejs'; | ||
|
||
const delay = async (ms: number): Promise<void> => { | ||
return await new Promise(resolve => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, ms); | ||
}); | ||
}; | ||
|
||
const main = async () => { | ||
const metrics = | ||
// metrics setup for recording metrics inside of a lambda | ||
const lambdaMetrics = | ||
MetricsSetups.lightstepNativeOtlpButItSendsMetricsUponRecordingForLambda({ | ||
aggregationWidthMillis: 10 * 1000 * 1000, | ||
aggregationWidthMillis: 10 * 1000, | ||
lightstepAccessToken: '<your lightstep api key>', | ||
prescientDimensions: new Map<string, Dimension>(), | ||
resourceDimensions: new Map<string, Dimension>(), | ||
}); | ||
|
||
await metrics.unaryMetricsFactory.record( | ||
await lambdaMetrics.unaryMetricsFactory.record( | ||
{name: 'test'}, | ||
async metrics => { | ||
console.info('inside metrics block'); | ||
metrics.measure('runs', 1); | ||
await delay(100); | ||
// await some async task | ||
metrics.dimension('result', 'success'); | ||
} | ||
); | ||
|
||
// using goodmetrics | ||
const goodmetrics = MetricsSetups.goodMetrics(); | ||
await goodmetrics.unaryMetricsFactory.record({name: 'unary'}, metrics => { | ||
metrics.dimension('is_local', true); | ||
metrics.measure('runs', 1); | ||
}); | ||
await goodmetrics.preaggregatedMetricsFactory.record( | ||
{name: 'preaggregated'}, | ||
metrics => { | ||
metrics.measure('w00t', 1); | ||
} | ||
); | ||
}; | ||
|
||
main().finally(); | ||
``` | ||
|
||
## Protos | ||
- [open telemetry client protos](https://github.com/bruuuuuuuce/otlp-generated) | ||
- [goodmetrics client protos](https://github.com/bruuuuuuuce/goodmetrics-generated) | ||
|
||
## Goodmetrics | ||
More information about the goodmetrics protocol can be found [here](https://github.com/kvc0/goodmetrics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters