trace

package
v0.0.0-...-a71ec85 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCurrentSpan

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

Types

type Decision

type Decision struct {
	// Sampled is set true if the span should be sampled.
	Sampled bool

	// Attributes provides insight into Sample	r's decision process.
	// It could be empty slice or nil if no attributes are recorded by the sampler.
	Attributes []core.KeyValue
}

type EndOption

type EndOption func(*EndOptions)

func WithEndTime

func WithEndTime(endTime time.Time) EndOption

type EndOptions

type EndOptions struct {
	EndTime time.Time
}
type Link struct {
	core.SpanContext
	Attributes []core.KeyValue
}

Link is used to establish relationship between two spans within the same Trace or across different Traces. Few examples of Link usage.

  1. Batch Processing: A batch of elements may contain elements associated with one or more traces/spans. Since there can only be one parent SpanContext, Link is used to keep reference to SpanContext of all elements in the batch.
  2. Public Endpoint: A SpanContext in incoming client request on a public endpoint is untrusted from service provider perspective. In such case it is advisable to start a new trace with appropriate sampling decision. However, it is desirable to associate incoming SpanContext to new trace initiated on service provider side so two traces (from Client and from Service Provider) can be correlated.

type NoopProvider

type NoopProvider struct{}

func (NoopProvider) GetTracer

func (p NoopProvider) GetTracer(name string) Tracer

GetTracer returns noop implementation of Tracer.

type NoopSpan

type NoopSpan struct {
}

func (NoopSpan) AddEvent

func (NoopSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue)

AddEvent does nothing.

func (NoopSpan) AddEventWithTimestamp

func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue)

AddEventWithTimestamp does nothing.

func (NoopSpan) AddLink(link Link)

AddLink does nothing.

func (NoopSpan) End

func (NoopSpan) End(options ...EndOption)

End does nothing.

func (NoopSpan) IsRecording

func (NoopSpan) IsRecording() bool

IsRecording always returns false for NoopSpan.

func (NoopSpan) Link(sc core.SpanContext, attrs ...core.KeyValue)

Link does nothing.

func (NoopSpan) SetAttribute

func (NoopSpan) SetAttribute(attribute core.KeyValue)

SetAttribute does nothing.

func (NoopSpan) SetAttributes

func (NoopSpan) SetAttributes(attributes ...core.KeyValue)

SetAttributes does nothing.

func (NoopSpan) SetError

func (NoopSpan) SetError(v bool)

SetError does nothing.

func (NoopSpan) SetName

func (NoopSpan) SetName(name string)

SetName does nothing.

func (NoopSpan) SetStatus

func (NoopSpan) SetStatus(status codes.Code)

SetStatus does nothing.

func (NoopSpan) SpanContext

func (NoopSpan) SpanContext() core.SpanContext

SpancContext returns an invalid span context.

func (NoopSpan) Tracer

func (NoopSpan) Tracer() Tracer

Tracer returns noop implementation of Tracer.

type NoopTracer

type NoopTracer struct{}

func (NoopTracer) Start

func (NoopTracer) Start(ctx context.Context, name string, opts ...SpanOption) (context.Context, Span)

Start starts a noop span.

func (NoopTracer) WithComponent

func (t NoopTracer) WithComponent(name string) Tracer

WithComponent does nothing and returns noop implementation of Tracer.

func (NoopTracer) WithResources

func (t NoopTracer) WithResources(attributes ...core.KeyValue) Tracer

WithResources does nothing and returns noop implementation of Tracer.

func (NoopTracer) WithService

func (t NoopTracer) WithService(name string) Tracer

WithService does nothing and returns noop implementation of Tracer.

func (NoopTracer) WithSpan

func (t NoopTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error) error

WithSpan wraps around execution of func with noop span.

type Provider

type Provider interface {
	// GetTracer creates a named tracer that implements Tracer interface.
	// If the name is an empty string then provider uses default name.
	GetTracer(name string) Tracer
}

type Relation

type Relation struct {
	core.SpanContext
	RelationshipType
}

Relation is used to establish relationship between newly created span and the other span. The other span could be related as a parent or linked or any other future relationship type.

type RelationshipType

