telemetry

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Timed

func Timed(ctx context.Context, h Histogram, fn func()) time.Duration

Timed measures and records the duration of fn as a metric.

Types

type Attribute

type Attribute struct {
	Key   string
	Value any
}

Attribute is a key-value pair for spans and metrics.

type Counter

type Counter interface {
	Add(ctx context.Context, delta int64)
}

Counter records monotonically increasing values.

type Gauge

type Gauge interface {
	Set(ctx context.Context, value float64)
}

Gauge records current values.

type Histogram

type Histogram interface {
	Record(ctx context.Context, value float64)
}

Histogram records distribution of values.

type Meter

type Meter interface {
	Counter(name string, attrs ...Attribute) Counter
	Histogram(name string, attrs ...Attribute) Histogram
	Gauge(name string, attrs ...Attribute) Gauge
}

Meter creates and records metrics.

type OTLPExporter

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

OTLPExporter sends spans and metrics to an OTLP-compatible endpoint over HTTP/JSON.

func NewOTLPExporter

func NewOTLPExporter(opts ...OTLPOption) *OTLPExporter

NewOTLPExporter creates a new OTLPExporter with the given options.

func (*OTLPExporter) Close

func (e *OTLPExporter) Close()

func (*OTLPExporter) ExportMetric

func (e *OTLPExporter) ExportMetric(m otlpMetric)

func (*OTLPExporter) ExportSpan

func (e *OTLPExporter) ExportSpan(span otlpSpan)

func (*OTLPExporter) Flush

func (e *OTLPExporter) Flush(ctx context.Context) error

type OTLPOption

type OTLPOption func(*OTLPExporter)

OTLPOption configures an OTLPExporter.

func WithOTLPBatchSize

func WithOTLPBatchSize(n int) OTLPOption

WithOTLPBatchSize sets the maximum batch size before flushing.

func WithOTLPEndpoint

func WithOTLPEndpoint(url string) OTLPOption

WithOTLPEndpoint sets the OTLP receiver endpoint URL.

type Option

type Option = options.Option[Provider]

Option configures a Provider.

func WithMeter

func WithMeter(m Meter) Option

WithMeter sets the meter implementation.

func WithTracer

func WithTracer(t Tracer) Option

WithTracer sets the tracer implementation.

type PrometheusExporter

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

func NewPrometheusExporter

func NewPrometheusExporter() *PrometheusExporter

NewPrometheusExporter creates a new PrometheusExporter.

func (*PrometheusExporter) IncCounter

func (p *PrometheusExporter) IncCounter(name string, delta int64)

func (*PrometheusExporter) ObserveHistogram

func (p *PrometheusExporter) ObserveHistogram(name string, value float64, buckets []float64)

func (*PrometheusExporter) SetGauge

func (p *PrometheusExporter) SetGauge(name string, value float64)

func (*PrometheusExporter) WriteText

func (p *PrometheusExporter) WriteText(w io.Writer)

type Provider

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

Provider is the central telemetry hub.

func NewProvider

func NewProvider(opts ...Option) *Provider

NewProvider creates a telemetry provider with noop defaults.

func (*Provider) Shutdown

func (p *Provider) Shutdown()

Shutdown cleans up all providers.

type SimpleMeter

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

SimpleMeter is a basic meter that stores counters in memory.

func NewSimpleMeter

func NewSimpleMeter() *SimpleMeter

NewSimpleMeter creates a SimpleMeter.

func (*SimpleMeter) Counter

func (m *SimpleMeter) Counter(name string, attrs ...Attribute) Counter

func (*SimpleMeter) Gauge

func (m *SimpleMeter) Gauge(name string, attrs ...Attribute) Gauge

func (*SimpleMeter) GetCounter

func (m *SimpleMeter) GetCounter(name string) int64

GetCounter returns the current counter value by name.

func (*SimpleMeter) GetGauge

func (m *SimpleMeter) GetGauge(name string) float64

GetGauge returns the current gauge value by name.

func (*SimpleMeter) Histogram

func (m *SimpleMeter) Histogram(name string, attrs ...Attribute) Histogram

type SimpleTracer

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

SimpleTracer is a basic tracer that logs span starts and ends to stderr.

func NewSimpleTracer

func NewSimpleTracer() *SimpleTracer

NewSimpleTracer creates a SimpleTracer.

func (*SimpleTracer) Start

func (s *SimpleTracer) Start(ctx context.Context, name string, attrs ...Attribute) (Span, context.Context)

type Span

type Span interface {
	SetAttributes(attrs ...Attribute)
	End()
}

Span represents an active span in a trace.

type TelemetryMiddleware

type TelemetryMiddleware struct {
	Provider *Provider
}

func NewTelemetryMiddleware

func NewTelemetryMiddleware(provider *Provider) *TelemetryMiddleware

NewTelemetryMiddleware creates a new TelemetryMiddleware wrapping the given provider.

func (*TelemetryMiddleware) WrapHTTP

func (tm *TelemetryMiddleware) WrapHTTP(next http.Handler) http.Handler

SrvMiddleware returns a middleware function compatible with the srv package. It accepts a HandlerFunc type to avoid circular import - use via adapter.

type TraceContext

type TraceContext struct {
	TraceID    string
	ParentID   string
	TraceFlags string
}

func ParseTraceparent

func ParseTraceparent(header string) (*TraceContext, error)

ParseTraceparent parses a W3C traceparent header.

func (*TraceContext) Encode

func (tc *TraceContext) Encode() string

type Tracer

type Tracer interface {
	Start(ctx context.Context, name string, attrs ...Attribute) (Span, context.Context)
}

Tracer creates and manages spans.

Jump to

Keyboard shortcuts

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