telemetry

package
v0.0.0-...-2460f69 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSpanAttributes

func AddSpanAttributes(ctx context.Context, attrs ...attribute.KeyValue)

AddSpanAttributes adds attributes to the current span in context

func CreatePrometheusHandler

func CreatePrometheusHandler() http.Handler

CreatePrometheusHandler creates a handler for the /metrics endpoint

func DecrementRequestsInFlight

func DecrementRequestsInFlight(ctx context.Context, method, path string)

DecrementRequestsInFlight decrements the in-flight requests counter

func GetTelemetryDefaults

func GetTelemetryDefaults() map[string]interface{}

GetTelemetryDefaults returns default values for telemetry configuration

func IncrementRequestsInFlight

func IncrementRequestsInFlight(ctx context.Context, method, path string)

IncrementRequestsInFlight increments the in-flight requests counter

func InitCommonMetrics

func InitCommonMetrics(mp *MetricsProvider) error

InitCommonMetrics initializes common metrics

func InitTracer

func InitTracer(ctx context.Context, config TracerConfig, logger *zap.Logger) (*sdktrace.TracerProvider, error)

InitTracer initializes the OpenTelemetry tracer provider

func InstrumentClient

func InstrumentClient(client *http.Client, opts ...otelhttp.Option) *http.Client

InstrumentClient wraps an http.Client with OpenTelemetry instrumentation

func InstrumentHandler

func InstrumentHandler(handler http.Handler, operation string, opts ...otelhttp.Option) http.Handler

InstrumentHandler wraps an http.Handler with OpenTelemetry instrumentation

func IsMetricsEnabled

func IsMetricsEnabled(k *koanf.Koanf) bool

IsMetricsEnabled returns whether metrics are enabled

func NewHTTPMiddleware

func NewHTTPMiddleware(logger *zap.Logger) func(http.Handler) http.Handler

NewHTTPMiddleware creates a new middleware for HTTP request tracing

func RecordDBOperation

func RecordDBOperation(ctx context.Context, operation, database, collection string, duration time.Duration, err error)

RecordDBOperation records metrics for a database operation

func RecordErrorMetric

func RecordErrorMetric(ctx context.Context, errorType, operation string)

RecordErrorMetric records an application error in metrics

func RecordErrorSpan

func RecordErrorSpan(ctx context.Context, err error, opts ...trace.EventOption)

RecordErrorSpan records an error on the current span in context

func RecordHTTPRequest

func RecordHTTPRequest(ctx context.Context, method, path string, statusCode int, duration time.Duration, responseSize int64)

RecordHTTPRequest records metrics for an HTTP request

func ShutdownTracer

func ShutdownTracer(ctx context.Context, tp *sdktrace.TracerProvider, logger *zap.Logger, k *koanf.Koanf)

ShutdownTracer gracefully shuts down the tracer provider

func StartSpan

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

StartSpan is a helper function to start a new span from a context

func UpdateDBConnections

func UpdateDBConnections(ctx context.Context, database string, delta int64)

UpdateDBConnections updates the open database connections counter

Types

type Config

type Config struct {
	Enabled         bool          `mapstructure:"enabled"`
	ServiceName     string        `mapstructure:"service_name"`
	Environment     string        `mapstructure:"environment"`
	Version         string        `mapstructure:"version"`
	ShutdownTimeout int           `mapstructure:"shutdown_timeout"`
	OTLP            OTLPConfig    `mapstructure:"otlp"`
	Tracing         TracingConfig `mapstructure:"tracing"`
	Metrics         MetricsConfig `mapstructure:"metrics"`
	HTTP            HTTPConfig    `mapstructure:"http"`
}

Config holds all telemetry configuration

func LoadConfig

func LoadConfig(k *koanf.Koanf) Config

LoadConfig loads telemetry configuration from koanf

type HTTPConfig

type HTTPConfig struct {
	TracingEnabled bool
}

HTTPConfig holds configuration for HTTP instrumentation

func NewHTTPConfig

func NewHTTPConfig() HTTPConfig

NewHTTPConfig creates a new HTTP instrumentation configuration

type MetricsConfig

type MetricsConfig struct {
	Enabled       bool             `mapstructure:"enabled"`
	ReportingFreq int              `mapstructure:"reporting_frequency_seconds"`
	Prometheus    PrometheusConfig `mapstructure:"prometheus"`
}

MetricsConfig holds configuration for metrics

type MetricsProvider

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

MetricsProvider holds the metrics provider and meters

func NewMetricsProvider

func NewMetricsProvider(ctx context.Context, logger *zap.Logger, k *koanf.Koanf) (*MetricsProvider, error)

NewMetricsProvider creates a new metrics provider

func (*MetricsProvider) Meter

func (mp *MetricsProvider) Meter() metric.Meter

Meter returns the meter

func (*MetricsProvider) Shutdown

func (mp *MetricsProvider) Shutdown(ctx context.Context) error

Shutdown shuts down the metrics provider

type OTLPConfig

type OTLPConfig struct {
	Endpoint string `mapstructure:"endpoint"`
	Insecure bool   `mapstructure:"insecure"`
	Timeout  int    `mapstructure:"timeout_seconds"`
}

OTLPConfig holds configuration for OTLP exporter

type PrometheusConfig

type PrometheusConfig struct {
	Enabled bool   `mapstructure:"enabled"`
	Listen  string `mapstructure:"listen"`
	Path    string `mapstructure:"path"`
}

PrometheusConfig holds configuration for Prometheus metrics

type TracerConfig

type TracerConfig struct {
	ServiceName    string
	ServiceVersion string
	Environment    string
	OTLPEndpoint   string
	Insecure       bool
}

TracerConfig holds configuration for the tracer

func NewTracerConfig

func NewTracerConfig(k *koanf.Koanf) TracerConfig

NewTracerConfig creates a new tracer configuration from koanf

type TracingConfig

type TracingConfig struct {
	Enabled         bool     `mapstructure:"enabled"`
	SamplingRatio   float64  `mapstructure:"sampling_ratio"`
	PropagationKeys []string `mapstructure:"propagation_keys"`
}

TracingConfig holds configuration for tracing

type TracingMiddleware

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

TracingMiddleware provides middleware for tracing HTTP requests

func NewTracingMiddleware

func NewTracingMiddleware(logger *zap.Logger) *TracingMiddleware

NewTracingMiddleware creates a new tracing middleware

func (*TracingMiddleware) Middleware

func (m *TracingMiddleware) Middleware(next http.Handler) http.Handler

Middleware returns an http.Handler middleware function

Jump to

Keyboard shortcuts

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