trace

package
v0.0.0-...-303e327 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Binary is the alias of opentracing.Binary.
	Binary = opentracing.Binary

	// TextMap is the alias of opentracing.TextMap.
	TextMap = opentracing.TextMap

	// HTTPHeaders is the alias of opentracing.HTTPHeaders.
	HTTPHeaders = opentracing.HTTPHeaders
)

Variables

View Source
var (
	// ErrUnsupportedFormat is the alias of opentracing.ErrUnsupportedFormat.
	ErrUnsupportedFormat = opentracing.ErrUnsupportedFormat

	// ErrSpanContextNotFound is the alias of opentracing.ErrSpanContextNotFound.
	ErrSpanContextNotFound = opentracing.ErrSpanContextNotFound

	// ErrInvalidSpanContext is the alias of opentracing.ErrInvalidSpanContext.
	ErrInvalidSpanContext = opentracing.ErrInvalidSpanContext

	// ErrInvalidCarrier is the alias of opentracing.ErrInvalidCarrier.
	ErrInvalidCarrier = opentracing.ErrInvalidCarrier

	// ErrSpanContextCorrupted is the alias of opentracing.ErrSpanContextCorrupted.
	ErrSpanContextCorrupted = opentracing.ErrSpanContextCorrupted
)
View Source
var ChildOf = opentracing.ChildOf

ChildOf is the alias of opentracing.ChildOf

View Source
var FollowsFrom = opentracing.FollowsFrom

FollowsFrom is the alias of opentracing.FollowsFrom

View Source
var TracerOptions tracerOptions

TracerOptions is a factory for all available TracerOption's

Functions

func CloseGlobalTracer

func CloseGlobalTracer()

CloseGlobalTracer closes global tracer gracefully.

func ContextWithSpan

func ContextWithSpan(ctx context.Context, span Span) context.Context

ContextWithSpan returns a new `context.Context` that holds a reference to the span. If span is nil, a new context without an active span is returned.

func Extract

func Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)

Extract returns a SpanContext instance given `format` and `carrier`.

func GetTraceIDKey

func GetTraceIDKey() string

GetTraceIDKey returns http header name of traceid

func InjectWithHTTPHeader

func InjectWithHTTPHeader(ctx context.Context, r *http.Request) error

InjectWithHTTPHeader takes the `sm` SpanContext instance and injects it for propagation within `HTTPHeadersCarrier` and `HTTPHeaders`.

func SetGlobalTracer

func SetGlobalTracer(tracer *Tracer)

SetGlobalTracer sets the [singleton] opentracing.Tracer returned by GlobalTracer(). Those who use GlobalTracer (rather than directly manage an opentracing.Tracer instance) should call SetGlobalTracer as early as possible in main(), prior to calling the `StartSpan` global func below. Prior to calling `SetGlobalTracer`, any Spans started via the `StartSpan` (etc) globals are noops.

Types

type HTTPHeadersCarrier

type HTTPHeadersCarrier = opentracing.HTTPHeadersCarrier

HTTPHeadersCarrier is the alias of opentracing.HTTPHeadersCarrier.

type ID

type ID uint64

ID used for spanID or traceID

func RandomID

func RandomID() ID

RandomID generate ID for traceID or spanID

func (ID) String

func (id ID) String() string

type Options

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

Options tracer options

type Span

type Span interface {
	opentracing.Span

	// OperationName allows retrieving current operation name.
	OperationName() string

	// Tags returns tags for span
	Tags() Tags

	// Logs returns micro logs for span
	Logs() []opentracing.LogRecord

	// String returns traceID:spanID.
	String() string

	// TraceID returns traceID
	TraceID() string

	// AppendRPCTrackLog appends RPC track logs to baggage with default key fieldTrackLogKey.
	AppendRPCTrackLog(logs []string)
	// AppendTrackLog records cost time with startTime (duration=time.Since(startTime)) for a calling to a module and
	// appends to baggage with default key fieldTrackLogKey.
	AppendTrackLog(module string, startTime time.Time, err error)
	// AppendTrackLogWithDuration records cost time with duration for a calling to a module and
	// appends to baggage with default key fieldTrackLogKey.
	AppendTrackLogWithDuration(module string, duration time.Duration, err error)
	// TrackLog returns track log, calls BaggageItem with default key fieldTrackLogKey.
	TrackLog() []string

	// BaseLogger defines interface of application log apis.
	log.BaseLogger
}

