tracing

package
v0.0.0-kmdagger2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: AGPL-3.0 Imports: 27 Imported by: 174

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithSpan

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

ContextWithSpan returns a new context.Context that holds a reference to the given span. If span is nil, a new context without an active span is returned. It is the equivalent of opentracing.ContextWithSpan and trace.ContextWithSpan.

func TraceIDFromContext

func TraceIDFromContext(c context.Context, requireSampled bool) string

Types

type EventValue

type EventValue struct {
	Str string
	Num int64
}

type FakeSpan

type FakeSpan struct {
	Name string

	Attributes  map[attribute.Key]attribute.Value
	StatusCode  codes.Code
	Description string
	Err         error
	Events      map[string]EventValue
	// contains filtered or unexported fields
}

func (*FakeSpan) AddEvents

func (t *FakeSpan) AddEvents(keys []string, values []EventValue)

func (*FakeSpan) End

func (t *FakeSpan) End()

func (*FakeSpan) IsEnded

func (t *FakeSpan) IsEnded() bool

func (*FakeSpan) RecordError

func (t *FakeSpan) RecordError(err error, options ...trace.EventOption)

func (*FakeSpan) SetAttributes

func (t *FakeSpan) SetAttributes(key string, value interface{}, kv attribute.KeyValue)

func (*FakeSpan) SetName

func (t *FakeSpan) SetName(name string)

func (*FakeSpan) SetStatus

func (t *FakeSpan) SetStatus(code codes.Code, description string)

type FakeTracer

type FakeTracer struct {
	Spans []*FakeSpan
}

func NewFakeTracer

func NewFakeTracer() *FakeTracer

func (*FakeTracer) Inject

func (t *FakeTracer) Inject(ctx context.Context, header http.Header, span Span)

func (*FakeTracer) Run

func (t *FakeTracer) Run(ctx context.Context) error

func (*FakeTracer) Start

func (t *FakeTracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, Span)

type Opentelemetry

type Opentelemetry struct {
	Address     string
	Propagation string

	Cfg *setting.Cfg
	// contains filtered or unexported fields
}

func ParseSettings

func ParseSettings(cfg *setting.Cfg) (*Opentelemetry, error)

func (*Opentelemetry) Inject

func (ots *Opentelemetry) Inject(ctx context.Context, header http.Header, _ Span)

func (*Opentelemetry) OTelExporterEnabled

func (ots *Opentelemetry) OTelExporterEnabled() bool

func (*Opentelemetry) Run

func (ots *Opentelemetry) Run(ctx context.Context) error

func (*Opentelemetry) Start

func (ots *Opentelemetry) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, Span)

type OpentelemetrySpan

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

func (OpentelemetrySpan) AddEvents

func (s OpentelemetrySpan) AddEvents(keys []string, values []EventValue)

func (OpentelemetrySpan) End

func (s OpentelemetrySpan) End()

func (OpentelemetrySpan) RecordError

func (s OpentelemetrySpan) RecordError(err error, options ...trace.EventOption)

func (OpentelemetrySpan) SetAttributes

func (s OpentelemetrySpan) SetAttributes(key string, value interface{}, kv attribute.KeyValue)

func (OpentelemetrySpan) SetName

func (s OpentelemetrySpan) SetName(name string)

func (OpentelemetrySpan) SetStatus

func (s OpentelemetrySpan) SetStatus(code codes.Code, description string)

type Span

type Span interface {
	// End finalizes the Span and adds its end timestamp.
	// Any further operations on the Span are not permitted after
	// End has been called.
	End()
	// SetAttributes adds additional data to a span.
	// SetAttributes repeats the key value pair with [string] and [any]
	// used for OpenTracing and [attribute.KeyValue] used for
	// OpenTelemetry.
	SetAttributes(key string, value interface{}, kv attribute.KeyValue)
	// SetName renames the span.
	SetName(name string)
	// SetStatus can be used to indicate whether the span was
	// successfully or unsuccessfully executed.
	//
	// Only useful for OpenTelemetry.
	SetStatus(code codes.Code, description string)
	// RecordError adds an error to the span.
	//
	// Only useful for OpenTelemetry.
	RecordError(err error, options ...trace.EventOption)
	// AddEvents adds additional data with a temporal dimension to the
	// span.
	//
	// Panics if the length of keys is shorter than the length of values.
	AddEvents(keys []string, values []EventValue)
	// contains filtered or unexported methods
}

Span defines a time range for an operation. This is equivalent to a single line in a flame graph.

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. It is the equivalent of opentracing.SpanFromContext and trace.SpanFromContext.

type Tracer

type Tracer interface {
	// Run implements registry.BackgroundService.
	Run(context.Context) error
	// Start creates a new [Span] and places trace metadata on the
	// [context.Context] passed to the method.
	// Chose a low cardinality spanName and use [Span.SetAttributes]
	// or [Span.AddEvents] for high cardinality data.
	Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, Span)
	// Inject adds identifying information for the span to the
	// headers defined in [http.Header] map (this mutates http.Header).
	//
	// Implementation quirk: Where OpenTelemetry is used, the [Span] is
	// picked up from [context.Context] and for OpenTracing the
	// information passed as [Span] is preferred.
	// Both the context and span must be derived from the same call to
	// [Tracer.Start].
	Inject(context.Context, http.Header, Span)
}

Tracer defines the service used to create new spans.

func InitializeTracerForTest

func InitializeTracerForTest() Tracer

func ProvideService

func ProvideService(cfg *setting.Cfg) (Tracer, error)

Jump to

Keyboard shortcuts

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