Skip to content

ebi-yade/spans

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%