trace

package
v0.0.0-...-51b41e4 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrTracerDying is used to indicate to *third parties* that the
	// tracer worker is dying, instead of catacomb.ErrDying, which is
	// unsuitable for propagating inter-worker.
	// This error indicates to consuming workers that their dependency has
	// become unmet and a restart by the dependency engine is imminent.
	ErrTracerDying = errors.ConstError("tracer worker is dying")
)
View Source
const (
	// OTELTraceID is the trace ID key used in the go label.
	OTELTraceID = "otel.traceid"
)

Variables

This section is empty.

Functions

func InjectTracerIfRequired

func InjectTracerIfRequired(ctx context.Context, tracer Tracer) context.Context

InjectTracerIfRequired returns a new context with the given tracer if one isn't already set on the context.

func ScopeFromContext

func ScopeFromContext(ctx context.Context) (string, string, int)

ScopeFromContext returns the traceID, spanID and the flags from the context. Both traceID and spanID can be in the form of a hex string or a raw string.

func TraceIDFromContext

func TraceIDFromContext(ctx context.Context) string

TraceIDFromContext returns the traceID from the context.

func WithSpan

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

WithSpan returns a new context with the given span.

func WithTraceScope

func WithTraceScope(ctx context.Context, traceID, spanID string, flags int) context.Context

WithTraceScope returns a new context with the given trace scope (traceID and spanID).

func WithTracer

func WithTracer(ctx context.Context, tracer Tracer) context.Context

WithTracer returns a new context with the given tracer.

Types

type Attribute

type Attribute interface {
	Key() string
	Value() string
}

Attribute allows you to add additional information to help identify an operation (event, error or span end).

type Int64Attribute

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

Int64Attribute defines an attribute with a string value.

func Int64Attr

func Int64Attr(key string, value int64) Int64Attribute

Int64Attr creates a Int64Attribute.

func (Int64Attribute) Key

func (a Int64Attribute) Key() string

Key defines the identifier for the attribute.

func (Int64Attribute) Value

func (a Int64Attribute) Value() string

Value returns a string.

type IntAttribute

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

IntAttribute defines an attribute with a string value.

func IntAttr

func IntAttr(key string, value int) IntAttribute

IntAttr creates a IntAttribute.

func (IntAttribute) Key

func (a IntAttribute) Key() string

Key defines the identifier for the attribute.

func (IntAttribute) Value

func (a IntAttribute) Value() string

Value returns a string.

type Kind

type Kind string

Kind represents the source of the trace. Either the trace will come from a controller, unit or client. We can expand on these later, for example we can add machine or worker kinds, but for now this is enough.

const (
	KindController Kind = "controller"
	KindUnit       Kind = "unit"
	KindClient     Kind = "client"
)

func (Kind) String

func (k Kind) String() string

type Name

type Name string

Name is the name of the span.

func NameFromFunc

func NameFromFunc() Name

NameFromFunc will return the name from the function. This is useful for automatically generating a name for a span.

func (Name) String

func (n Name) String() string

type NoopScope

type NoopScope struct{}

NoopScope is a scope that does nothing.

func (NoopScope) IsSampled

func (NoopScope) IsSampled() bool

IsSampled returns if the span is sampled.

func (NoopScope) SpanID

func (NoopScope) SpanID() string

SpanID returns the span ID of the span.

func (NoopScope) TraceFlags

func (NoopScope) TraceFlags() int

TraceFlags returns the trace flags of the span.

func (NoopScope) TraceID

func (NoopScope) TraceID() string

TraceID returns the trace ID of the span.

type NoopSpan

type NoopSpan struct{}

NoopSpan is a span that does nothing.

func (NoopSpan) AddEvent

func (NoopSpan) AddEvent(string, ...Attribute)

AddEvent will record an event for this span. This is a manual mechanism for recording an event, it is useful to log information about what happened during the lifetime of a span. This is not the same as a log attached to a span, unfortunately the OpenTelemetry API does not have a way to record logs yet.

func (NoopSpan) End

func (NoopSpan) End(...Attribute)

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.

func (NoopSpan) RecordError

func (NoopSpan) RecordError(error, ...Attribute)

RecordError will record err as an exception span event for this span. If this span is not being recorded or err is nil then this method does nothing. The attributes is lazy and only called if the span is recording.

func (NoopSpan) Scope

func (NoopSpan) Scope() Scope

Scope returns the scope of the span.

type NoopTracer

type NoopTracer struct{}

NoopTracer is a tracer that does nothing.

func (NoopTracer) Enabled

func (NoopTracer) Enabled() bool

func (NoopTracer) Start

