Documentation
¶
Index ¶
- func AddSpanAttributes(ctx context.Context, attrs ...attribute.KeyValue)
- func CreatePrometheusHandler() http.Handler
- func DecrementRequestsInFlight(ctx context.Context, method, path string)
- func GetTelemetryDefaults() map[string]interface{}
- func IncrementRequestsInFlight(ctx context.Context, method, path string)
- func InitCommonMetrics(mp *MetricsProvider) error
- func InitTracer(ctx context.Context, config TracerConfig, logger *zap.Logger) (*sdktrace.TracerProvider, error)
- func InstrumentClient(client *http.Client, opts ...otelhttp.Option) *http.Client
- func InstrumentHandler(handler http.Handler, operation string, opts ...otelhttp.Option) http.Handler
- func IsMetricsEnabled(k *koanf.Koanf) bool
- func NewHTTPMiddleware(logger *zap.Logger) func(http.Handler) http.Handler
- func RecordDBOperation(ctx context.Context, operation, database, collection string, ...)
- func RecordErrorMetric(ctx context.Context, errorType, operation string)
- func RecordErrorSpan(ctx context.Context, err error, opts ...trace.EventOption)
- func RecordHTTPRequest(ctx context.Context, method, path string, statusCode int, ...)
- func ShutdownTracer(ctx context.Context, tp *sdktrace.TracerProvider, logger *zap.Logger, ...)
- func StartSpan(ctx context.Context, name string) (context.Context, trace.Span)
- func UpdateDBConnections(ctx context.Context, database string, delta int64)
- type Config
- type HTTPConfig
- type MetricsConfig
- type MetricsProvider
- type OTLPConfig
- type PrometheusConfig
- type TracerConfig
- type TracingConfig
- type TracingMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSpanAttributes ¶
AddSpanAttributes adds attributes to the current span in context
func CreatePrometheusHandler ¶
CreatePrometheusHandler creates a handler for the /metrics endpoint
func DecrementRequestsInFlight ¶
DecrementRequestsInFlight decrements the in-flight requests counter
func GetTelemetryDefaults ¶
func GetTelemetryDefaults() map[string]interface{}
GetTelemetryDefaults returns default values for telemetry configuration
func IncrementRequestsInFlight ¶
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 ¶
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 ¶
IsMetricsEnabled returns whether metrics are enabled
func NewHTTPMiddleware ¶
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 ¶
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
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 ¶
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
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