tracing

package
v0.0.0-...-677c28a Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoInSpan

func DoInSpan(ctx context.Context, spanName string, f func(context.Context) error) error

DoInSpan does `f` function inside span using tracer in the context. WARNING: ctx has to be chained to root Tracer.StartSpan or Tracer.DoInSpan.

Types

type Context

type Context interface {
	IsSampled() bool
	TraceID() string
	SpanID() string
}

type Exporter

type Exporter = sdktrace.SpanExporter

type ExporterBuilder

type ExporterBuilder func() (Exporter, error)

func NewWriterExporter

func NewWriterExporter(w io.Writer) ExporterBuilder

NewWriterExporter returns the writer exporter for spans.

type Option

type Option func(*options)

Option sets the value of an option for a Config.

func WithExporter

func WithExporter(startExporterFn ExporterBuilder) Option

WithExporter sets additional exporter builders for spans. E.g. otlp.Exporter and Thrift

func WithSampler

func WithSampler(s Sampler) Option

WithSampler sets sampler, by default there is no sampler.

func WithServiceName

func WithServiceName(s string) Option

WithServiceName sets service name that will be in attributes of all spans created by this tracer in "service.name" key. Usually it comes in format of service:app.

type Sampler

type Sampler = sdktrace.Sampler

func TraceIDRatioBasedSampler

func TraceIDRatioBasedSampler(fraction float64) Sampler

TraceIDRatioBasedSampler samples a given fraction of traces. Fractions >= 1 will always sample. Fractions < 0 are treated as zero. To respect the parent trace's `SampledFlag`, the `TraceIDRatioBased` sampler should be used as a delegate of a `Parent` sampler.

type Span

type Span interface {
	// End completes the Span. The Span is considered complete and ready to be
	// delivered through the rest of the telemetry pipeline after this method
	// is called. Therefore, updates to the Span are not allowed after this
	// method has been called.
	// TODO(bwplotka): Add Set status to End options.
	End(err error)

	// Context returns span context that contains useful information about span and belonging trace.
	// This information is available even after span End.
	// NOTE: Do not confuse with Go context.Context which is important, but has to be tracked outside of Span.
	Context() Context

	// AddEvent adds an event to the span. This was previously (in OpenTracing) known as
	// structured logs attached to the span.
	AddEvent(name string, keyvals ...interface{})

	// SetAttributes sets kv as attributes of the Span. If a key from kv
	// already exists for an attribute of the Span it should be overwritten with
	// the value contained in kv.
	SetAttributes(keyvals ...interface{})
}

Span is the individual component of a trace. It represents a single named and timed operation of a workflow that is traced. A Tracer is used to create a Span and it is then up to the operation the Span represents to properly end the Span when the operation itself ends.

func GetSpan

func GetSpan(ctx context.Context) Span

GetSpan returns current span or noopSpan if no span was created.

func StartSpan

func StartSpan(ctx context.Context, spanName string) (context.Context, Span)

StartSpan creates spans using tracer in the context. WARNING: ctx has to be chained to root Tracer.StartSpan or Tracer.DoInSpan.

type Tracer

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

Tracer is the root tracing entity that can enables creation of spans, and its export to the desired backends in a form of traces.

func NewTracer

func NewTracer(exporter ExporterBuilder, opts ...Option) (*Tracer, func() error, error)

NewTracer creates new instance of Tracer with given exporter builder. Tracer returns tracer and close function that releases all resources or error.

func (*Tracer) DoInSpan

func (tr *Tracer) DoInSpan(spanName string, f func(context.Context) error, opts ...TracerStartSpanOption) error

DoInSpan does `f` function that can return error inside span using tracer in the context.

func (*Tracer) StartSpan

func (tr *Tracer) StartSpan(spanName string, opts ...TracerStartSpanOption) (context.Context, Span)

StartSpan creates a new root span that can add more spans using returned context. Returned context

type TracerStartSpanOption

type TracerStartSpanOption func(*tracerStartSpanOptions)

TracerStartSpanOption sets the value in tracerStartSpanOptions.

func WithTracerStartSpanContext

func WithTracerStartSpanContext(ctx context.Context) TracerStartSpanOption

Directories

Path Synopsis
exporters

Jump to

Keyboard shortcuts

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