Documentation
¶
Index ¶
- func ContextWithSpan(ctx context.Context, span *Span) context.Context
- func TracedFunction(tracer *Tracer, name string, fn func(context.Context) error) func(context.Context) error
- type ConsoleExporter
- type LogEntry
- type MemoryExporter
- type Span
- type SpanExporter
- type SpanStats
- type SpanStatus
- type Tracer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithSpan ¶
ContextWithSpan adds a span to the context
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) 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 ¶
SpanFromContext retrieves a span from the context
func (*Span) SetAttribute ¶
SetAttribute adds an attribute to a span
type SpanExporter ¶
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)