https://github.com/mralias/bind
Bind OpenTelemetry metric instruments to attributes
https://github.com/mralias/bind
Last synced: 11 months ago
JSON representation
Bind OpenTelemetry metric instruments to attributes
- Host: GitHub
- URL: https://github.com/mralias/bind
- Owner: MrAlias
- License: apache-2.0
- Created: 2025-08-19T20:53:59.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-09-07T14:50:07.000Z (11 months ago)
- Last Synced: 2025-09-07T16:31:18.577Z (11 months ago)
- Language: Go
- Size: 74.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# bind
[](https://github.com/MrAlias/bind/actions/workflows/ci.yml)
[](https://codecov.io/gh/MrAlias/bind)
[](https://goreportcard.com/report/github.com/MrAlias/bind)
[](https://pkg.go.dev/github.com/MrAlias/bind)
[](https://github.com/MrAlias/bind/releases)
[](https://opensource.org/licenses/Apache-2.0)
`bind` is a Go library for binding [OpenTelemetry] synchronous metric instruments to attributes.
This can greatly improve performance for instrumentation when measurements are only recorded for known static attribute sets.
## Installation
```sh
go get github.com/MrAlias/bind
```
## Usage
```go
import (
"github.com/MrAlias/bind"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
// Example: Bind attributes to a Float64Counter
counter := bind.Float64Counter(myCounter, attribute.String("user", "Alice"))
// Measured with {"user": "Alice"}
counter.Add(ctx, 1.0)
// Measured with {"user": "Alice", "id: 1}
counter.Add(ctx, 2.0, metric.WithAttributes(attribute.Int("id", 1)))
// Bind additional attributes to the counter.
counter = bind.Float64Counter(counter, attribute.Bool("admin", true))
// Measure with {"user": "Alice", "admin": true}
counter.Add(ctx, -1.0)
// Unwrap to get the underlying instrument (i.e. myCounter) and attributes
// (i.e. {"user": "Alice", "admin": true})
base, attrs := bind.Unwrap(counter)
```
See [GoDoc] for full API documentation and examples.
## Contributing
Contributions are welcome!
Please see our [Contributing Guide](CONTRIBUTING.md) for details.
## License
Licensed under the [Apache 2.0 License](LICENSE).
[OpenTelemetry]: opentelemetry.io
[GoDoc]: https://pkg.go.dev/github.com/MrAlias/bind