tracer

package
v4.0.20 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 6 Imported by: 2

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 (
	// TraceIDKey is the key used for the trace id in the log call
	TraceIDKey = "trace-id"
	// SpanIDKey is the key used for the span id in the log call
	SpanIDKey = "span-id"
)
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 WithEventLabels added in v4.0.8

func WithEventLabels(ls ...interface{}) options.Option

func WithSpanKind

func WithSpanKind(k SpanKind) options.Option

func WithSpanLabels

func WithSpanLabels(ls ...interface{}) options.Option

Types

type EventOption

type EventOption func(o *EventOptions)

EventOption func signature

type EventOptions

type EventOptions struct {
	Labels []interface{}
}

EventOptions contains event options

func NewEventOptions added in v4.0.11

func NewEventOptions(opts ...options.Option) EventOptions

NewEventOptions returns default EventOptions

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 ...options.Option) Options

NewOptions returns default options

type Span

type Span interface {
	// Tracer return underlining tracer
	Tracer() Tracer
	// Finish complete and send span
	Finish(opts ...options.Option)
	// 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 ...options.Option)
	// AddLogs append logs to span
	AddLogs(kv ...interface{})
	// Kind returns span kind
	Kind() SpanKind
	// TraceID returns trace id
	TraceID() string
	// SpanID returns span id
	SpanID() string
}

func SpanFromContext

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

SpanFromContext returns a span from context

type SpanKind

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

func (sk SpanKind) String() string

type SpanOptions

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

SpanOptions contains span option

func NewSpanOptions

func NewSpanOptions(opts ...options.Option) SpanOptions

NewSpanOptions returns default SpanOptions

type SpanStatus

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

func (s SpanStatus) String() string

type Tracer

type Tracer interface {
	// Name return tracer name
	Name() string
	// Init tracer with options
	Init(...options.Option) error
	// Start a trace
	Start(ctx context.Context, name string, opts ...options.Option) (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 ...options.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