tracing

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 12 Imported by: 9

Documentation

Index

Constants

View Source
const LogField = "traceid"

LogField is the key in log message field that holds tracing id value.

Variables

View Source
var (
	// ErrContextNotFound is returned when tracing context is not present
	// in p2p Headers or context.
	ErrContextNotFound = errors.New("tracing context not found")
)

Functions

func FromContext

func FromContext(ctx context.Context) opentracing.SpanContext

FromContext return tracing span context from go context. If the tracing span context is not present in go context, nil is returned.

func NewLoggerWithTraceID

func NewLoggerWithTraceID(ctx context.Context, l logging.Logger) *logrus.Entry

NewLoggerWithTraceID creates a new log Entry with "traceid" field added if it exists in tracing span context stored from go context.

func WithContext

func WithContext(ctx context.Context, c opentracing.SpanContext) context.Context

WithContext adds tracing span context to go context.

Types

type Options

type Options struct {
	Enabled     bool
	Endpoint    string
	ServiceName string
}

Options are optional parameters for Tracer constructor.

type Tracer

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

Tracer connect to a tracing server and handles tracing spans and contexts by using opentracing Tracer.

func NewTracer

func NewTracer(o *Options) (*Tracer, io.Closer, error)

NewTracer creates a new Tracer and returns a closer which needs to be closed when the Tracer is no longer used to flush remaining traces.

func (*Tracer) AddContextHeader

func (t *Tracer) AddContextHeader(ctx context.Context, headers p2p.Headers) error

AddContextHeader adds a tracing span context to provided p2p Headers from the go context. If the tracing span context is not present in go context, ErrContextNotFound is returned.

func (*Tracer) FromHeaders

func (t *Tracer) FromHeaders(headers p2p.Headers) (opentracing.SpanContext, error)

FromHeaders returns tracing span context from p2p Headers. If the tracing span context is not present in go context, ErrContextNotFound is returned.

func (*Tracer) StartSpanFromContext

func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string, l logging.Logger, opts ...opentracing.StartSpanOption) (opentracing.Span, *logrus.Entry, context.Context)

StartSpanFromContext starts a new tracing span that is either a root one or a child of existing one from the provided Context. If logger is provided, a new log Entry will be returned with "traceid" log field.

func (*Tracer) WithContextFromHeaders

func (t *Tracer) WithContextFromHeaders(ctx context.Context, headers p2p.Headers) (context.Context, error)

WithContextFromHeaders returns a new context with injected tracing span context if they are found in p2p Headers. If the tracing span context is not present in go context, ErrContextNotFound is returned.

Jump to

Keyboard shortcuts

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