observability

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package observability provides Prometheus metrics for MongoRPC.

Package observability provides OpenTelemetry tracing for MongoRPC.

Index

Constants

This section is empty.

Variables

View Source
var (
	// RequestsTotal counts total gRPC requests.
	RequestsTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "mongorpc_requests_total",
			Help: "Total number of gRPC requests",
		},
		[]string{"method", "status"},
	)

	// RequestDuration measures request latency.
	RequestDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "mongorpc_request_duration_seconds",
			Help:    "Request duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method"},
	)

	// ActiveConnections tracks active connections.
	ActiveConnections = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "mongorpc_active_connections",
			Help: "Number of active connections",
		},
	)

	// MongoDBOperations counts MongoDB operations.
	MongoDBOperations = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "mongorpc_mongodb_operations_total",
			Help: "Total MongoDB operations",
		},
		[]string{"operation", "database", "collection"},
	)

	// MongoDBErrors counts MongoDB errors.
	MongoDBErrors = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "mongorpc_mongodb_errors_total",
			Help: "Total MongoDB errors",
		},
		[]string{"operation", "database", "collection"},
	)

	// DocumentsProcessed counts documents processed.
	DocumentsProcessed = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "mongorpc_documents_processed_total",
			Help: "Total documents processed",
		},
		[]string{"operation"},
	)
)

Functions

func InitTracer

func InitTracer(serviceName, serviceVersion string) (func(context.Context) error, error)

InitTracer initializes the OpenTelemetry tracer.

func RecordMongoOp

func RecordMongoOp(op, database, collection string, err error)

RecordMongoOp records a MongoDB operation.

func RecordRequest

func RecordRequest(method, status string, durationSeconds float64)

RecordRequest records a request for metrics.

func SpanAttributes

func SpanAttributes(method, database, collection string) []attribute.KeyValue

SpanAttributes returns common span attributes for gRPC methods.

func StartSpan

func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan starts a new span with the given name.

func Tracer

func Tracer() trace.Tracer

Tracer returns the global tracer for MongoRPC.

Types

This section is empty.

Jump to

Keyboard shortcuts

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