func (NoopTracer) Start(ctx context.Context, name string, options ...Option) (context.Context, Span)

type Option

type Option func(*TracerOption)

Option are options that can be passed to the Tracer.Start() method.

func WithAttributes

func WithAttributes(attributes ...Attribute) Option

WithAttributes returns a Option that sets the attributes on the span.

func WithStackTrace

func WithStackTrace() Option

WithStackTrace returns a Option that sets the stack trace on the span.

type Scope

type Scope interface {
	// TraceID returns the trace ID of the span.
	TraceID() string
	// SpanID returns the span ID of the span.
	SpanID() string
	// TraceFlags returns the trace flags of the span.
	TraceFlags() int
	// IsSampled returns if the span is sampled.
	IsSampled() bool
}

Scope is the scope of the span.

type Span

type Span interface {
	// Scope returns the scope of the span. This is useful for identifying
	// the trace and span ID.
	Scope() Scope

	// AddEvent will record an event for this span. This is a manual mechanism
	// for recording an event, it is useful to log information about what
	// happened during the lifetime of a span.
	// This is not the same as a log attached to a span, unfortunately the
	// OpenTelemetry API does not have a way to record logs yet.
	AddEvent(string, ...Attribute)

	// RecordError will record err as an exception span event for this span. If
	// this span is not being recorded or err is nil then this method does
	// nothing.
	// The attributes is lazy and only called if the span is recording.
	RecordError(error, ...Attribute)

	// 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.
	End(...Attribute)
}

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 SpanFromContext

func SpanFromContext(ctx context.Context) Span

SpanFromContext returns a span from the context. If no span is found, an empty span is returned.

func Start

func Start(ctx context.Context, name Name, options ...Option) (context.Context, Span)

Start returns a new context with the given trace.

type StringAttribute

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

StringAttribute defines an attribute with a string value.

func StringAttr

func StringAttr(key, value string) StringAttribute

StringAttr creates a StringAttribute.

func (StringAttribute) Key

func (a StringAttribute) Key() string

Key defines the identifier for the attribute.

func (StringAttribute) Value

func (a StringAttribute) Value() string

Value returns a string.

type TaggedTracerNamespace

type TaggedTracerNamespace struct {
	TracerNamespace
	Tag  names.Tag
	Kind Kind
}

TaggedTracerNamespace is a TracerNamespace with a tag.

func (TaggedTracerNamespace) String

func (ns TaggedTracerNamespace) String() string

type Tracer

type Tracer interface {
	// Start creates a span and a context.Context containing the newly-created
	// span.
	//
	// If the context.Context provided in `ctx` contains a Span then the
	// newly-created Span will be a child of that span, otherwise it will be a
	// root span.
	//
	// Any Span that is created MUST also be ended. This is the responsibility
	// of the user. Implementations of this API may leak memory or other
	// resources if Spans are not ended.
	Start(context.Context, string, ...Option) (context.Context, Span)

	// Enabled returns if the tracer is enabled.
	Enabled() bool
}

Tracer is the interface that all tracers must implement.

func TracerFromContext

func TracerFromContext(ctx context.Context) (Tracer, bool)

TracerFromContext returns a tracer from the context. If no tracer is found, an empty tracer is returned.

type TracerNamespace

type TracerNamespace struct {
	Worker    string
	Namespace string
}

TracerNamespace is a combination of the worker name and the namespace, it allows us to uniquely identify a tracer. Note: the worker doesn't need to be 100% accurate, it is just used to identify the tracer.

func Namespace

func Namespace(worker, namespace string) TracerNamespace

Namespace returns a new namespace.

func (TracerNamespace) ShortNamespace

func (ns TracerNamespace) ShortNamespace() string

ShortNamespace returns a short representation of the namespace.

func (TracerNamespace) String

func (ns TracerNamespace) String() string

String returns a short representation of the namespace.

func (TracerNamespace) WithTagAndKind

func (ns TracerNamespace) WithTagAndKind(tag names.Tag, kind Kind) TaggedTracerNamespace

WithTagAndKind returns a new TaggedTracerNamespace.

type TracerOption

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

TracerOption is an option that can be passed to the Tracer.Start() method.

func NewTracerOptions

func NewTracerOptions() *TracerOption

NewTracerOptions returns a new tracerOption.

func (*TracerOption) Attributes

func (t *TracerOption) Attributes() []Attribute

Attributes returns a slice of attributes for creating a span.

func (*TracerOption) StackTrace

func (t *TracerOption) StackTrace() bool

StackTrace returns if the stack trace is enabled on the span on errors.

Jump to

Keyboard shortcuts

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