Documentation ¶
Index ¶
- Constants
- Variables
- func FromContext(ctx context.Context) opentracing.SpanContext
- func NewLoggerWithTraceID(ctx context.Context, l logging.Logger) *logrus.Entry
- func WithContext(ctx context.Context, c opentracing.SpanContext) context.Context
- type Options
- type Tracer
- func (t *Tracer) AddContextHeader(ctx context.Context, headers p2p.Headers) error
- func (t *Tracer) FromHeaders(headers p2p.Headers) (opentracing.SpanContext, error)
- func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string, l logging.Logger, ...) (opentracing.Span, *logrus.Entry, context.Context)
- func (t *Tracer) WithContextFromHeaders(ctx context.Context, headers p2p.Headers) (context.Context, error)
Constants ¶
const LogField = "traceid"
LogField is the key in log message field that holds tracing id value.
Variables ¶
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 ¶
FromContext return tracing span context from go context. If the tracing span context is not present in go context, nil is returned.
func NewLoggerWithTraceID ¶
NewLoggerWithTraceID creates a new log Entry with "traceid" field added if it exists in tracing span context stored from go context.
Types ¶
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 ¶
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 ¶
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 ¶
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.