Documentation
ΒΆ
Index ΒΆ
- Variables
- type Attribute
- func BoolAttr(key string, value bool) Attribute
- func ErrorAttrs(err error) []Attribute
- func Float64Attr(key string, value float64) Attribute
- func GRPCAttrs(method, code string) []Attribute
- func GRPCMethodAttrs(method string) []Attribute
- func HTTPAttrs(method, endpoint, status string) []Attribute
- func HTTPEndpointAttrs(endpoint string) []Attribute
- func HTTPMethodAttrs(method string) []Attribute
- func Int64Attr(key string, value int64) Attribute
- func IntAttr(key string, value int) Attribute
- func StatusAttrs(status string) []Attribute
- func StringAttr(key, value string) Attribute
- func TypeAttrs(typ string) []Attribute
- func WorkerAttrs(workerName string) []Attribute
- func WorkerErrorAttrs(workerName string, err error) []Attribute
- type AttributeBuilder
- func (ab *AttributeBuilder) Bool(key string, value bool) Attribute
- func (ab *AttributeBuilder) Float64(key string, value float64) Attribute
- func (ab *AttributeBuilder) Int(key string, value int) Attribute
- func (ab *AttributeBuilder) Int64(key string, value int64) Attribute
- func (ab *AttributeBuilder) String(key, value string) Attribute
- type Config
- type CounterBuilder
- type CounterMetric
- type GaugeBuilder
- type GaugeMetric
- type HistogramBuilder
- type HistogramMetric
- type MetricsBuilder
- type MetricsProvider
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( ErrFailedToCreateCounter = errors.New("failed to create counter") ErrFailedToCreateGauge = errors.New("failed to create gauge") ErrFailedToCreateHistogram = errors.New("failed to create histogram") )
var ( ErrFailedToCreateOTLPExporter = errors.New("failed to create OTLP exporter") ErrFailedToCreatePrometheusExporter = errors.New("failed to create Prometheus exporter") ErrFailedToCreateResource = errors.New("failed to create resource") ErrFailedToShutdownProvider = errors.New("failed to shutdown metrics provider") )
Functions ΒΆ
This section is empty.
Types ΒΆ
type Attribute ΒΆ added in v0.7.0
Attribute represents a key-value pair for metric attributes. This wraps OpenTelemetry's attribute.KeyValue to hide the dependency.
func ErrorAttrs ΒΆ added in v0.7.0
ErrorAttrs creates common error attributes.
func Float64Attr ΒΆ added in v0.7.0
func GRPCMethodAttrs ΒΆ added in v0.7.0
GRPCMethodAttrs creates gRPC method attributes.
func HTTPEndpointAttrs ΒΆ added in v0.7.0
HTTPEndpointAttrs creates HTTP endpoint attributes.
func HTTPMethodAttrs ΒΆ added in v0.7.0
HTTPMethodAttrs creates HTTP method attributes.
func StatusAttrs ΒΆ added in v0.7.0
StatusAttrs creates status attributes.
func StringAttr ΒΆ added in v0.7.0
Convenience functions for creating attributes without needing the builder.
func WorkerAttrs ΒΆ added in v0.7.0
WorkerAttrs creates common worker attributes.
func WorkerErrorAttrs ΒΆ added in v0.7.0
WorkerErrorAttrs combines worker and error attributes.
type AttributeBuilder ΒΆ added in v0.7.0
type AttributeBuilder struct{}
AttributeBuilder provides methods to create metric attributes without exposing OpenTelemetry.
func NewAttributeBuilder ΒΆ added in v0.7.0
func NewAttributeBuilder() *AttributeBuilder
NewAttributeBuilder creates a new attribute builder.
func (*AttributeBuilder) Bool ΒΆ added in v0.7.0
func (ab *AttributeBuilder) Bool(key string, value bool) Attribute
Bool creates a boolean attribute.
func (*AttributeBuilder) Float64 ΒΆ added in v0.7.0
func (ab *AttributeBuilder) Float64(key string, value float64) Attribute
Float64 creates a float64 attribute.
func (*AttributeBuilder) Int ΒΆ added in v0.7.0
func (ab *AttributeBuilder) Int(key string, value int) Attribute
Int creates an integer attribute.
func (*AttributeBuilder) Int64 ΒΆ added in v0.7.0
func (ab *AttributeBuilder) Int64(key string, value int64) Attribute
Int64 creates an int64 attribute.
func (*AttributeBuilder) String ΒΆ added in v0.7.0
func (ab *AttributeBuilder) String(key, value string) Attribute
String creates a string attribute.
type Config ΒΆ added in v0.7.2
type Config struct {
// Service information
ServiceName string `conf:"service_name" default:""`
ServiceVersion string `conf:"service_version" default:""`
// OpenTelemetry Collector configuration (preferred)
OTLPEndpoint string `conf:"otlp_endpoint" default:""`
// Legacy direct exporters (still supported)
PrometheusEndpoint string `conf:"prometheus_endpoint" default:""`
// Export interval
ExportInterval time.Duration `conf:"export_interval" default:"30s"`
RegisterNativeCollectors bool `conf:"register_native_collectors" default:"true"`
OTLPInsecure bool `conf:"otlp_insecure" default:"true"`
}
Config holds configuration for metrics export.
type CounterBuilder ΒΆ added in v0.7.0
type CounterBuilder struct {
// contains filtered or unexported fields
}
CounterBuilder provides a fluent interface for building counter metrics.
func (*CounterBuilder) Build ΒΆ added in v0.7.0
func (cb *CounterBuilder) Build() (*CounterMetric, error)
Build creates the counter metric and returns a CounterMetric wrapper.
func (*CounterBuilder) WithUnit ΒΆ added in v0.7.0
func (cb *CounterBuilder) WithUnit(unit string) *CounterBuilder
WithUnit sets the unit for the counter.
type CounterMetric ΒΆ added in v0.7.0
type CounterMetric struct {
// contains filtered or unexported fields
}
CounterMetric wraps a counter with convenient methods.
type GaugeBuilder ΒΆ added in v0.7.0
type GaugeBuilder struct {
// contains filtered or unexported fields
}
GaugeBuilder provides a fluent interface for building gauge metrics.
func (*GaugeBuilder) Build ΒΆ added in v0.7.0
func (gb *GaugeBuilder) Build() (*GaugeMetric, error)
Build creates the gauge metric and returns a GaugeMetric wrapper.
func (*GaugeBuilder) WithUnit ΒΆ added in v0.7.0
func (gb *GaugeBuilder) WithUnit(unit string) *GaugeBuilder
WithUnit sets the unit for the gauge.
type GaugeMetric ΒΆ added in v0.7.0
type GaugeMetric struct {
// contains filtered or unexported fields
}
GaugeMetric wraps a gauge with convenient methods.
type HistogramBuilder ΒΆ added in v0.7.0
type HistogramBuilder struct {
// contains filtered or unexported fields
}
HistogramBuilder provides a fluent interface for building histogram metrics.
func (*HistogramBuilder) Build ΒΆ added in v0.7.0
func (hb *HistogramBuilder) Build() (*HistogramMetric, error)
Build creates the histogram metric and returns a HistogramMetric wrapper.
func (*HistogramBuilder) WithBuckets ΒΆ added in v0.7.0
func (hb *HistogramBuilder) WithBuckets(buckets ...float64) *HistogramBuilder
WithBuckets sets custom bucket boundaries for the histogram.
func (*HistogramBuilder) WithDurationBuckets ΒΆ added in v0.7.0
func (hb *HistogramBuilder) WithDurationBuckets() *HistogramBuilder
WithDurationBuckets sets predefined duration buckets for the histogram.
func (*HistogramBuilder) WithUnit ΒΆ added in v0.7.0
func (hb *HistogramBuilder) WithUnit(unit string) *HistogramBuilder
WithUnit sets the unit for the histogram.
type HistogramMetric ΒΆ added in v0.7.0
type HistogramMetric struct {
// contains filtered or unexported fields
}
HistogramMetric wraps a histogram with convenient methods.
func (*HistogramMetric) Record ΒΆ added in v0.7.0
func (hm *HistogramMetric) Record(ctx context.Context, value float64, attrs ...Attribute)
Record records a value in the histogram with optional attributes.
func (*HistogramMetric) RecordDuration ΒΆ added in v0.7.0
func (hm *HistogramMetric) RecordDuration( ctx context.Context, duration time.Duration, attrs ...Attribute, )
RecordDuration records a duration in seconds with optional attributes.
type MetricsBuilder ΒΆ added in v0.7.0
type MetricsBuilder struct {
// contains filtered or unexported fields
}
MetricsBuilder provides a fluent interface for creating and managing metrics.
func NewMetricsBuilder ΒΆ added in v0.7.0
func NewMetricsBuilder(provider *MetricsProvider) *MetricsBuilder
NewMetricsBuilder creates a new metrics builder with the given meter and name prefix.
func (*MetricsBuilder) Counter ΒΆ added in v0.7.0
func (mb *MetricsBuilder) Counter(name, description string) *CounterBuilder
Counter creates a new counter metric.
func (*MetricsBuilder) Gauge ΒΆ added in v0.7.0
func (mb *MetricsBuilder) Gauge(name, description string) *GaugeBuilder
Gauge creates a new gauge metric.
func (*MetricsBuilder) Histogram ΒΆ added in v0.7.0
func (mb *MetricsBuilder) Histogram(name, description string) *HistogramBuilder
Histogram creates a new histogram metric.
type MetricsProvider ΒΆ
type MetricsProvider struct {
// contains filtered or unexported fields
}
func NewMetricsProvider ΒΆ
func NewMetricsProvider(config *Config) *MetricsProvider
NewMetricsProvider creates a new metrics provider with the given configuration.
func (*MetricsProvider) Init ΒΆ added in v0.7.2
func (mp *MetricsProvider) Init() error
func (*MetricsProvider) NewBuilder ΒΆ added in v0.7.2
func (mp *MetricsProvider) NewBuilder() *MetricsBuilder