trace

package
v2.9.0-beta2-websocket... Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrManagerDisabled = errors.New("trace: trace is diabled")

Functions

func AddTracer

func AddTracer(service string) error

AddTracer initialize a tracer for the service.

func Close

func Close() error

Close calls Close on the global tace manager.

func Debug

func Debug(ctx context.Context, logrus Logrus, args ...interface{})

Debug creates debug log on both logrus and span.

func Disable

func Disable()

Disable disables the global trace manager.

func Enable

func Enable()

Enable sets the global manager to enabled.

func Error

func Error(ctx context.Context, logrus Logrus, args ...interface{})

func Extract

func Extract(tr Tracer, h http.Header) (opentracing.SpanContext, error)

func ExtractFromContext

func ExtractFromContext(ctx context.Context, h http.Header) (opentracing.SpanContext, error)

func GetServiceID

func GetServiceID(ctx context.Context) string

GetServiceID returns service name attched to context returns an empty string if the service name key is not found.

func Handle

func Handle(service string, h http.Handler) http.Handler

Handle returns a http.Handler with root opentracting setup. This should be the topmost handler.

func Info

func Info(ctx context.Context, logrus Logrus, args ...interface{})

func Inject

func Inject(service string, span opentracing.Span, h http.Header) error

func InjectFromContext

func InjectFromContext(ctx context.Context, span opentracing.Span, h http.Header) error

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if the global trace manager is enabled.

func Log

func Log(ctx context.Context, fields ...log.Field)

Log tries to check if there is a span in ctx and adds logs fields on the span.

func Root

func Root(service string, r *http.Request) (opentracing.Span, *http.Request)

func SetLogger

func SetLogger(log Logger)

func SetServiceID

func SetServiceID(ctx context.Context, service string) context.Context

SetServiceID returns context with service assigned to it.

func SetupTracing

func SetupTracing(name string, opts map[string]interface{})

func Span

Span creates a new span for the given ops. If tracing is disabled in this ctx then a noop span is created and the same ctx is returned.

Note that the returned context contains the returned span as active span. So any spans created form the returned context will be children of the returned span.

func Warning

func Warning(ctx context.Context, logrus Logrus, args ...interface{})

Types

type Config

type Config struct {
	Name string
	Opts map[string]interface{}
}

type Logger

type Logger interface {
	Errorf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
}

Logger defines api for logging messages by the OpenTracer struct. This is a workaround to avoid trying this to logrus

type Logrus

type Logrus interface {
	Debug(args ...interface{})
	Error(args ...interface{})
	Warning(args ...interface{})
	Info(args ...interface{})
}

Logrus implements a subset of logrus api to reduce friction when we want to log both on opentracing and on logrus.

type NoopTracer

type NoopTracer struct {
	opentracing.NoopTracer
}

NoopTracer wraps opentracing.NoopTracer to satisfy Tracer interface.

func (NoopTracer) Close

func (n NoopTracer) Close() error

Close implements io.Closer interface by doing nothing.

func (NoopTracer) Name

func (n NoopTracer) Name() string

type OpenTracer

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

OpenTracer manages initializing,storage and retrieving on multiple tracers based on service names.

func NewManager

func NewManager(log Logger) *OpenTracer

NewManager returns a new opentrace manager. If log is not nil it will be used to log errors and info by the manager.

func (*OpenTracer) AddTracer

func (o *OpenTracer) AddTracer(service string) error

AddTracer initializes a tracer based on the configuration stored in o for the given service name and caches. This does donthing when there is already a tracer for the given service.

func (*OpenTracer) Close

func (o *OpenTracer) Close() error

Close calls Close on the active tracer.

func (*OpenTracer) Disable

func (o *OpenTracer) Disable()

Disable sets o to disabled state.

func (*OpenTracer) Enable

func (o *OpenTracer) Enable()

Enable sets o to enabled state.

func (*OpenTracer) Get

func (o *OpenTracer) Get(service string) Tracer

Get returns a tracer for a given service, it returns a NoopTracer if there is no tracer for the service found.

func (*OpenTracer) GetOk

func (o *OpenTracer) GetOk(service string) (Tracer, bool)

GetOk like Get but instead of returning NoopTracer for missing tracer it returns nil and false when the service tracer wasn't found.

func (*OpenTracer) IsEnabled

func (o *OpenTracer) IsEnabled() bool

IsEnabled returns true if the manager is enabled.

func (*OpenTracer) Set

func (o *OpenTracer) Set(service string, tr Tracer)

Set saves tr using service as key on o.

func (*OpenTracer) SetLogger

func (o *OpenTracer) SetLogger(log Logger)

SetLogger sets log as the default logger for o.

func (*OpenTracer) SetupTracing

func (o *OpenTracer) SetupTracing(name string, opts map[string]interface{})

type Tracer

type Tracer interface {
	Name() string
	opentracing.Tracer
	io.Closer
}

func Get

func Get(service string) Tracer

Get returns a tracer stored on the global trace manager.

func Init

func Init(name string, service string, opts map[string]interface{}, logger Logger) (Tracer, error)

Init returns a tracer for a given name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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