telemetry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KiB float64 = 1024
	MiB         = KiB * 1024
	GiB         = MiB * 1024
)

Variables

View Source
var (
	HTTPServerRequestDurationInstrument = semconvhttp.ServerRequestDuration{}.Name()
	HTTPServerRequestSizeInstrument     = semconvhttp.ServerRequestBodySize{}.Name()
	HTTPServerResponseSizeInstrument    = semconvhttp.ServerResponseBodySize{}.Name()
)
View Source
var HTTPServerDurationBounds = []float64{
	0.005, 0.01, 0.025, 0.05, 0.075, 0.1,
	0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10,
	30, 60, 120, 300, 600,
}

HTTPServerDurationBounds extends the default middleware buckets (0.005–10s from go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho/internal/semconv) to capture long uploads/downloads up to 10 minutes.

View Source
var SizeBoundaries = []float64{

	KiB,
	2 * KiB,
	4 * KiB,
	8 * KiB,
	16 * KiB,
	32 * KiB,
	64 * KiB,
	128 * KiB,
	256 * KiB,
	512 * KiB,
	MiB,
	2 * MiB,
	4 * MiB,
	8 * MiB,
	16 * MiB,
	32 * MiB,
	64 * MiB,
	128 * MiB,
	256 * MiB,
	512 * MiB,
	GiB,
}

Functions

func BoolAttr

func BoolAttr(key string, value bool) attribute.KeyValue

func FloatAttr

func FloatAttr(key string, value float64) attribute.KeyValue

func Initialize

func Initialize(ctx context.Context, cfg Config) error

Initialize sets up the global telemetry instance. This should be called once at application startup.

func Int64Attr

func Int64Attr(key string, value int64) attribute.KeyValue

func IntAttr

func IntAttr(key string, value int) attribute.KeyValue

func RecordServerInfo

func RecordServerInfo(ctx context.Context, serverType string, extraAttrs ...attribute.KeyValue)

RecordServerInfo records server metadata as an info metric this metric is best effort, if it fails, a warning is log and the process continues

func Shutdown

func Shutdown(ctx context.Context) error

Shutdown shuts down the global telemetry instance.

func StringAttr

func StringAttr(key, value string) attribute.KeyValue

Types

type Config

type Config struct {
	ServiceName     string
	ServiceVersion  string
	InstanceID      string
	Environment     string
	Endpoint        string
	PublishInterval time.Duration
	TracesEndpoint  string
	// contains filtered or unexported fields
}

type Counter

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

func NewCounter

func NewCounter(meter metric.Meter, cfg CounterConfig) (*Counter, error)

func (*Counter) Add

func (c *Counter) Add(ctx context.Context, value int64, attrs ...attribute.KeyValue)

func (*Counter) Inc

func (c *Counter) Inc(ctx context.Context, attrs ...attribute.KeyValue)

func (*Counter) WithAttributes

func (c *Counter) WithAttributes(attrs ...attribute.KeyValue) *Counter

type CounterConfig

type CounterConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
}

type FloatCounter

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

func NewFloatCounter

func NewFloatCounter(meter metric.Meter, cfg FloatCounterConfig) (*FloatCounter, error)

func (*FloatCounter) Add

func (c *FloatCounter) Add(ctx context.Context, value float64, attrs ...attribute.KeyValue)

func (*FloatCounter) WithAttributes

func (c *FloatCounter) WithAttributes(attrs ...attribute.KeyValue) *FloatCounter

type FloatCounterConfig

type FloatCounterConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
}

type FloatGauge

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

func NewFloatGauge

func NewFloatGauge(meter metric.Meter, cfg FloatGaugeConfig) (*FloatGauge, error)

func (*FloatGauge) Record

func (g *FloatGauge) Record(ctx context.Context, value float64, attrs ...attribute.KeyValue)

func (*FloatGauge) WithAttributes

func (g *FloatGauge) WithAttributes(attrs ...attribute.KeyValue) *FloatGauge

type FloatGaugeConfig

type FloatGaugeConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
}

type Gauge

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

func NewGauge

func NewGauge(meter metric.Meter, cfg GaugeConfig) (*Gauge, error)

