tracing

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanID added in v2.0.1

func GetSpanID(span opentracing.Span) string

GetSpanID extracts the span ID from the opentracing Span.

Currently only jaeger is supported. This can be useful when paired with the latest Grafana that includes a trace viewer.

func GetTraceID added in v2.0.1

func GetTraceID(span opentracing.Span) string

GetTraceID extracts the span ID from the opentracing Span.

Currently only jaeger is supported. This can be useful when paired with the latest Grafana that includes a trace viewer.

func InitJaeger

func InitJaeger(app string) error

InitJaeger asserts that the global tracer is initialized.

This will read the configuration from the "JAEGER_*"" environment variables. Overriding the empty values with the supplied app value. If a sampler type is not configured via the environment variables, then InitJaeger will be configured with the constant sampler.

Types

type SpanHook added in v2.5.0

type SpanHook struct{}

SpanHook is a logrus Hook to send write logs and their fields to the current span.

func (*SpanHook) Fire added in v2.5.0

func (hook *SpanHook) Fire(entry *logrus.Entry) error

Fire implements the Hook interface

func (*SpanHook) Levels added in v2.5.0

func (hook *SpanHook) Levels() []logrus.Level

Levels implements the Hook interface

type Tracer

type Tracer interface {
	StartSpan(ctx context.Context, operationName string) (opentracing.Span, context.Context)
	FinishSpan(opentracing.Span, error)
}

Tracer contains all the tracing-related functions for any module of the server that uses tracing

Normally, if you have a module that needs tracing you embed the Tracer as following:

type Some struct {
  tracing.Tracer
}

And then initialize the tracer when you initialize the module:

func NewSome() Some {
  return Some{
    Tracer: tracing.NewTracer("package", "Some"),
  }
}

To use the tracing capabilities you use it as following:

func (s Some) Foo(ctx context.Context) (err error) {
  span, ctx := s.StartSpan(ctx, "Foo")
  // since the err is not assigned yet we have to take it into the closure
  defer func() {
    s.FinishSpan(span, err)
  }()
  span.SetTag("something", "important")
  ...
}

func NewTracer

func NewTracer(pkgName, componentName string) Tracer

NewTracer create a new tracer that contains implementation for all tracing-related actions

func NewTracerWithLogs added in v2.0.1

func NewTracerWithLogs(pkgName, componentName string) Tracer

NewTracerWithLogs create a new tracer that contains logs spans to stdout as well as to the opentracing tracer.

Jump to

Keyboard shortcuts

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