tracing

package
v1.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSpanAttribute

func AddSpanAttribute(span *Span, key, value string)

AddSpanAttribute adds attribute using global tracer

func AddSpanEvent

func AddSpanEvent(span *Span, name string, attributes map[string]string)

AddSpanEvent adds event using global tracer

func EndSpan

func EndSpan(span *Span)

EndSpan ends a span using global tracer

func InitTracer

func InitTracer(serviceName string)

InitTracer initializes global tracer

func SetSpanError

func SetSpanError(span *Span, err error)

SetSpanError sets span error using global tracer

Types

type Exporter

type Exporter interface {
	ExportSpan(span *Span) error
}

Exporter exports spans to external system

type InMemoryExporter

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

InMemoryExporter stores spans in memory for testing

func NewInMemoryExporter

func NewInMemoryExporter() *InMemoryExporter

NewInMemoryExporter creates a new in-memory exporter

func (*InMemoryExporter) Clear

func (e *InMemoryExporter) Clear()

Clear clears all stored spans

func (*InMemoryExporter) ExportSpan

func (e *InMemoryExporter) ExportSpan(span *Span) error

ExportSpan stores span in memory

func (*InMemoryExporter) GetSpans

func (e *InMemoryExporter) GetSpans() []*Span

GetSpans returns all stored spans

type NoOpExporter

type NoOpExporter struct{}

NoOpExporter does nothing with spans

func (*NoOpExporter) ExportSpan

func (e *NoOpExporter) ExportSpan(span *Span) error

ExportSpan implements Exporter interface

type Span

type Span struct {
	TraceID    TraceID           `json:"trace_id"`
	SpanID     SpanID            `json:"span_id"`
	ParentID   SpanID            `json:"parent_id,omitempty"`
	Name       string            `json:"name"`
	Kind       SpanKind          `json:"kind"`
	StartTime  time.Time         `json:"start_time"`
	EndTime    time.Time         `json:"end_time"`
	Duration   time.Duration     `json:"duration"`
	Attributes map[string]string `json:"attributes,omitempty"`
	Events     []SpanEvent       `json:"events,omitempty"`
	Status     SpanStatus        `json:"status"`
	Error      string            `json:"error,omitempty"`
}

Span represents a trace span

func StartSpan

func StartSpan(ctx context.Context, name string, kind SpanKind) (*Span, context.Context)

StartSpan starts a span using global tracer

type SpanEvent

type SpanEvent struct {
	Timestamp  time.Time         `json:"timestamp"`
	Name       string            `json:"name"`
	Attributes map[string]string `json:"attributes,omitempty"`
}

SpanEvent represents an event within a span

type SpanID

type SpanID string

SpanID represents a unique span identifier

type SpanKind

type SpanKind string

SpanKind represents the kind of span

const (
	// SpanKindClient indicates a client span
	SpanKindClient SpanKind = "client"

	// SpanKindServer indicates a server span
	SpanKindServer SpanKind = "server"

	// SpanKindInternal indicates an internal span
	SpanKindInternal SpanKind = "internal"

	// SpanKindProducer indicates a producer span
	SpanKindProducer SpanKind = "producer"

	// SpanKindConsumer indicates a consumer span
	SpanKindConsumer SpanKind = "consumer"
)

type SpanStatus

type SpanStatus string

SpanStatus represents span status

const (
	// SpanStatusUnset indicates status is unset
	SpanStatusUnset SpanStatus = "unset"

	// SpanStatusOK indicates success
	SpanStatusOK SpanStatus = "ok"

	// SpanStatusError indicates an error
	SpanStatusError SpanStatus = "error"
)

type TraceID

type TraceID string

TraceID represents a unique trace identifier

type Tracer

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

Tracer creates and manages spans

func GetTracer

func GetTracer() *Tracer

GetTracer returns global tracer

func NewTracer

func NewTracer(serviceName string) *Tracer

NewTracer creates a new tracer

func (*Tracer) AddSpanAttribute

func (t *Tracer) AddSpanAttribute(span *Span, key, value string)

AddSpanAttribute adds an attribute to span

func (*Tracer) AddSpanEvent

func (t *Tracer) AddSpanEvent(span *Span, name string, attributes map[string]string)

AddSpanEvent adds an event to span

func (*Tracer) EndSpan

func (t *Tracer) EndSpan(span *Span)

EndSpan ends a span

func (*Tracer) GetTrace

func (t *Tracer) GetTrace(traceID TraceID) []*Span

GetTrace retrieves all spans for a trace

func (*Tracer) SetExporter

func (t *Tracer) SetExporter(exporter Exporter)

SetExporter sets the span exporter

func (*Tracer) SetSpanError

func (t *Tracer) SetSpanError(span *Span, err error)

SetSpanError sets span error status

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(ctx context.Context, name string, kind SpanKind) (*Span, context.Context)

StartSpan starts a new span

Jump to

Keyboard shortcuts

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