observability

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Tracing   TracingConfig   `json:"tracing" yaml:"tracing" mapstructure:"tracing"`
	Metrics   MetricsConfig   `json:"metrics" yaml:"metrics" mapstructure:"metrics"`
	Logging   LogConfig       `json:"logging" yaml:"logging" mapstructure:"logging"`
	Profiling ProfilingConfig `json:"profiling" yaml:"profiling" mapstructure:"profiling"`
}

Config configures logs, traces and metrics for the application

type Impl

type Impl struct {
	metric.MeterProvider
	// contains filtered or unexported fields
}

func NewObservability

func NewObservability(ctx context.Context, info ServiceInfo, config Config) (*Impl, error)

func (*Impl) AreMetricsEnabled added in v0.2.2

func (obs *Impl) AreMetricsEnabled() bool

func (*Impl) IsProfilingEnabled added in v0.2.2

func (obs *Impl) IsProfilingEnabled() bool

func (*Impl) IsTracingEnabled added in v0.2.2

func (obs *Impl) IsTracingEnabled() bool

func (*Impl) Log

func (obs *Impl) Log() *otelzap.Logger

Log Returns the logger

func (*Impl) LogSpan

func (obs *Impl) LogSpan(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx)

LogSpan creates a new span with the given name and fields and logs the span and trace id fields

func (*Impl) LogSpanWithTimeout

func (obs *Impl) LogSpanWithTimeout(ctx context.Context, spanName string, timeout time.Duration, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx)

LogSpanWithTimeout creates a new span with the given name and fields and logs the span and trace id fields

func (*Impl) Metrics

func (obs *Impl) Metrics() *Metrics

Metrics returns the metrics instance

func (*Impl) SetupGinMiddleware added in v0.2.0

func (obs *Impl) SetupGinMiddleware(router *gin.Engine)

SetupGinMiddleware adds middleware to the Gin router based on the observability configuration

func (*Impl) Shutdown

func (obs *Impl) Shutdown(ctx context.Context) error

Shutdown Gracefully shutdown observability components

func (*Impl) Span

func (obs *Impl) Span(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func())

Span creates a new span

func (*Impl) WithSpanKind

func (obs *Impl) WithSpanKind(spanKind trace.SpanKind) *Impl

WithSpanKind returns a copy of the observability instance with the given span type

type LogConfig

type LogConfig struct {
	Level      *LogLevel   `yaml:"level" json:"level,omitempty" mapstructure:"level"` // debug, info, warn, error
	OtelLogger *OtelLogger `yaml:"otelLogger" json:"otelLogger,omitempty" mapstructure:"otelLogger"`
}

LogConfig is the configuration for the logging

type LogFormat added in v0.2.1

type LogFormat string

type LogLevel

type LogLevel string
const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
)

type Logging

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

func NewLogging

func NewLogging(config LogConfig) *Logging

func (*Logging) Logger

func (l *Logging) Logger() *otelzap.Logger

func (*Logging) Shutdown

func (l *Logging) Shutdown() error

type Metrics

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

func NewMetrics

func NewMetrics(ctx context.Context, info ServiceInfo, config MetricsConfig) (*Metrics, error)

NewMetrics Creates a new metrics instance

func (*Metrics) DecrementConsumers

func (m *Metrics) DecrementConsumers(queueName string)

func (*Metrics) IncrementConsumers

func (m *Metrics) IncrementConsumers(queueName string)

todo underlying implementation should use metrics package instead?

func (*Metrics) IncrementMessagesAcknowledged

func (m *Metrics) IncrementMessagesAcknowledged(queueName string)

func (*Metrics) IncrementMessagesDelivered

func (m *Metrics) IncrementMessagesDelivered(queueName string)

func (*Metrics) IncrementMessagesDiscarded

func (m *Metrics) IncrementMessagesDiscarded(queueName string)

func (*Metrics) IncrementMessagesPublished

func (m *Metrics) IncrementMessagesPublished(ctx context.Context, queueName string)

func (*Metrics) IncrementMessagesRequeued

func (m *Metrics) IncrementMessagesRequeued(queueName string)

func (*Metrics) Middleware

func (m *Metrics) Middleware(tracingEnabled bool) func(c *gin.Context)

Middleware returns a gin middleware that records metrics for each HTTP request.

type MetricsConfig

type MetricsConfig struct {
	Enabled      bool    `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
	Address      string  `json:"address,omitempty" yaml:"address" mapstructure:"address"`
	TLS          tls.TLS `json:"tls" yaml:"tls" mapstructure:"tls"`
	PushInterval int64   `json:"pushInterval,omitempty" yaml:"pushInterval" mapstructure:"pushInterval"`
}

MetricsConfig configures the metrics for the application (over OpenTelemetry GRPC).

type Observability

type Observability interface {
	Shutdown(ctx context.Context) error
	Span(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func())
	LogSpan(ctx context.Context, spanName string, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx)
	LogSpanWithTimeout(ctx context.Context, spanName string, timeout time.Duration, fields ...zap.Field) (context.Context, func(), otelzap.LoggerWithCtx)
	Log() *otelzap.Logger
	Metrics() *Metrics
	SetupGinMiddleware(router *gin.Engine)
	WithSpanKind(spanKind trace.SpanKind) *Impl
	IsTracingEnabled() bool
	IsProfilingEnabled() bool
	AreMetricsEnabled() bool
	metric.MeterProvider
}

func NewNoopObservability

func NewNoopObservability() Observability

type OtelLogger added in v0.2.1

type OtelLogger struct {
	Address string   `yaml:"address" json:"address,omitempty" mapstructure:"address"`
	TLS     *tls.TLS `yaml:"tls" json:"tls,omitempty" mapstructure:"tls"`
}

type Profiling

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

func NewProfiler

func NewProfiler(name string, config ProfilingConfig) (*Profiling, error)

func (*Profiling) Shutdown

func (p *Profiling) Shutdown() error

type ProfilingConfig

type ProfilingConfig struct {
	Enabled   bool   `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
	Address   string `json:"address,omitempty" yaml:"address" mapstructure:"address"`
	AuthToken string `json:"authToken,omitempty" yaml:"authToken" mapstructure:"authToken"`
}

type ServiceInfo

type ServiceInfo struct {
	Name    string
	Version string
}

type Tracing

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

func NewTracing

func NewTracing(ctx context.Context, info ServiceInfo, config TracingConfig) (*Tracing, error)

NewTracing creates a new tracing instance

func (*Tracing) Shutdown

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

func (*Tracing) Tracer

func (t *Tracing) Tracer() trace.Tracer

func (*Tracing) TracerProvider added in v0.2.0

func (t *Tracing) TracerProvider() trace.TracerProvider

type TracingConfig

type TracingConfig struct {
	Enabled bool    `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
	Address string  `json:"address,omitempty" yaml:"address" mapstructure:"address"`
	TLS     tls.TLS `json:"tls" yaml:"tls" mapstructure:"tls"`
}

TracingConfig configures the tracing for the application (over OpenTelemetry GRPC).

Jump to

Keyboard shortcuts

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