observability

package
v0.0.0-...-d375c66 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAttribute

func AddAttribute(ctx context.Context, key string, value interface{})

AddAttribute adds an attribute to the current span

func AddEvent

func AddEvent(ctx context.Context, name string, attributes ...attribute.KeyValue)

AddEvent adds an event to the current span

func Configure

func Configure(serviceName string)

Configure sets up the global logger

func RecordError

func RecordError(ctx context.Context, err error)

RecordError records an error in the current span

func StartSpan

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

StartSpan starts a new span

func TraceMiddleware

func TraceMiddleware(serviceName string) func(http.Handler) http.Handler

TraceMiddleware creates HTTP middleware for tracing

Types

type ContextKey

type ContextKey string

ContextKey is a type for context keys

const (
	RequestIDKey ContextKey = "request_id"
	UserIDKey    ContextKey = "user_id"
	ServiceKey   ContextKey = "service"
)

Context keys

type Logger

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

Logger is a structured logger

func NewLogger

func NewLogger(serviceName string) *Logger

NewLogger creates a new structured logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...map[string]interface{})

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(msg string, err error, fields ...map[string]interface{})

Error logs an error message

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, err error, fields ...map[string]interface{})

Fatal logs a fatal message and exits

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...map[string]interface{})

Info logs an info message

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...map[string]interface{})

Warn logs a warning message

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext returns a logger with context values

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]interface{}) *Logger

WithFields returns a logger with additional fields

type MetricsServer

type MetricsServer struct {
	Counters   map[string]prometheus.Counter
	Gauges     map[string]prometheus.Gauge
	Histograms map[string]prometheus.Histogram
	Summaries  map[string]prometheus.Summary
	// contains filtered or unexported fields
}

MetricsServer provides prometheus metrics functionality

func NewMetricsServer

func NewMetricsServer(serviceName string, port int) *MetricsServer

NewMetricsServer creates a new metrics server

func (*MetricsServer) Middleware

func (ms *MetricsServer) Middleware(serviceName string) func(http.Handler) http.Handler

Middleware creates a middleware for recording HTTP request metrics

func (*MetricsServer) NewCounter

func (ms *MetricsServer) NewCounter(name, help string, labels ...string) prometheus.Counter

NewCounter creates a new counter metric

func (*MetricsServer) NewGauge

func (ms *MetricsServer) NewGauge(name, help string, labels ...string) prometheus.Gauge

NewGauge creates a new gauge metric

func (*MetricsServer) NewHistogram

func (ms *MetricsServer) NewHistogram(name, help string, buckets []float64, labels ...string) prometheus.Histogram

NewHistogram creates a new histogram metric

func (*MetricsServer) NewSummary

func (ms *MetricsServer) NewSummary(name, help string, objectives map[float64]float64, labels ...string) prometheus.Summary

NewSummary creates a new summary metric

func (*MetricsServer) Start

func (ms *MetricsServer) Start() error

Start starts the metrics server

func (*MetricsServer) Stop

func (ms *MetricsServer) Stop() error

Stop stops the metrics server

type Timer

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

Timer is a utility for timing code execution

func NewTimer

func NewTimer(histogram prometheus.Histogram) *Timer

NewTimer creates a new timer

func (*Timer) ObserveDuration

func (t *Timer) ObserveDuration()

ObserveDuration records the duration

type TracingProvider

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

TracingProvider manages the OpenTelemetry tracing configuration

func NewTracingProvider

func NewTracingProvider(serviceName string) (*TracingProvider, error)

NewTracingProvider creates a new tracing provider

func (*TracingProvider) Shutdown

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

Shutdown stops the trace provider

func (*TracingProvider) Tracer

func (t *TracingProvider) Tracer(name string) trace.Tracer

Tracer creates a named tracer

Jump to

Keyboard shortcuts

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