Span extends opentracing.Span

func SpanFromContext

func SpanFromContext(ctx context.Context) Span

SpanFromContext returns the `Span` previously associated with `ctx`, or `nil` if no such `Span` could be found.

func SpanFromContextSafe

func SpanFromContextSafe(ctx context.Context) Span

SpanFromContextSafe returns the `Span` previously associated with `ctx`, or creates a root Span with name default.

func StartSpanFromContext

func StartSpanFromContext(ctx context.Context, operationName string, opts ...opentracing.StartSpanOption) (Span, context.Context)

StartSpanFromContext starts and returns a Span with `operationName`, using any Span found within `ctx` as a ChildOfRef. If no such parent could be found, StartSpanFromContext creates a root (parentless) Span.

func StartSpanFromContextWithTraceID

func StartSpanFromContextWithTraceID(ctx context.Context, operationName string, traceID string, opts ...opentracing.StartSpanOption) (Span, context.Context)

StartSpanFromContextWithTraceID starts and return a new span with `operationName` and traceID.

func StartSpanFromHTTPHeaderSafe

func StartSpanFromHTTPHeaderSafe(r *http.Request, operationName string) (Span, context.Context)

StartSpanFromHTTPHeaderSafe starts and return a Span with `operationName` and http.Request

type SpanContext

type SpanContext struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SpanContext implements opentracing.SpanContext

func (*SpanContext) ForeachBaggageItem

func (s *SpanContext) ForeachBaggageItem(handler func(k, v string) bool)

ForeachBaggageItem implements opentracing.SpanContext API

func (*SpanContext) ForeachBaggageItems

func (s *SpanContext) ForeachBaggageItems(handler func(k string, v []string) bool)

ForeachBaggageItems will called the handler function for each baggage key/values pair.

func (*SpanContext) IsEmpty

func (s *SpanContext) IsEmpty() bool

IsEmpty returns true is span context is empty

func (*SpanContext) IsValid

func (s *SpanContext) IsValid() bool

IsValid returns true if SpanContext is valid

type StartTime

type StartTime = opentracing.StartTime

StartTime is alias of opentracing.StartTime.

type Tag

type Tag = opentracing.Tag

Tag is the alias of opentracing.Tag,

type Tags

type Tags opentracing.Tags

Tags are the expand of opentracing.Tags

func (Tags) Apply

func (t Tags) Apply(options *opentracing.StartSpanOptions)

Apply satisfies the StartSpanOption interface.

func (Tags) Marshal

func (t Tags) Marshal() (ret []byte, err error)

Marshal marshal tracer tags

func (Tags) ToSlice

func (t Tags) ToSlice() (ret []string)

ToSlice change tags to slice

type TextMapCarrier

type TextMapCarrier = opentracing.TextMapCarrier

TextMapCarrier is the alias of opentracing.TextMapCarrier.

type TextMapPropagator

type TextMapPropagator struct{}

TextMapPropagator is a combined Injector and Extractor for TextMap format.

func (*TextMapPropagator) Extract

func (t *TextMapPropagator) Extract(carrier interface{}) (opentracing.SpanContext, error)

Extract implements Extractor of TextMapPropagator.

func (*TextMapPropagator) Inject

func (t *TextMapPropagator) Inject(sc *SpanContext, carrier interface{}) error

Inject implements Injector of TextMapPropagator

type Tracer

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

Tracer implements opentracing.Tracer

func GlobalTracer

func GlobalTracer() *Tracer

GlobalTracer returns the global singleton `Tracer` implementation.

func NewTracer

func NewTracer(serviceName string, opts ...TracerOption) *Tracer

NewTracer creates a tracer with serviceName

func (*Tracer) Close

func (t *Tracer) Close() error

Close releases all resources

func (*Tracer) Extract

func (t *Tracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error)

Extract implements Extract() method of opentracing.Tracer

func (*Tracer) Inject

func (t *Tracer) Inject(sc opentracing.SpanContext, format interface{}, carrier interface{}) error

Inject implements Inject() method of opentracing.Tracer

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(operationName string, options ...opentracing.StartSpanOption) opentracing.Span

StartSpan implements StartSpan() method of opentracing.Tracer. Create, start, and return a new Span with the given `operationName` and incorporate the given StartSpanOption `opts`.

type TracerOption

type TracerOption func(tracer *Tracer)

TracerOption is a function that sets some option on the tracer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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