Version: v1.6.0 Latest Latest

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 1 Imported by: 2



Package tracing contains the definitions needed to support distributed tracing.



This section is empty.


This section is empty.


This section is empty.


type Attribute

type Attribute struct {
	// Key is the name of the attribute.
	Key string

	// Value is the attribute's value.
	// Types that are natively supported include int64, float64, int, bool, string.
	// Any other type will be formatted per rules of fmt.Sprintf("%v").
	Value any

Attribute is a key-value pair.

type Provider

type Provider struct {
	// contains filtered or unexported fields

Provider is the factory that creates Tracer instances. It defaults to a no-op provider.

func NewProvider

func NewProvider(newTracerFn func(name, version string) Tracer, options *ProviderOptions) Provider

NewProvider creates a new Provider with the specified values.

  • newTracerFn is the underlying implementation for creating Tracer instances
  • options contains optional values; pass nil to accept the default value

func (Provider) NewTracer

func (p Provider) NewTracer(name, version string) (tracer Tracer)

NewTracer creates a new Tracer for the specified name and version.

  • name - the name of the tracer object, typically the fully qualified name of the service client
  • version - the version of the module in which the service client resides

type ProviderOptions

type ProviderOptions struct {

ProviderOptions contains the optional values when creating a Provider.

type Span

type Span struct {
	// contains filtered or unexported fields

Span is a single unit of a trace. A trace can contain multiple spans. A zero-value Span provides a no-op implementation.

func NewSpan

func NewSpan(impl SpanImpl) Span

NewSpan creates a Span with the specified implementation.

func (Span) AddError

func (s Span) AddError(err error)

AddError adds the specified error event to the span.

func (Span) AddEvent

func (s Span) AddEvent(name string, attrs ...Attribute)

AddEvent adds a named event with an optional set of attributes to the span.

func (Span) End

func (s Span) End()

End terminates the span and MUST be called before the span leaves scope. Any further updates to the span will be ignored after End is called.

func (Span) SetAttributes

func (s Span) SetAttributes(attrs ...Attribute)

SetAttributes sets the specified attributes on the Span. Any existing attributes with the same keys will have their values overwritten.

func (Span) SetStatus

func (s Span) SetStatus(code SpanStatus, desc string)

SetStatus sets the status on the span along with a description.

type SpanImpl

type SpanImpl struct {
	// End contains the implementation for the Span.End method.
	End func()

	// SetAttributes contains the implementation for the Span.SetAttributes method.
	SetAttributes func(...Attribute)

	// AddEvent contains the implementation for the Span.AddEvent method.
	AddEvent func(string, ...Attribute)

	// AddError contains the implementation for the Span.AddError method.
	AddError func(err error)

	// SetStatus contains the implementation for the Span.SetStatus method.
	SetStatus func(SpanStatus, string)

SpanImpl abstracts the underlying implementation for Span, allowing it to work with various tracing implementations. Any zero-values will have their default, no-op behavior.

type SpanKind

type SpanKind int

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 indicates the span represents an internal operation within an application.
	SpanKindInternal SpanKind = 1

	// SpanKindServer indicates the span covers server-side handling of a request.
	SpanKindServer SpanKind = 2

	// SpanKindClient indicates the span describes a request to a remote service.
	SpanKindClient SpanKind = 3

	// SpanKindProducer indicates the span was created by a messaging producer.
	SpanKindProducer SpanKind = 4

	// SpanKindConsumer indicates the span was created by a messaging consumer.
	SpanKindConsumer SpanKind = 5

type SpanOptions

type SpanOptions struct {
	// Kind indicates the kind of Span.
	Kind SpanKind

	// Attributes contains key-value pairs of attributes for the span.
	Attributes []Attribute

SpanOptions contains optional settings for creating a span.

type SpanStatus

type SpanStatus int

SpanStatus represents the status of a span.

const (
	// SpanStatusUnset is the default status code.
	SpanStatusUnset SpanStatus = 0

	// SpanStatusError indicates the operation contains an error.
	SpanStatusError SpanStatus = 1

	// SpanStatusOK indicates the operation completed successfully.
	SpanStatusOK SpanStatus = 2

type Tracer

type Tracer struct {
	// contains filtered or unexported fields

Tracer is the factory that creates Span instances.

func NewTracer

func NewTracer(newSpanFn func(ctx context.Context, spanName string, options *SpanOptions) (context.Context, Span), options *TracerOptions) Tracer

NewTracer creates a Tracer with the specified values.

  • newSpanFn is the underlying implementation for creating Span instances
  • options contains optional values; pass nil to accept the default value

func (Tracer) Start

func (t Tracer) Start(ctx context.Context, spanName string, options *SpanOptions) (context.Context, Span)

Start creates a new span and a context.Context that contains it.

  • ctx is the parent context for this span. If it contains a Span, the newly created span will be a child of that span, else it will be a root span
  • spanName identifies the span within a trace, it's typically the fully qualified API name
  • options contains optional values for the span, pass nil to accept any defaults

type TracerOptions

type TracerOptions struct {

TracerOptions contains the optional values when creating a Tracer.

Jump to

Keyboard shortcuts

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