span

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package span provides the Span type for representing units of work with timing information and hierarchical structure.

A Span records when an operation started and ended, maintains parent-child relationships with other spans, and can hold attributes and events. Spans are thread-safe for concurrent access.

Use this package when you need to create and manipulate spans directly. For context-based span propagation, use the parent trace package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(opts *spanOptions)

Option configures a spanOptions instance.

func WithEndCallback

func WithEndCallback(callback func(*Span)) Option

WithEndCallback provides an Option to set a callback that is invoked when the span ends.

type Span

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

Span represents a unit of work with timing information and hierarchical structure.

func New

func New(name string, traceID string, parent *Span, opts ...Option) *Span

New creates a new span with the given name, trace ID, and optional parent. If a parent is provided, the new span is added as a child of the parent.

func (*Span) AddEvent

func (s *Span) AddEvent(e *event.Event)

AddEvent adds an event to the span.

func (*Span) Attributes

func (s *Span) Attributes() []*attribute.Attribute

Attributes returns a copy of all attributes on the span.

func (*Span) Children

func (s *Span) Children() []*Span

Children returns a copy of the child spans.

func (*Span) Duration

func (s *Span) Duration() time.Duration

Duration returns the time elapsed between start and end.

func (*Span) End

func (s *Span) End()

End marks the span as complete by recording the end time. Only the first call has any effect; subsequent calls are ignored.

func (*Span) EndTime

func (s *Span) EndTime() time.Time

EndTime returns when the span ended.

func (*Span) Events

func (s *Span) Events() []*event.Event

Events returns a copy of all events on the span.

func (*Span) Name

func (s *Span) Name() string

Name returns the name of the span.

func (*Span) Parent

func (s *Span) Parent() *Span

Parent returns the parent span, or nil if this is a root span.

func (*Span) RecordError

func (s *Span) RecordError(err error)

RecordError records an error on the span by setting the status to Error and adding an error event.

func (*Span) SetAttributes

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

SetAttributes sets attributes on the span.

func (*Span) SetStatusCode

func (s *Span) SetStatusCode(code status.Code)

SetStatusCode sets the status code on the span.

func (*Span) SpanID

func (s *Span) SpanID() string

SpanID returns the unique identifier for this span within its hierarchy. This should NOT be used as a globally unique identifier. A unique identifier for a span is a combination of an application ID, a TraceID, and a SpanID.

func (*Span) StartTime

func (s *Span) StartTime() time.Time

StartTime returns when the span started.

func (*Span) StatusCode

func (s *Span) StatusCode() status.Code

StatusCode returns the status code of the span.

func (*Span) TraceID

func (s *Span) TraceID() string

TraceID returns the distributed trace ID of the span. This should NOT be used as a globally unique identifier. A unique identifier for a span is a combination of an application ID, a TraceID, and a SpanID.

Jump to

Keyboard shortcuts

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