metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientAttributes

func ClientAttributes(clientID string, metadata map[string]string) []attribute.KeyValue

ClientAttributes returns common client attributes for tracing

func ContextWithSpan

func ContextWithSpan(ctx context.Context, span trace.Span) context.Context

ContextWithSpan returns a new context with the given span

func Extract

Extract extracts trace context from carrier

func HTTPMiddleware

func HTTPMiddleware(metrics *Metrics, tracer *Tracer) func(http.Handler) http.Handler

HTTPMiddleware provides HTTP metrics and tracing middleware

func Inject

func Inject(ctx context.Context, carrier propagation.TextMapCarrier)

Inject injects trace context into carrier

func MessageAttributes

func MessageAttributes(messageID, queue, msgType string, priority int) []attribute.KeyValue

MessageAttributes returns common message attributes for tracing

func MetricsHandler

func MetricsHandler() http.Handler

MetricsHandler returns an HTTP handler for Prometheus metrics

func QueueAttributes

func QueueAttributes(queueName string, queueType string) []attribute.KeyValue

QueueAttributes returns common queue attributes for tracing

func RecordError

func RecordError(span trace.Span, err error)

RecordError records an error on the span

func RequestLogger

func RequestLogger(metrics *Metrics) func(http.Handler) http.Handler

RequestLogger provides request logging with metrics

func SetOK

func SetOK(span trace.Span)

SetOK sets the span status to OK

func SpanFromContext

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext returns the current span from context

func WithContext

func WithContext(ctx context.Context, m *Metrics) context.Context

WithContext adds metrics to context

func WithTracer

func WithTracer(ctx context.Context, tracer *Tracer) context.Context

WithTracer adds tracer to context

Types

type Metrics

type Metrics struct {
	// Message metrics
	MessagesProcessed *prometheus.CounterVec
	MessageDuration   *prometheus.HistogramVec
	MessagesInFlight  *prometheus.GaugeVec
	MessageSize       *prometheus.HistogramVec

	// Queue metrics
	QueueDepth    *prometheus.GaugeVec
	QueueCapacity *prometheus.GaugeVec
	EnqueueRate   *prometheus.CounterVec
	DequeueRate   *prometheus.CounterVec

	// Client metrics
	ClientConnections   *prometheus.GaugeVec
	ClientHeartbeats    *prometheus.CounterVec
	ClientSubscriptions *prometheus.GaugeVec

	// Error metrics
	ErrorsTotal        *prometheus.CounterVec
	RetryAttempts      *prometheus.CounterVec
	DeadLetterMessages *prometheus.CounterVec

	// Store metrics
	StoreOperations *prometheus.CounterVec
	StoreLatency    *prometheus.HistogramVec
	StoreSize       prometheus.Gauge

	// System metrics
	WorkerPoolSize *prometheus.GaugeVec
	ActiveWorkers  *prometheus.GaugeVec
	BatchSize      *prometheus.HistogramVec

	// gRPC metrics (if enabled)
	GRPCRequests     *prometheus.CounterVec
	GRPCDuration     *prometheus.HistogramVec
	GRPCStreamActive *prometheus.GaugeVec

	// HTTP metrics
	HTTPRequests     *prometheus.CounterVec
	HTTPDuration     *prometheus.HistogramVec
	HTTPRequestSize  *prometheus.HistogramVec
	HTTPResponseSize *prometheus.HistogramVec
}

Metrics holds all AMQ metrics

func FromContext

func FromContext(ctx context.Context) *Metrics

FromContext retrieves metrics from context

func NewMetrics

func NewMetrics(namespace string) *Metrics

NewMetrics creates a new metrics instance

func (*Metrics) RecordDequeue

func (m *Metrics) RecordDequeue(queue, priority string)

RecordDequeue records message dequeue

func (*Metrics) RecordEnqueue

func (m *Metrics) RecordEnqueue(queue, priority string)

RecordEnqueue records message enqueue

func (*Metrics) RecordError

func (m *Metrics) RecordError(errorType, operation string)

RecordError records an error

func (*Metrics) RecordGRPCRequest

func (m *Metrics) RecordGRPCRequest(method, status string, duration time.Duration)

RecordGRPCRequest records a gRPC request

func (*Metrics) RecordHTTPRequest

func (m *Metrics) RecordHTTPRequest(method, endpoint, status string, duration time.Duration, reqSize, respSize int)

RecordHTTPRequest records an HTTP request

func (*Metrics) RecordMessageProcessed

func (m *Metrics) RecordMessageProcessed(queue, msgType, status string, duration time.Duration)

RecordMessageProcessed records a processed message

func (*Metrics) RecordMessageSize

func (m *Metrics) RecordMessageSize(queue, msgType string, size int)

RecordMessageSize records message size

func (*Metrics) RecordStoreOperation

func (m *Metrics) RecordStoreOperation(operation string, success bool, duration time.Duration)

RecordStoreOperation records a store operation

func (*Metrics) UpdateClientConnections

func (m *Metrics) UpdateClientConnections(clientType string, delta int)

UpdateClientConnections updates client connection count

func (*Metrics) UpdateGRPCStreams

func (m *Metrics) UpdateGRPCStreams(method string, delta int)

UpdateGRPCStreams updates active gRPC stream count

func (*Metrics) UpdateQueueDepth

func (m *Metrics) UpdateQueueDepth(queue string, priority string, depth int)

UpdateQueueDepth updates queue depth gauge

type Timer

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

Timer provides a convenient way to time operations

func NewTimer

func NewTimer() *Timer

NewTimer creates a new timer

func (*Timer) ObserveDuration

func (t *Timer) ObserveDuration() time.Duration

ObserveDuration records the duration since timer creation

type Tracer

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

Tracer wraps OpenTelemetry tracer

func NewTracer

func NewTracer(config TracingConfig) (*Tracer, error)

NewTracer creates a new tracer instance

func TracerFromContext

func TracerFromContext(ctx context.Context) *Tracer

TracerFromContext retrieves tracer from context

func (*Tracer) Shutdown

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

Shutdown shuts down the tracer

func (*Tracer) Start

func (t *Tracer) Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

Start starts a new span

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(ctx context.Context, operation string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan starts a new span with common attributes

type TracingConfig

type TracingConfig struct {
	Enabled      bool
	Endpoint     string
	ServiceName  string
	SamplingRate float64
	Insecure     bool
}

TracingConfig holds tracing configuration

func DefaultTracingConfig

func DefaultTracingConfig() TracingConfig

DefaultTracingConfig returns default tracing configuration

type TracingPropagator

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

TracingPropagator provides HTTP trace propagation

func NewTracingPropagator

func NewTracingPropagator(tracer *Tracer) *TracingPropagator

NewTracingPropagator creates a new tracing propagator

func (*TracingPropagator) Extract

func (tp *TracingPropagator) Extract(r *http.Request) *http.Request

Extract extracts trace context from HTTP headers

func (*TracingPropagator) Inject

func (tp *TracingPropagator) Inject(r *http.Request)

Inject injects trace context into HTTP headers

Jump to

Keyboard shortcuts

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