Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dgzlopes/minit-go
A minimal tracing library for Go
https://github.com/dgzlopes/minit-go
go opentelemetry tracing
Last synced: 25 days ago
JSON representation
A minimal tracing library for Go
- Host: GitHub
- URL: https://github.com/dgzlopes/minit-go
- Owner: dgzlopes
- License: apache-2.0
- Created: 2023-11-02T19:43:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-03T18:48:14.000Z (about 1 year ago)
- Last Synced: 2024-12-09T19:56:59.906Z (about 1 month ago)
- Topics: go, opentelemetry, tracing
- Language: Go
- Homepage:
- Size: 153 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# minit-go [![Go Reference](https://pkg.go.dev/badge/github.com/dgzlopes/minit.svg)](https://pkg.go.dev/github.com/dgzlopes/minit)
> **NOTE:** You don't want to use this library. You should probably be using [OpenTelemetry]([https://opentelemetry.io/](https://opentelemetry.io/docs/instrumentation/go/)).
Minit is a minimal tracing library for Go.
When I say minimal, I mean it: It's ~300 lines of code and has no dependencies*.
As you can expect, it has many limitations:
- Only works with OpenTelemetry HTTP-compatible collectors.
- Doesn't support sampling.
- No helpers to use in distributed/microservices setups.Truth to be said: Because it's so tiny, it's easy to understand and modify.
It's also easy to use in simple, non-distributed applications.
**Instead of [using the OTEL Protobufs](https://gist.github.com/dgzlopes/831a393c8071193b50165df9b72d3653), we moved the important bits to Go structs (check `pkg/otel`).*
## Installation
```bash
go get github.com/dgzlopes/minit
```## Usage
```go
package mainimport (
"context"
"time""github.com/dgzlopes/minit"
)type App struct {
tracing *minit.TracingClient
}func main() {
tracing := minit.NewTracingClient("http://localhost:4318/v1/traces")
defer tracing.Export()app := App{
tracing: tracing,
}_, ctx := tracing.StartTrace(context.Background())
root, ctx := tracing.StartSpan(ctx, "hello!")
root.Service.Name = "my-app"
defer root.Finish()// Do something...
app.WithChildSpan(ctx)
}func (a *App) WithChildSpan(ctx context.Context) {
span, ctx := a.tracing.StartSpan(ctx, "with_child_span")
defer span.Finish()// Do something...
child, _ := a.tracing.StartSpan(ctx, "child")
defer child.Finish()// Do something else...
if (true) {
child.MarkAsFailed()
}
}
```