Documentation
¶
Overview ¶
Package telemetry provides OpenTelemetry tracing, metrics, and Prometheus exporter setup.
Index ¶
- Variables
- type Attr
- type Config
- type Counter
- type Gauge
- type Histogram
- type HistogramOption
- type Int64Observer
- type Meter
- func (m *Meter) Counter(name, desc string) (*Counter, error)
- func (m *Meter) Gauge(name, desc string) (*Gauge, error)
- func (m *Meter) Histogram(name, desc string, opts ...HistogramOption) (*Histogram, error)
- func (m *Meter) Int64ObservableGauge(name, desc string, cb ObservableGaugeCallback) error
- func (m *Meter) MustCounter(name, desc string) *Counter
- func (m *Meter) MustGauge(name, desc string) *Gauge
- func (m *Meter) MustHistogram(name, desc string, opts ...HistogramOption) *Histogram
- func (m *Meter) MustUpDownCounter(name, desc string) *UpDownCounter
- func (m *Meter) UpDownCounter(name, desc string) (*UpDownCounter, error)
- type ObservableGaugeCallback
- type Telemetry
- type UpDownCounter
- func (g *UpDownCounter) Add(ctx context.Context, value int64, attrs ...attribute.KeyValue)
- func (g *UpDownCounter) AddKV(ctx context.Context, value int64, kv ...any)
- func (g *UpDownCounter) Dec(ctx context.Context, attrs ...attribute.KeyValue)
- func (g *UpDownCounter) DecKV(ctx context.Context, kv ...any)
- func (g *UpDownCounter) Inc(ctx context.Context, attrs ...attribute.KeyValue)
- func (g *UpDownCounter) IncKV(ctx context.Context, kv ...any)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrServiceNameRequired indicates service name is missing. ErrServiceNameRequired = errors.New("service_name is required") // ErrServiceVersionRequired indicates service version is missing. ErrServiceVersionRequired = errors.New("service_version is required") // ErrEnvironmentRequired indicates environment is missing. ErrEnvironmentRequired = errors.New("environment is required") // ErrIntervalRequired indicates metrics interval must be positive. ErrIntervalRequired = errors.New("interval must be greater than 0") // ErrNoExportersEnabled indicates no telemetry exporters are enabled. ErrNoExportersEnabled = errors.New("at least one exporter (OTLP or Prometheus) must be enabled") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ServiceName string `toml:"service_name" env:"OTEL_SERVICE_NAME" env-default:"unknown_service"`
ServiceVersion string `toml:"service_version" env:"OTEL_SERVICE_VERSION" env-default:"0.0.1"`
Environment string `toml:"environment" env:"ENV" env-default:"production"`
OTLPEndpoint string `toml:"otel_endpoint" env:"OTEL_EXPORTER_OTLP_ENDPOINT" env-default:"localhost:4317"`
OTLPInsecure bool `toml:"otel_insecure" env:"OTEL_EXPORTER_OTLP_INSECURE" env-default:"true"`
PrometheusEnabled bool `toml:"prometheus_enabled" env:"METRICS_PROMETHEUS_ENABLED" env-default:"true"`
Interval time.Duration `toml:"interval" env:"OTEL_INTERVAL" env-default:"15s"`
}
Config defines OpenTelemetry and Prometheus configuration parameters.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter wraps an OpenTelemetry Int64Counter with dynamic MeterProvider resolution.
func MustCounter ¶
MustCounter creates a Counter on the default scope or panics on failure.
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge wraps an OpenTelemetry Float64Gauge with dynamic MeterProvider resolution.
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram wraps an OpenTelemetry Float64Histogram with dynamic MeterProvider resolution.
func MustHistogram ¶
func MustHistogram(name, desc string, opts ...HistogramOption) *Histogram
MustHistogram creates a Histogram on the default scope or panics on failure.
type HistogramOption ¶
type HistogramOption func(*histogramConfig)
HistogramOption configures histogram instrument parameters.
func WithBuckets ¶
func WithBuckets(buckets []float64) HistogramOption
WithBuckets sets custom histogram bucket boundaries.
type Int64Observer ¶
type Int64Observer struct {
// contains filtered or unexported fields
}
Int64Observer wraps an asynchronous OpenTelemetry Int64Observer.
func (*Int64Observer) Observe ¶
func (o *Int64Observer) Observe(value int64, attrs ...attribute.KeyValue)
Observe records a value with explicit attributes.
func (*Int64Observer) ObserveKV ¶
func (o *Int64Observer) ObserveKV(value int64, kv ...any)
ObserveKV records a value with key-value pair attributes.
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter provides scoped metric instrument creation.
func (*Meter) Histogram ¶
func (m *Meter) Histogram(name, desc string, opts ...HistogramOption) (*Histogram, error)
Histogram creates a new Histogram.
func (*Meter) Int64ObservableGauge ¶
func (m *Meter) Int64ObservableGauge(name, desc string, cb ObservableGaugeCallback) error
Int64ObservableGauge registers an asynchronous gauge metric callback.
func (*Meter) MustCounter ¶
MustCounter creates a new Counter or panics on failure.
func (*Meter) MustHistogram ¶
func (m *Meter) MustHistogram(name, desc string, opts ...HistogramOption) *Histogram
MustHistogram creates a new Histogram or panics on failure.
func (*Meter) MustUpDownCounter ¶
func (m *Meter) MustUpDownCounter(name, desc string) *UpDownCounter
MustUpDownCounter creates a new UpDownCounter or panics on failure.
func (*Meter) UpDownCounter ¶
func (m *Meter) UpDownCounter(name, desc string) (*UpDownCounter, error)
UpDownCounter creates a new UpDownCounter.
type ObservableGaugeCallback ¶
type ObservableGaugeCallback func(ctx context.Context, obs *Int64Observer) error
ObservableGaugeCallback is invoked during asynchronous metric collection.
type Telemetry ¶
type Telemetry struct {
// contains filtered or unexported fields
}
Telemetry manages lifecycle for tracer and meter providers.
func Setup ¶
Setup initializes global TracerProvider and MeterProvider instances based on configuration.
type UpDownCounter ¶
type UpDownCounter struct {
// contains filtered or unexported fields
}
UpDownCounter wraps an OpenTelemetry Int64UpDownCounter with dynamic MeterProvider resolution.
func MustUpDownCounter ¶
func MustUpDownCounter(name, desc string) *UpDownCounter
MustUpDownCounter creates an UpDownCounter on the default scope or panics on failure.
func (*UpDownCounter) AddKV ¶
func (g *UpDownCounter) AddKV(ctx context.Context, value int64, kv ...any)
AddKV adds value to the counter with key-value pair attributes.
func (*UpDownCounter) Dec ¶
func (g *UpDownCounter) Dec(ctx context.Context, attrs ...attribute.KeyValue)
Dec decrements the counter by 1 with explicit attributes.
func (*UpDownCounter) DecKV ¶
func (g *UpDownCounter) DecKV(ctx context.Context, kv ...any)
DecKV decrements the counter by 1 with key-value pair attributes.