tracing

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithSpan

func ContextWithSpan(ctx context.Context, span *Span) context.Context

ContextWithSpan adds a span to the context

func TracedFunction

func TracedFunction(tracer *Tracer, name string, fn func(context.Context) error) func(context.Context) error

TracedFunction wraps a function with tracing

Types

type ConsoleExporter

type ConsoleExporter struct{}

ConsoleExporter exports spans to console

func (*ConsoleExporter) Export

func (e *ConsoleExporter) Export(span *Span) error

Export writes span to console

type LogEntry

type LogEntry struct {
	Timestamp time.Time      `json:"timestamp"`
	Fields    map[string]any `json:"fields"`
}

LogEntry represents a log entry within a span

type MemoryExporter

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

MemoryExporter stores spans in memory for testing

func NewMemoryExporter

func NewMemoryExporter() *MemoryExporter

NewMemoryExporter creates a new memory exporter

func (*MemoryExporter) Clear

func (e *MemoryExporter) Clear()

Clear removes all recorded spans

func (*MemoryExporter) Export

func (e *MemoryExporter) Export(span *Span) error

Export stores span in memory

func (*MemoryExporter) GetSpans

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

GetSpans returns all recorded spans

type Span

type Span struct {
	TraceID    string            `json:"trace_id"`
	SpanID     string            `json:"span_id"`
	ParentID   string            `json:"parent_id,omitempty"`
	Name       string            `json:"name"`
	StartTime  time.Time         `json:"start_time"`
	EndTime    time.Time         `json:"end_time,omitempty"`
	Duration   int64             `json:"duration_ms,omitempty"`
	Tags       map[string]string `json:"tags,omitempty"`
	Logs       []LogEntry        `json:"logs,omitempty"`
	Status     SpanStatus        `json:"status"`
	Attributes map[string]any    `json:"attributes,omitempty"`
}

Span represents a single operation within a trace

func SpanFromContext

func SpanFromContext(ctx context.Context) *Span

SpanFromContext retrieves a span from the context

func (*Span) Log

func (s *Span) Log(fields map[string]any)

Log adds a log entry to a span

func (*Span) SetAttribute

func (s *Span) SetAttribute(key string, value any)

SetAttribute adds an attribute to a span

func (*Span) SetError

func (s *Span) SetError(err error)

SetError marks the span as having an error

func (*Span) SetTag

func (s *Span) SetTag(key, value string)

SetTag adds a tag to a span

type SpanExporter

type SpanExporter interface {
	Export(span *Span) error
}

SpanExporter defines the interface for exporting spans

type SpanStats

type SpanStats struct {
	TotalSpans  int
	TotalErrors int
	AvgDuration int64
	MaxDuration int64
	MinDuration int64
	SpanCounts  map[string]int
}

SpanStats provides statistics about spans

type SpanStatus

type SpanStatus int

SpanStatus represents the status of a span

const (
	StatusOK SpanStatus = iota
	StatusError
	StatusCancelled
)

func (SpanStatus) String

func (s SpanStatus) String() string

type Tracer

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

Tracer handles span creation and management

func NewTracer

func NewTracer(enabled bool, exporter SpanExporter) *Tracer

NewTracer creates a new tracer

func NoopTracer

func NoopTracer() *Tracer

NoopTracer returns a tracer that does nothing (for disabling tracing)

func (*Tracer) Finish

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

Finish completes a span and exports it

func (*Tracer) GetStats

func (t *Tracer) GetStats() SpanStats

GetStats returns statistics about recorded spans

func (*Tracer) StartSpan

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

StartSpan begins a new span

Jump to

Keyboard shortcuts

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