Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 982 Bytes

README.md

File metadata and controls

50 lines (37 loc) · 982 Bytes

spans

Provides an easy way to create OpenTelemetry spans with structured attributes.

Installation

go get github.com/ebi-yade/spans

Usage

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

Acknowledgements

The prototype of this library was created by @mashiike.