tracing

package
v0.0.0-...-1762b78 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTraceConfig is the default Trace middleware config.
	DefaultTraceConfig = TraceConfig{
		ComponentName: defaultComponentName,
		IsBodyDump:    false,
	}
)

Functions

func InjectHTTPCarrier

func InjectHTTPCarrier(span Span, req *http.Request) error

InjectHTTPCarrier extracts trace ID from span and injects it into the http header.

func LogSpanError

func LogSpanError(span Span, message string, err error)

LogSpanError attaches message and error to the span.

func New

func New(router *mux.Router) io.Closer

New creates an Opentracing tracer and attaches it to mux middleware. Returns Closer do be added to caller function as `defer closer.Close()`

func Trace

func Trace(tracer opentracing.Tracer) mux.MiddlewareFunc

Trace returns a Trace middleware. Trace middleware traces http requests and reporting errors.

func TraceWithConfig

func TraceWithConfig(config TraceConfig) mux.MiddlewareFunc

TraceWithConfig returns a Trace middleware with config. See: `Trace()`.

Types

type Span

type Span interface {
	Finish()
	FinishWithOptions(opts opentracing.FinishOptions)
	Context() opentracing.SpanContext
	SetOperationName(operationName string) opentracing.Span
	SetTag(key string, value interface{}) opentracing.Span
	LogFields(fields ...log.Field)
	LogKV(alternatingKeyValues ...interface{})
	SetBaggageItem(restrictedKey string, value string) opentracing.Span
	BaggageItem(restrictedKey string) string
	Tracer() opentracing.Tracer
	LogEvent(event string)
	LogEventWithPayload(event string, payload interface{})
	Log(data opentracing.LogData)
}

Span is copy of opentracing.Span interface. It helps us to wrap the opentracing.Span and expose the local span to other layers.

Span represents an active, un-finished span in the OpenTracing system. The function that create the span is responsible to finish it.

func CreateSpan

func CreateSpan(ctx context.Context, operationName string) (Span, context.Context)

CreateSpan creates a new opentracing span adding tags for the span name and caller details. It accepts a context and an operation name. The span will be attached to the context, in this way we can create a nested spans. The operation name can be a function name, service name, or application layer name.

User must call defer `sp.Finish()`

type TraceConfig

type TraceConfig struct {
	// OpenTracing Tracer instance which should be got before
	Tracer opentracing.Tracer

	// ComponentName used for describing the tracing component name
	ComponentName string

	// Add req body & resp body to tracing tags
	IsBodyDump bool
}

TraceConfig defines the config for Trace middleware.

Jump to

Keyboard shortcuts

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