metrics

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package metrics provides OpenTelemetry-based observability for the SDK and allows developers to register custom metrics for their engrams and impulses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Counter

func Counter(name, description string) (metric.Int64Counter, error)

Counter creates a custom counter metric that developers can use in their engrams. Example:

counter, _ := metrics.Counter("myengram.records.processed_total", "Total records processed")
counter.Add(ctx, int64(len(records)))

func Gauge

func Gauge(name, description, unit string, callback func() float64) error

Gauge creates a custom gauge metric (async) that periodically calls the provided callback. Example:

metrics.Gauge("myengram.queue.size", "Current queue size", "items",
    func() float64 { return float64(len(queue)) })

func GetMeter

func GetMeter() metric.Meter

GetMeter returns the underlying OpenTelemetry meter for advanced use cases. Most developers should use Counter, Histogram, or Gauge instead.

func Histogram

func Histogram(name, description, unit string) (metric.Float64Histogram, error)

Histogram creates a custom histogram metric for recording distributions. Example:

hist, _ := metrics.Histogram("myengram.processing.duration_seconds", "Processing duration", "s")
hist.Record(ctx, durationSec)

func RecordClientBufferAdded

func RecordClientBufferAdded(ctx context.Context, reason string)

RecordClientBufferAdded increments add counter with a reason label.

func RecordClientBufferDrop

func RecordClientBufferDrop(ctx context.Context, reason string)

RecordClientBufferDrop increments drop counter with a reason label.

func RecordClientBufferFlush

func RecordClientBufferFlush(ctx context.Context, count int)

RecordClientBufferFlush increments flush counter by count.

func RecordDehydrationSize

func RecordDehydrationSize(ctx context.Context, sizeBytes int64)

RecordDehydrationSize records the size of dehydrated data for observability.

func RecordHydrationSize

func RecordHydrationSize(ctx context.Context, sizeBytes int64)

RecordHydrationSize records the size of hydrated data for observability.

func RecordK8sOperation

func RecordK8sOperation(ctx context.Context, operation string, durationSec float64, success bool)

RecordK8sOperation records the duration of a Kubernetes API operation.

func RecordStreamBackpressureTimeout added in v0.1.2

func RecordStreamBackpressureTimeout(ctx context.Context, stage string)

RecordStreamBackpressureTimeout records occurrences of backpressure timeouts. Stage should denote where the timeout happened (e.g., "client_receiver", "server_reader").

func RecordStreamMessage

func RecordStreamMessage(ctx context.Context, direction string)

RecordStreamMessage increments the stream message counter. Direction should be "received" or "sent".

func RecordStreamReconnectAttempt

func RecordStreamReconnectAttempt(ctx context.Context, reason string)

RecordStreamReconnectAttempt increments the reconnect attempts counter with reason labeling.

func RecordStreamReconnectFailure

func RecordStreamReconnectFailure(ctx context.Context, reason string)

RecordStreamReconnectFailure increments the reconnect failures counter (terminal) with reason labeling.

func RegisterClientBufferGauges

func RegisterClientBufferGauges(sizeFn func() float64, bytesFn func() float64) func()

RegisterClientBufferGauges registers async gauges for buffer size and bytes. The callbacks will be polled by the OTel SDK.

Types

This section is empty.

Jump to

Keyboard shortcuts

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