https://github.com/lucavallin/gotel
A Go wrapper for OpenTelemetry.
https://github.com/lucavallin/gotel
golang opentelemetry otel
Last synced: 3 months ago
JSON representation
A Go wrapper for OpenTelemetry.
- Host: GitHub
- URL: https://github.com/lucavallin/gotel
- Owner: lucavallin
- License: mit
- Created: 2025-02-05T19:58:48.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-06-30T13:49:02.000Z (3 months ago)
- Last Synced: 2025-07-15T06:47:41.726Z (3 months ago)
- Topics: golang, opentelemetry, otel
- Language: Go
- Homepage: https://lucavall.in
- Size: 131 KB
- Stars: 37
- Watchers: 2
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gotel
`gotel` is a Go library for handy observability. It is a wrapper around the OpenTelemetry Go library that provides a simplified API for instrumenting your Go applications.
`gotel` offers the following features:
- A simplified API for instrumenting your Go applications: log messages, metrics, and traces.
- OpenTelemetry exporters via OTLP gRPC
- A configuration struct that can be loaded from environment variables.
- A no-op telemetry provider that can be used as a fallback when the exporter fails.## Installation
To install `gotel`, use `go get`:
```sh
go get github.com/lucavallin/gotel
```## Usage
To use `gotel`, you need to create an instance `gotel.Telemetry` and use it to instrument your application. Here is an example:
```go
package mainimport (
"context"
"fmt"
"os""github.com/lucavallin/gotel"
)func main() {
ctx := context.Background()telemConfig, err := gotel.NewConfigFromEnv()
if err != nil {
fmt.Println("failed to load telemetry config")
os.Exit(1)
}// Initialize telemetry. If the exporter fails, fallback to nop.
var telem gotel.TelemetryProvider
telem, err = gotel.NewTelemetry(ctx, telemConfig)
if err != nil {
fmt.Println("failed to create telemetry, falling back to no-op telemetry")
telem, _ = gotel.NewNoopTelemetry(telemConfig)
}
defer telem.Shutdown(ctx)telem.LogInfo("telemetry initialized")
}
````gotel` also provides middleware for `gin`, which can be used to instrument your web applications. Here is an example:
```go
...
r := gin.New()
r.Use(telem.LogRequest())
r.Use(telem.MeterRequestDuration())
r.Use(telem.MeterRequestsInFlight())
...
```## Development
The repository contains a `justfile` with useful commands for development. To see the list of available commands, run `just`:
```sh
❯ just
Available recipes:
build # Build the gotel package
default # Default recipe
deps # Install dependencies
gen-mocks # Generate mocks
help # Show help message
lint *ARGS # Run linter (--fix to fix issues)
test json="" # Run tests (--json to output coverage in json format)
```## Contributing
Contributions are welcome! For bug reports, feature requests, or questions, please [open an issue](https://github.com/lucavallin/gotel/issues/new). For pull requests, fork the repository and submit a PR.