Documentation
¶
Index ¶
- func GetSpanID(ctx context.Context) string
- func GetTraceID(ctx context.Context) string
- func IsSampled(ctx context.Context) bool
- type AlwaysSampler
- type BatchSpanProcessor
- type ConsoleExporter
- type DistributedTracer
- func (d *DistributedTracer) GetFactory() *TracerFactory
- func (d *DistributedTracer) GetTracer() *Tracer
- func (d *DistributedTracer) Shutdown(ctx context.Context) error
- func (d *DistributedTracer) TraceBusinessOperation(ctx context.Context, name string, attrs map[string]interface{}, ...) error
- func (d *DistributedTracer) TraceCacheOperation(ctx context.Context, operation, key string, fn func(ctx context.Context) error) error
- func (d *DistributedTracer) TraceDBQuery(ctx context.Context, query string, fn func(ctx context.Context) error) error
- func (d *DistributedTracer) TraceHTTPCall(ctx context.Context, method, url string, fn func(ctx context.Context) error) error
- type DistributedTracingConfig
- type NeverSampler
- type Sampler
- type SimpleSpanProcessor
- type Span
- type SpanEvent
- type SpanExporter
- type SpanKind
- type SpanProcessor
- type SpanStartOption
- type SpanStatus
- type SpanStatusCode
- type TraceIDRatioBased
- type TracedOperation
- type Tracer
- func (t *Tracer) AddEvent(span *Span, name string, attrs map[string]interface{})
- func (t *Tracer) End(span *Span, err error)
- func (t *Tracer) SetAttributes(span *Span, attrs map[string]interface{})
- func (t *Tracer) SetStatus(span *Span, code SpanStatusCode, message string)
- func (t *Tracer) Shutdown(ctx context.Context) error
- func (t *Tracer) Start(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, *Span)
- type TracerConfig
- type TracerFactory
- type TracerMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTraceID ¶
GetTraceID gets the trace ID from context
Types ¶
type AlwaysSampler ¶
type AlwaysSampler struct{}
AlwaysSampler always samples
func (*AlwaysSampler) ShouldSample ¶
func (a *AlwaysSampler) ShouldSample(traceID string) bool
type BatchSpanProcessor ¶
type BatchSpanProcessor struct {
// contains filtered or unexported fields
}
BatchSpanProcessor processes spans in batches
func NewBatchSpanProcessor ¶
func NewBatchSpanProcessor(exporter SpanExporter, batchSize int, timeout time.Duration) *BatchSpanProcessor
NewBatchSpanProcessor creates a new batch span processor
func (*BatchSpanProcessor) Flush ¶
func (b *BatchSpanProcessor) Flush()
Flush flushes the current batch
func (*BatchSpanProcessor) OnEnd ¶
func (b *BatchSpanProcessor) OnEnd(span *Span)
OnEnd processes a span when it ends
type ConsoleExporter ¶
type ConsoleExporter struct{}
ConsoleExporter exports spans to the console
func NewConsoleExporter ¶
func NewConsoleExporter() *ConsoleExporter
NewConsoleExporter creates a new console exporter
func (*ConsoleExporter) Export ¶
func (c *ConsoleExporter) Export(span *Span) error
Export exports a span to the console
type DistributedTracer ¶
type DistributedTracer struct {
// contains filtered or unexported fields
}
DistributedTracer represents a distributed tracer
func NewDistributedTracer ¶
func NewDistributedTracer(config DistributedTracingConfig) (*DistributedTracer, error)
NewDistributedTracer creates a new distributed tracer
func (*DistributedTracer) GetFactory ¶
func (d *DistributedTracer) GetFactory() *TracerFactory
GetFactory gets the factory
func (*DistributedTracer) GetTracer ¶
func (d *DistributedTracer) GetTracer() *Tracer
GetTracer gets the tracer
func (*DistributedTracer) Shutdown ¶
func (d *DistributedTracer) Shutdown(ctx context.Context) error
Shutdown shuts down the tracer
func (*DistributedTracer) TraceBusinessOperation ¶
func (d *DistributedTracer) TraceBusinessOperation(ctx context.Context, name string, attrs map[string]interface{}, fn func(ctx context.Context) error) error
TraceBusinessOperation traces a business operation
func (*DistributedTracer) TraceCacheOperation ¶
func (d *DistributedTracer) TraceCacheOperation(ctx context.Context, operation, key string, fn func(ctx context.Context) error) error
TraceCacheOperation traces a cache operation
func (*DistributedTracer) TraceDBQuery ¶
func (d *DistributedTracer) TraceDBQuery(ctx context.Context, query string, fn func(ctx context.Context) error) error
TraceDBQuery traces a database query
func (*DistributedTracer) TraceHTTPCall ¶
func (d *DistributedTracer) TraceHTTPCall(ctx context.Context, method, url string, fn func(ctx context.Context) error) error
TraceHTTPCall traces an HTTP call
type DistributedTracingConfig ¶
type DistributedTracingConfig struct {
Enable bool
ServiceName string
ServiceVersion string
SamplingRate float64
EnableBatching bool
BatchTimeout time.Duration
EnableMiddleware bool
EnableDBTracing bool
EnableCacheTracing bool
EnableHTTPTracing bool
}
DistributedTracingConfig represents the configuration for distributed tracing
func DefaultDistributedTracingConfig ¶
func DefaultDistributedTracingConfig(serviceName string) DistributedTracingConfig
DefaultDistributedTracingConfig creates a default distributed tracing configuration
type NeverSampler ¶
type NeverSampler struct{}
NeverSampler never samples
func (*NeverSampler) ShouldSample ¶
func (n *NeverSampler) ShouldSample(traceID string) bool
type SimpleSpanProcessor ¶
type SimpleSpanProcessor struct {
// contains filtered or unexported fields
}
SimpleSpanProcessor is a simple span processor
func NewSimpleSpanProcessor ¶
func NewSimpleSpanProcessor() *SimpleSpanProcessor
NewSimpleSpanProcessor creates a new simple span processor
func (*SimpleSpanProcessor) OnEnd ¶
func (s *SimpleSpanProcessor) OnEnd(span *Span)
OnEnd processes a span when it ends
type Span ¶
type Span struct {
TraceID string
SpanID string
ParentID string
Name string
StartTime time.Time
EndTime time.Time
Attributes map[string]interface{}
Events []SpanEvent
Status SpanStatus
Kind SpanKind
}
Span represents a single operation within a trace
type SpanExporter ¶
SpanExporter exports spans
type SpanProcessor ¶
SpanProcessor processes spans
type SpanStartOption ¶
type SpanStartOption func(*Span)
SpanStartOption represents a span start option
func WithAttributes ¶
func WithAttributes(attrs map[string]interface{}) SpanStartOption
WithAttributes sets attributes
func WithParentID ¶
func WithParentID(parentID string) SpanStartOption
WithParentID sets the parent span ID
func WithSpanKind ¶
func WithSpanKind(kind SpanKind) SpanStartOption
WithSpanKind sets the span kind
type SpanStatus ¶
type SpanStatus struct {
Code SpanStatusCode
Message string
}
SpanStatus represents the status of a span
type SpanStatusCode ¶
type SpanStatusCode int
SpanStatusCode represents the status code of a span
const ( StatusCodeUnset SpanStatusCode = 0 StatusCodeOK SpanStatusCode = 1 StatusCodeError SpanStatusCode = 2 )
type TraceIDRatioBased ¶
type TraceIDRatioBased struct {
// contains filtered or unexported fields
}
TraceIDRatioBased samples based on a ratio
func NewTraceIDRatioBased ¶
func NewTraceIDRatioBased(ratio float64) *TraceIDRatioBased
NewTraceIDRatioBased creates a new trace ID ratio based sampler
func (*TraceIDRatioBased) ShouldSample ¶
func (t *TraceIDRatioBased) ShouldSample(traceID string) bool
type TracedOperation ¶
type TracedOperation struct {
// contains filtered or unexported fields
}
TracedOperation represents a traced operation
func NewTracedOperation ¶
func NewTracedOperation(tracer *Tracer, name string) *TracedOperation
NewTracedOperation creates a new traced operation
func (*TracedOperation) ExecuteWithResult ¶
func (t *TracedOperation) ExecuteWithResult(ctx context.Context, fn func(ctx context.Context) (interface{}, error)) (interface{}, error)
ExecuteWithResult executes a function with tracing and returns a result
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer represents a distributed tracing tracer
func NewTracer ¶
func NewTracer(config TracerConfig) (*Tracer, error)
NewTracer creates a new tracer
func (*Tracer) SetAttributes ¶
SetAttributes sets attributes on a span
func (*Tracer) SetStatus ¶
func (t *Tracer) SetStatus(span *Span, code SpanStatusCode, message string)
SetStatus sets the status of a span
type TracerConfig ¶
type TracerConfig struct {
ServiceName string
ServiceVersion string
SamplingRate float64
Processor SpanProcessor
}
TracerConfig represents the configuration for a tracer
func DefaultTracerConfig ¶
func DefaultTracerConfig(serviceName string) TracerConfig
DefaultTracerConfig creates a default tracer configuration
type TracerFactory ¶
type TracerFactory struct {
// contains filtered or unexported fields
}
TracerFactory creates and manages tracers
func NewTracerFactory ¶
func NewTracerFactory() *TracerFactory
NewTracerFactory creates a new tracer factory
func (*TracerFactory) GetTracer ¶
func (f *TracerFactory) GetTracer(serviceName string) (*Tracer, error)
GetTracer gets or creates a tracer
func (*TracerFactory) GetTracerWithConfig ¶
func (f *TracerFactory) GetTracerWithConfig(config TracerConfig) (*Tracer, error)
GetTracerWithConfig gets a tracer with specific configuration
func (*TracerFactory) ShutdownAll ¶
func (f *TracerFactory) ShutdownAll(ctx context.Context) error
ShutdownAll shuts down all tracers
type TracerMiddleware ¶
type TracerMiddleware struct {
// contains filtered or unexported fields
}
TracerMiddleware is a middleware for HTTP tracing
func NewTracerMiddleware ¶
func NewTracerMiddleware(tracer *Tracer) *TracerMiddleware
NewTracerMiddleware creates a new tracer middleware
func (*TracerMiddleware) Middleware ¶
func (m *TracerMiddleware) Middleware(next http.Handler) http.Handler
Middleware wraps an HTTP handler with tracing