Provides an easy way to create OpenTelemetry spans with structured attributes.
go get github.com/ebi-yade/spans
package main
import (
"github.com/ebi-yade/spans"
"go.opentelemetry.io/otel"
)
type HTTPContext struct {
Status int `otel:"status_code"` // you can explicitly specify the key suffix
Method string `otel:"method"`
Path string // => key suffix is "path"
RemoteAddr string // => key suffix is "remote_addr"
AuthHeader string `otel:"-"` // you also can ignore the field
Cookie string `otel:",omitempty"` // you can ignore the field if it is empty
}
func main() {
httpCtx := HTTPContext{
Status: 200,
Method: "GET",
Path: "/",
AuthHeader: "Bearer xxx",
Cookie: "",
}
ctx, spans := otel.Tracer("handler").Start("foo", spans.WithAttrs(
spans.ObjectAttr("http", httpCtx),
))
}
LICENSE: MIT
The prototype of this library was created by @mashiike.