tracing

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package tracing is responsible for forwarding and translating span headers for internal requests

Index

Constants

View Source
const (
	TraceID = prefixTracerState + "traceid"
)

Variables

This section is empty.

Functions

func HTTPMiddleware

func HTTPMiddleware(h http.Handler) http.Handler

func HeaderMatcher

func HeaderMatcher(key string) (string, bool)

HeaderMatcher ensures that open tracing headers x-b3-* are forwarded to output requests

func LogFromContext added in v0.27.0

func LogFromContext(ctx context.Context, log logger.Logger) logger.Logger

LogFromContext takes the trace ID from the current span and adds it to the logger:

returns:

  • the new logger with a context metadata value for traceID

This will be called on entry to a method or a function that has a context.Context.

func New

func New(log logger.Logger, service string, host string, zipkinEndpoint string) io.Closer

New initialises tracing uses zipkin client tracer

func NewFromEnv

func NewFromEnv(log logger.Logger, service string, host string, endpointVar, disableVar string) io.Closer

NewFromEnv initialises tracing and returns a closer if tracing is configured. If the necessary configuration is not available it is Fatal unless disableVar is set and is truthy (strconf.ParseBool -> true). If tracing is disabled returns nil

func NewSpanContext

func NewSpanContext(ctx context.Context, log logger.Logger, name string) (spanner.Spanner, context.Context)

func NewSpanWithAttributes added in v0.28.0

func NewSpanWithAttributes(ctx context.Context, name string, log logger.Logger, attributes map[string]any) (spanner.Spanner, context.Context)

Constructors...

func NewTracer

func NewTracer(log logger.Logger, portName string) io.Closer

NewTracer and the following methods are only called once to create the global tracer in startup/run.go

func SetSpanField added in v0.27.0

func SetSpanField(ctx context.Context, key string, value string)

func SetSpanHTTPHeader added in v0.27.0

func SetSpanHTTPHeader(span opentracing.Span, log logger.Logger, r *http.Request)

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, log logger.Logger, name string) (spanner.Spanner, context.Context)

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context, log logger.Logger) string

Types

type Span added in v0.28.0

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

Injecting a function StartSpanFomContext that returns an interface does not work as the Go compiler treats interfaces defined in separate packages as different even though the signature is identical. So this struct hides the interface and returns a concrete type instead. Conveniently it also hides calls to the opentracing-go package thsu making it easier to move to opentelemetry later.

func (*Span) Attributes added in v0.28.0

func (s *Span) Attributes(log logger.Logger) map[string]any

func (*Span) Close added in v0.28.0

func (s *Span) Close()

func (*Span) LogField added in v0.28.0

func (s *Span) LogField(key string, value any)

func (*Span) SetSpanHTTPHeader added in v0.28.0

func (s *Span) SetSpanHTTPHeader(r *http.Request)

func (*Span) SetTag added in v0.28.0

func (s *Span) SetTag(key string, value any)

func (*Span) TraceID added in v0.28.0

func (s *Span) TraceID() string

type Spanner added in v0.28.0

type Spanner interface {
	Close()
	SetTag(string, any)
	SetSpanHTTPHeader(http.Request)
	SetSpanField(string, string)
	TraceID() string
}

Jump to

Keyboard shortcuts

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