observability

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeHealthCheck

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

CompositeHealthCheck combines multiple health checks

func NewCompositeHealthCheck

func NewCompositeHealthCheck(name string, checks ...HealthCheck) *CompositeHealthCheck

NewCompositeHealthCheck creates a new composite health check

func (*CompositeHealthCheck) Check

func (*CompositeHealthCheck) Name

func (h *CompositeHealthCheck) Name() string

type Config

type Config struct {
	ServiceName    string
	ServiceVersion string
	TracingEnabled bool
	MetricsEnabled bool
}

Config holds observability middleware configuration

type DatabaseHealthCheck

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

DatabaseHealthCheck checks database connectivity

func NewDatabaseHealthCheck

func NewDatabaseHealthCheck(name string, db *sql.DB) *DatabaseHealthCheck

NewDatabaseHealthCheck creates a new database health check

func (*DatabaseHealthCheck) Check

func (*DatabaseHealthCheck) Name

func (h *DatabaseHealthCheck) Name() string

type DiskSpaceHealthCheck

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

DiskSpaceHealthCheck checks disk space

func NewDiskSpaceHealthCheck

func NewDiskSpaceHealthCheck(name, path string, minFreePercent float64) *DiskSpaceHealthCheck

NewDiskSpaceHealthCheck creates a new disk space health check

func (*DiskSpaceHealthCheck) Check

func (*DiskSpaceHealthCheck) Name

func (h *DiskSpaceHealthCheck) Name() string

type HTTPHealthCheck

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

HTTPHealthCheck checks external HTTP services

func NewHTTPHealthCheck

func NewHTTPHealthCheck(name, url string, expectedStatus int) *HTTPHealthCheck

NewHTTPHealthCheck creates a new HTTP service health check

func (*HTTPHealthCheck) Check

func (*HTTPHealthCheck) Name

func (h *HTTPHealthCheck) Name() string

type HealthCheck

type HealthCheck interface {
	Name() string
	Check(ctx context.Context) HealthResult
}

HealthCheck represents a health check

type HealthResult

type HealthResult struct {
	Healthy bool                   `json:"healthy"`
	Message string                 `json:"message"`
	Latency time.Duration          `json:"latency"`
	Details map[string]interface{} `json:"details,omitempty"`
}

HealthResult represents the result of a health check

type MemoryHealthCheck

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

MemoryHealthCheck checks memory usage

func NewMemoryHealthCheck

func NewMemoryHealthCheck(name string, maxMemoryPercent float64) *MemoryHealthCheck

NewMemoryHealthCheck creates a new memory health check

func (*MemoryHealthCheck) Check

func (*MemoryHealthCheck) Name

func (h *MemoryHealthCheck) Name() string

type MetricsCollector

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

MetricsCollector provides OpenTelemetry metrics collection

func NewMetricsCollector

func NewMetricsCollector(config MetricsConfig, logger logger.Logger) (*MetricsCollector, error)

NewMetricsCollector creates a new metrics collector

func (*MetricsCollector) DecHTTPRequestsInFlight

func (mc *MetricsCollector) DecHTTPRequestsInFlight(ctx context.Context)

func (*MetricsCollector) GetMeter

func (mc *MetricsCollector) GetMeter() metric.Meter

GetMeter returns the OpenTelemetry meter for custom metrics

func (*MetricsCollector) IncHTTPRequestsInFlight

func (mc *MetricsCollector) IncHTTPRequestsInFlight(ctx context.Context)

func (*MetricsCollector) RecordBusinessEvent

func (mc *MetricsCollector) RecordBusinessEvent(ctx context.Context, eventType string, labels map[string]string)

Business Event Metrics

func (*MetricsCollector) RecordCacheHit

func (mc *MetricsCollector) RecordCacheHit(ctx context.Context, cacheType string)

Cache Metrics

func (*MetricsCollector) RecordCacheMiss

func (mc *MetricsCollector) RecordCacheMiss(ctx context.Context, cacheType string)

func (*MetricsCollector) RecordDatabaseConnection

func (mc *MetricsCollector) RecordDatabaseConnection(ctx context.Context, delta int64)

Database Metrics

func (*MetricsCollector) RecordError

func (mc *MetricsCollector) RecordError(ctx context.Context, errorType string, component string)

Error Metrics

func (*MetricsCollector) RecordHTTPRequest

func (mc *MetricsCollector) RecordHTTPRequest(ctx context.Context, method, path string, statusCode int, duration time.Duration)

HTTP Metrics

func (*MetricsCollector) Shutdown

func (mc *MetricsCollector) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the metrics provider

type MetricsConfig

type MetricsConfig struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	Enabled        bool
}

MetricsConfig holds configuration for metrics

type ObservabilityMiddleware

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

ObservabilityMiddleware provides observability middleware

func NewObservabilityMiddleware

func NewObservabilityMiddleware(config Config, logger logger.Logger) (*ObservabilityMiddleware, error)

NewObservabilityMiddleware creates a new observability middleware

func (*ObservabilityMiddleware) BusinessMetrics

func (om *ObservabilityMiddleware) BusinessMetrics() gin.HandlerFunc

BusinessMetrics middleware records business-specific metrics

func (*ObservabilityMiddleware) GetMetricsCollector

func (om *ObservabilityMiddleware) GetMetricsCollector() *MetricsCollector

GetMetricsCollector returns the metrics collector for additional custom metrics

func (*ObservabilityMiddleware) Logging

func (om *ObservabilityMiddleware) Logging(logger logger.Logger) gin.HandlerFunc

Logging middleware provides structured logging for HTTP requests

func (*ObservabilityMiddleware) Metrics

func (om *ObservabilityMiddleware) Metrics() gin.HandlerFunc

Metrics middleware records HTTP metrics

func (*ObservabilityMiddleware) Tracing

func (om *ObservabilityMiddleware) Tracing() gin.HandlerFunc

Tracing middleware provides distributed tracing

type RedisHealthCheck

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

RedisHealthCheck checks Redis connectivity

func NewRedisHealthCheck

func NewRedisHealthCheck(name string, client redis.UniversalClient) *RedisHealthCheck

NewRedisHealthCheck creates a new Redis health check

func (*RedisHealthCheck) Check

func (*RedisHealthCheck) Name

func (h *RedisHealthCheck) Name() string

type SimpleObservabilityMiddleware

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

SimpleObservabilityMiddleware provides basic observability without OpenTelemetry

func NewSimpleObservabilityMiddleware

func NewSimpleObservabilityMiddleware(config Config, logger logger.Logger) *SimpleObservabilityMiddleware

NewSimpleObservabilityMiddleware creates a basic observability middleware

func (*SimpleObservabilityMiddleware) BusinessMetrics

func (som *SimpleObservabilityMiddleware) BusinessMetrics() gin.HandlerFunc

BusinessMetrics middleware records business-specific metrics

func (*SimpleObservabilityMiddleware) Logging

Logging middleware provides structured logging for HTTP requests

func (*SimpleObservabilityMiddleware) Metrics

Metrics middleware records basic HTTP metrics (simplified)

func (*SimpleObservabilityMiddleware) Tracing

Tracing middleware provides basic request tracing (simplified without OpenTelemetry)

Jump to

Keyboard shortcuts

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