func (*Gauge) Record

func (g *Gauge) Record(ctx context.Context, value int64, attrs ...attribute.KeyValue)

func (*Gauge) WithAttributes

func (g *Gauge) WithAttributes(attrs ...attribute.KeyValue) *Gauge

type GaugeConfig

type GaugeConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
}

type Histogram

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

func NewHistogram

func NewHistogram(meter metric.Meter, cfg HistogramConfig) (*Histogram, error)

func (*Histogram) Record

func (h *Histogram) Record(ctx context.Context, value int64, attrs ...attribute.KeyValue)

func (*Histogram) WithAttributes

func (h *Histogram) WithAttributes(attrs ...attribute.KeyValue) *Histogram

type HistogramConfig

type HistogramConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
	Boundaries  []float64
}

type Info

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

Info represents an info metric - a gauge that always has value 1 Info metrics are used to expose textual information as labels.

func NewInfo

func NewInfo(meter metric.Meter, cfg InfoConfig) (*Info, error)

NewInfo creates a new info metric. Under the hood it is a gauge that always reports 1. This is useful for exposing version info, addresses, and other metadata

func (*Info) Record

func (i *Info) Record(ctx context.Context, attrs ...attribute.KeyValue)

Record records the info metric with the given attributes, merging them with existing ones

type InfoConfig

type InfoConfig struct {
	Name        string
	Description string
	Labels      map[string]string
}

InfoConfig configures an info metric

type Provider

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

func (*Provider) Meter

func (p *Provider) Meter() metric.Meter

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

type Telemetry

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

func Global

func Global() *Telemetry

Global returns the global telemetry instance. If Initialize hasn't been called, it returns a no-op telemetry instance.

func New

func New(ctx context.Context, cfg Config) (*Telemetry, error)

func NewWithMeter

func NewWithMeter(meter metric.Meter) *Telemetry

NewWithMeter creates a new Telemetry instance with a custom meter. This is useful for testing with in-memory exporters or manual readers.

func (*Telemetry) Meter

func (t *Telemetry) Meter() metric.Meter

func (*Telemetry) NewCounter

func (t *Telemetry) NewCounter(cfg CounterConfig) (*Counter, error)

func (*Telemetry) NewFloatCounter

func (t *Telemetry) NewFloatCounter(cfg FloatCounterConfig) (*FloatCounter, error)

func (*Telemetry) NewFloatGauge

func (t *Telemetry) NewFloatGauge(cfg FloatGaugeConfig) (*FloatGauge, error)

func (*Telemetry) NewGauge

func (t *Telemetry) NewGauge(cfg GaugeConfig) (*Gauge, error)

func (*Telemetry) NewHistogram

func (t *Telemetry) NewHistogram(cfg HistogramConfig) (*Histogram, error)

func (*Telemetry) NewInfo

func (t *Telemetry) NewInfo(cfg InfoConfig) (*Info, error)

func (*Telemetry) NewTimer

func (t *Telemetry) NewTimer(cfg TimerConfig) (*Timer, error)

func (*Telemetry) Shutdown

func (t *Telemetry) Shutdown(ctx context.Context) error

type TimedContext

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

func (*TimedContext) End

func (tc *TimedContext) End(attrs ...attribute.KeyValue)

type Timer

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

func NewTimer

func NewTimer(meter metric.Meter, cfg TimerConfig) (*Timer, error)

func (*Timer) Record

func (t *Timer) Record(ctx context.Context, duration time.Duration, attrs ...attribute.KeyValue)

func (*Timer) RecordFloat

func (t *Timer) RecordFloat(ctx context.Context, value float64, attrs ...attribute.KeyValue)

func (*Timer) Start

func (t *Timer) Start(ctx context.Context, attrs ...attribute.KeyValue) *TimedContext

func (*Timer) WithAttributes

func (t *Timer) WithAttributes(attrs ...attribute.KeyValue) *Timer

type TimerConfig

type TimerConfig struct {
	Name        string
	Description string
	Unit        string
	Attributes  map[string]string
	Boundaries  []float64
}

Jump to

Keyboard shortcuts

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