spans

package module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 5 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAttrs

func SetAttrs(span trace.Span, attrs ...KeyValue)

SetAttrs can be used in place of span.SetAttributes to set multiple attributes on a span after it has been created.

func WithAttrs

func WithAttrs(attrs ...KeyValue) trace.SpanStartEventOption

WithAttrs can be used in place of trace.WithAttributes to set multiple attributes on a span at the time of creation.

Types

type KeyValue

type KeyValue struct {
	// contains filtered or unexported fields
}

func BoolAttr

func BoolAttr(k string, v bool) KeyValue

BoolAttr is comparable to attribute.Bool.

func BoolSliceAttr

func BoolSliceAttr(k string, v []bool) KeyValue

BoolSliceAttr is comparable to attribute.BoolSlice.

func Float64Attr

func Float64Attr(k string, v float64) KeyValue

Float64Attr is comparable to attribute.Float64.

func Float64SliceAttr

func Float64SliceAttr(k string, v []float64) KeyValue

Float64SliceAttr is comparable to attribute.Float64Slice.

func Int64Attr

func Int64Attr(k string, v int64) KeyValue

Int64Attr is comparable to attribute.Int64.

func Int64SliceAttr

func Int64SliceAttr(k string, v []int64) KeyValue

Int64SliceAttr is comparable to attribute.Int64Slice.

func IntAttr

func IntAttr(k string, v int) KeyValue

IntAttr is comparable to attribute.Int.

func IntSliceAttr

func IntSliceAttr(k string, v []int) KeyValue

IntSliceAttr is comparable to attribute.IntSlice.

func ObjectAttr

func ObjectAttr(k string, v interface{}) KeyValue

ObjectAttr は構造体や map などの複合型を属性として設定するための KeyValue を生成します。 綺麗な型制約や命名を提供できなかったのはご愛嬌として、以下の点にご注意ください。

  • プリミティブ型以外の配列、またはそれを子として持つ構造体や map は構造上受け入れられない(JSONとして出力される)
  • map のキーの基底型が string でない場合は <T value> が属性のキーとして採用される

func StringAttr

func StringAttr(k, v string) KeyValue

StringAttr is comparable to attribute.String.

func StringSliceAttr

func StringSliceAttr(k string, v []string) KeyValue

StringSliceAttr is comparable to attribute.StringSlice.

func StringerAttr

func StringerAttr(k string, v fmt.Stringer) KeyValue

StringerAttr is comparable to attribute.Stringer.

Directories

Path Synopsis
package gcp is an abbreviation for Google Cloud 'Processor', not 'Platform'.
package gcp is an abbreviation for Google Cloud 'Processor', not 'Platform'.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL