https://github.com/bool64/stats
Contextualized Stats Tracker for Go
https://github.com/bool64/stats
Last synced: about 2 months ago
JSON representation
Contextualized Stats Tracker for Go
- Host: GitHub
- URL: https://github.com/bool64/stats
- Owner: bool64
- License: mit
- Created: 2020-08-10T19:19:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-12-29T10:55:14.000Z (about 4 years ago)
- Last Synced: 2024-06-21T08:28:26.347Z (almost 2 years ago)
- Language: Go
- Size: 56.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Contextualized Stats Tracker for Go
This library provides context-driven stats tracker.
[](https://github.com/bool64/stats/actions?query=branch%3Amaster+workflow%3Atest)
[](https://codecov.io/gh/bool64/stats)
[](https://pkg.go.dev/github.com/bool64/stats)
[](https://wakatime.com/badge/github/bool64/stats)


## Features
* Loosely coupled with underlying implementation.
* Context-driven labels control.
* Zero allocation implementation for [Prometheus client](https://github.com/bool64/prom-stats).
* A simple interface with variadic number of key-value pairs for labels.
* Easily mockable interface free from 3rd party dependencies.
## Example
```go
// Bring your own Prometheus registry.
registry := prometheus.NewRegistry()
tr := prom.Tracker{
Registry: registry,
}
// Add custom Prometheus configuration where necessary.
tr.DeclareHistogram("my_latency_seconds", prometheus.HistogramOpts{
Buckets: []float64{1e-4, 1e-3, 1e-2, 1e-1, 1, 10, 100},
})
ctx := context.Background()
// Add labels to context.
ctx = stats.AddKeysAndValues(ctx, "ctx-label", "ctx-value0")
// Override label values.
ctx = stats.AddKeysAndValues(ctx, "ctx-label", "ctx-value1")
// Collect stats with last mile labels.
tr.Add(ctx, "my_count", 1,
"some-label", "some-value",
)
tr.Add(ctx, "my_latency_seconds", 1.23)
tr.Set(ctx, "temperature", 33.3)
```
## Versioning
This project adheres to [Semantic Versioning](https://semver.org/#semantic-versioning-200).
Before version `1.0.0`, breaking changes are tagged with `MINOR` bump, features and fixes are tagged with `PATCH` bump.
After version `1.0.0`, breaking changes are tagged with `MAJOR` bump.