type RelationshipType int
const (
	ChildOfRelationship RelationshipType = iota
	FollowsFromRelationship
)

type Sampler

type Sampler interface {
	// ShouldSample returns a Decision that contains a decision whether to sample
	// or not sample the span to be created. Decision is based on a Sampler specific
	// algorithm that takes into account one or more input parameters.
	ShouldSample(
		sc core.SpanContext,
		remote bool,
		traceID core.TraceID,
		spanID uint64,
		spanName string,
	) Decision

	// Description returns of the sampler. It contains its name or short description
	// and its configured properties.
	// For example 'ProbabilitySampler:{0.00001}'
	Description() string
}

func AlwaysSampleSampler

func AlwaysSampleSampler() Sampler

func NeverSampleSampler

func NeverSampleSampler() Sampler

type Span

type Span interface {
	// Tracer returns tracer used to create this span. Tracer cannot be nil.
	Tracer() Tracer

	// End completes the span. No updates are allowed to span after it
	// ends. The only exception is setting status of the span.
	End(options ...EndOption)

	// AddEvent adds an event to the span.
	AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue)
	// AddEventWithTimestamp adds an event with a custom timestamp
	// to the span.
	AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue)

	// IsRecording returns true if the span is active and recording events is enabled.
	IsRecording() bool

	// AddLink adds a link to the span.
	AddLink(link Link)

	// Link creates a link between this span and the other span specified by the SpanContext.
	// It then adds the newly created Link to the span.
	Link(sc core.SpanContext, attrs ...core.KeyValue)

	// SpanContext returns span context of the span. Returned SpanContext is usable
	// even after the span ends.
	SpanContext() core.SpanContext

	// SetStatus sets the status of the span. The status of the span can be updated
	// even after span ends.
	SetStatus(codes.Code)

	// SetName sets the name of the span.
	SetName(name string)

	// Set span attributes
	SetAttribute(core.KeyValue)
	SetAttributes(...core.KeyValue)
}

func CurrentSpan

func CurrentSpan(ctx context.Context) Span

type SpanKind

type SpanKind string

SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span will be processed and visualized by various backends.

const (
	SpanKindInternal SpanKind = "internal"
	SpanKindServer   SpanKind = "server"
	SpanKindClient   SpanKind = "client"
	SpanKindProducer SpanKind = "producer"
	SpanKindConsumer SpanKind = "consumer"
)

type SpanOption

type SpanOption func(*SpanOptions)

SpanOption apply changes to SpanOptions.

func ChildOf

func ChildOf(sc core.SpanContext) SpanOption

ChildOf. TODO: do we need this?.

func FollowsFrom

func FollowsFrom(sc core.SpanContext) SpanOption

FollowsFrom. TODO: do we need this?.

func WithAttributes

func WithAttributes(attrs ...core.KeyValue) SpanOption

WithAttributes sets attributes to span. These attributes provides additional data about the span.

func WithRecord

func WithRecord() SpanOption

WithRecord specifies that the span should be recorded. Note that the implementation may still override this preference, e.g., if the span is a child in an unsampled trace.

func WithSpanKind

func WithSpanKind(sk SpanKind) SpanOption

WithSpanKind specifies the role a Span on a Trace.

func WithStartTime

func WithStartTime(t time.Time) SpanOption

WithStartTime sets the start time of the span to provided time t, when it is started. In absence of this option, wall clock time is used as start time. This option is typically used when starting of the span is delayed.

type SpanOptions

type SpanOptions struct {
	Attributes []core.KeyValue
	StartTime  time.Time
	Relation   Relation
	Record     bool
	SpanKind   SpanKind
}

SpanOptions provides options to set properties of span at the time of starting a new span.

type Tracer

type Tracer interface {
	// Start a span.
	Start(context.Context, string, ...SpanOption) (context.Context, Span)

	// WithSpan wraps the execution of the function body with a span.
	// It starts a new span and sets it as an active span in the context.
	// It then executes the body. It closes the span before returning the execution result.
	WithSpan(
		ctx context.Context,
		operation string,
		body func(ctx context.Context) error,
	) error
}

Jump to

Keyboard shortcuts

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