tracer

package
v3.10.41 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 12

Documentation

Overview

Package tracer provides an interface for distributed tracing

Package tracer provides an interface for distributed tracing

Index

Constants

This section is empty.

Variables

View Source
var DefaultTracer = NewTracer()

DefaultTracer is the global default tracer

Functions

func NewContext

func NewContext(ctx context.Context, tracer Tracer) context.Context

NewContext saves the tracer in the context

func NewSpanContext

func NewSpanContext(ctx context.Context, span Span) context.Context

NewSpanContext saves the span in the context

func UniqLabels added in v3.10.27

func UniqLabels(labels []interface{}) []interface{}

Types

type EventOption

type EventOption func(o *EventOptions)

EventOption func signature

func WithEventLabels added in v3.10.26

func WithEventLabels(kv ...interface{}) EventOption

type EventOptions

type EventOptions struct {
	Labels []interface{}
}

EventOptions contains event options

func NewEventOptions added in v3.10.28

func NewEventOptions(opts ...EventOption) EventOptions

NewEventOptions returns default EventOptions

type Option

type Option func(o *Options)

Option func signature

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Name

func Name(n string) Option

Name sets the name

func SetOption added in v3.10.1

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

type Options

type Options struct {
	// Context used to store custome tracer options
	Context context.Context
	// Logger used for logging
	Logger logger.Logger
	// Name of the tracer
	Name string
}

Options struct

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns default options

type Span

type Span interface {
	// Tracer return underlining tracer
	Tracer() Tracer
	// Finish complete and send span
	Finish(opts ...SpanOption)
	// Context return context with span
	Context() context.Context
	// SetName set the span name
	SetName(name string)
	// SetStatus set the span status code and msg
	SetStatus(status SpanStatus, msg string)
	// Status returns span status and msg
	Status() (SpanStatus, string)
	// AddLabels append labels to span
	AddLabels(kv ...interface{})
	// AddEvent append event to span
	AddEvent(name string, opts ...EventOption)
	// AddEvent append event to span
	AddLogs(kv ...interface{})
	// Kind returns span kind
	Kind() SpanKind
}

func SpanFromContext

func SpanFromContext(ctx context.Context) (Span, bool)

SpanFromContext returns a span from context

type SpanKind added in v3.10.3

type SpanKind int
const (
	// SpanKindUnspecified is an unspecified SpanKind and is not a valid
	// SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal
	// if it is received.
	SpanKindUnspecified SpanKind = 0
	// SpanKindInternal is a SpanKind for a Span that represents an internal
	// operation within an application.
	SpanKindInternal SpanKind = 1
	// SpanKindServer is a SpanKind for a Span that represents the operation
	// of handling a request from a client.
	SpanKindServer SpanKind = 2
	// SpanKindClient is a SpanKind for a Span that represents the operation
	// of client making a request to a server.
	SpanKindClient SpanKind = 3
	// SpanKindProducer is a SpanKind for a Span that represents the operation
	// of a producer sending a message to a message broker. Unlike
	// SpanKindClient and SpanKindServer, there is often no direct
	// relationship between this kind of Span and a SpanKindConsumer kind. A
	// SpanKindProducer Span will end once the message is accepted by the
	// message broker which might not overlap with the processing of that
	// message.
	SpanKindProducer SpanKind = 4
	// SpanKindConsumer is a SpanKind for a Span that represents the operation
	// of a consumer receiving a message from a message broker. Like
	// SpanKindProducer Spans, there is often no direct relationship between
	// this Span and the Span that produced the message.
	SpanKindConsumer SpanKind = 5
)

func (SpanKind) String added in v3.10.3

func (sk SpanKind) String() string

type SpanOption

type SpanOption func(o *SpanOptions)

SpanOption func signature

func WithSpanKind added in v3.10.3

func WithSpanKind(k SpanKind) SpanOption

func WithSpanLabels added in v3.10.3

func WithSpanLabels(kv ...interface{}) SpanOption

type SpanOptions

type SpanOptions struct {
	Labels []interface{}
	Kind   SpanKind
}

SpanOptions contains span option

func NewSpanOptions added in v3.10.3

func NewSpanOptions(opts ...SpanOption) SpanOptions

NewSpanOptions returns default SpanOptions

type SpanStatus added in v3.10.4

type SpanStatus int
const (
	// SpanStatusUnset is the default status code.
	SpanStatusUnset SpanStatus = 0

	// SpanStatusError indicates the operation contains an error.
	SpanStatusError SpanStatus = 1

	// SpanStatusOK indicates operation has been validated by an Application developers
	// or Operator to have completed successfully, or contain no error.
	SpanStatusOK SpanStatus = 2
)

func (SpanStatus) String added in v3.10.4

func (s SpanStatus) String() string

type Tracer

type Tracer interface {
	// Name return tracer name
	Name() string
	// Init tracer with options
	Init(...Option) error
	// Start a trace
	Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)
	// Flush flushes spans
	Flush(ctx context.Context) error
}

Tracer is an interface for distributed tracing

func FromContext

func FromContext(ctx context.Context) (Tracer, bool)

FromContext returns a tracer from context

func NewTracer

func NewTracer(opts ...Option) Tracer

NewTracer returns new memory tracer

Directories

Path Synopsis
Package wrapper provides wrapper for Tracer
Package wrapper provides wrapper for Tracer

Jump to

Keyboard shortcuts

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