Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/go-slog/otelslog
Handler attaching OpenTelemetry trace and resource details to logs
https://github.com/go-slog/otelslog
hacktoberfest slog
Last synced: 2 months ago
JSON representation
Handler attaching OpenTelemetry trace and resource details to logs
- Host: GitHub
- URL: https://github.com/go-slog/otelslog
- Owner: go-slog
- License: mit
- Created: 2023-09-14T13:01:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-20T19:45:57.000Z (3 months ago)
- Last Synced: 2024-10-22T09:32:16.550Z (3 months ago)
- Topics: hacktoberfest, slog
- Language: Go
- Homepage:
- Size: 114 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-slog - otelslog
README
# OpenTelemetry handler
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/go-slog/otelslog/ci.yaml?style=flat-square)](https://github.com/go-slog/otelslog/actions/workflows/ci.yaml)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/mod/github.com/go-slog/otelslog)
![Go Version](https://img.shields.io/badge/go%20version-%3E=1.22-61CFDD.svg?style=flat-square)
[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org)**[log/slog](https://pkg.go.dev/log/slog) handler attaching OpenTelemetry trace details to logs.**
## Installation
```shell
go get github.com/go-slog/otelslog
```## Usage
Wrap an existing handler:
```go
import(
"log/slog""github.com/go-slog/otelslog"
)var handler slog.Handler
// Set up your handler
// handler = ...// Wrap Handler
handler = otelslog.NewHandler(handler)logger := slog.New(handler)
// Call logger with a context
logger.InfoContext(ctx, "hello world")
// Output: level=INFO msg="hello world" trace_id=74726163655f69645f74657374313233 span_id=7370616e5f696431
```Use it as a middleware in [slogmulti.Pipe](https://pkg.go.dev/github.com/samber/slog-multi#Pipe):
```go
import (
"github.com/go-slog/otelslog"
"github.com/samber/slog-multi"
)handler = slogmulti.Pipe(otelslog.Middleware()).Handler(handler)
// Set p logger
// ...
```## Development
Run tests:
```shell
go test -race -v ./...
```Run linter:
```shell
golangci-lint run
```## License
The project is licensed under the [MIT License](LICENSE).