https://github.com/cyprinus12138/otelgin
OpenTelemetry trace & metric instrumentation as Gin Middleware
https://github.com/cyprinus12138/otelgin
gin gin-gonic gin-middleware http http-server metrics opentelemetry-go tracer
Last synced: 4 months ago
JSON representation
OpenTelemetry trace & metric instrumentation as Gin Middleware
- Host: GitHub
- URL: https://github.com/cyprinus12138/otelgin
- Owner: Cyprinus12138
- License: apache-2.0
- Created: 2024-03-26T17:41:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T07:34:01.000Z (over 1 year ago)
- Last Synced: 2025-07-04T00:03:47.025Z (4 months ago)
- Topics: gin, gin-gonic, gin-middleware, http, http-server, metrics, opentelemetry-go, tracer
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Go OpenTelemetry Gonic-gin Trace & Metrics Instrumentation
[](https://github.com/Cyprinus12138/otelgin/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/Cyprinus12138/otelgin)
[](https://pkg.go.dev/mod/github.com/Cyprinus12138/otelgin)It is an OpenTelemetry (OTel) trace & metric instrumentation for http server implement with Gonic-gin. [Gin Web Framework](https://gin-gonic.com/).
## Install
```bash
$ go get github.com/Cyprinus12138/otelgin
```## Usage
Metrics are reported based on [Semantic Conventions for HTTP Metrics](https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#http-server) :
1. `http.server.request.duration`
2. `http.server.request.body.size`
3. `http.server.response.body.size`
4. `http.server.active_requests`### Plugin as a middleware
[Example Server](https://github.com/Cyprinus12138/otelgin/blob/main/example/server.go)
```go
r := gin.New()
r.Use(otelgin.Middleware("my-server"))
```