telemetry

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 26 Imported by: 0 modules, 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

Overview

Package telemetry provides OpenTelemetry initialization and management

Index

Constants

View Source
const DefaultShutdownTimeout = 10 * time.Second

DefaultShutdownTimeout is the default timeout for telemetry shutdown

Variables

This section is empty.

Functions

func MergeResourceAttributes

func MergeResourceAttributes(base *resource.Resource, attrs map[string]string) (*resource.Resource, error)

MergeResourceAttributes merges additional attributes into an existing resource

func RegisterMetricsEndpoint

func RegisterMetricsEndpoint(e *echo.Echo, provider *Provider, config *Config) error

RegisterMetricsEndpoint registers the metrics endpoint with Echo router

func Shutdown

func Shutdown(provider *Provider) error

Shutdown gracefully shuts down the telemetry provider with a timeout

func ShutdownWithTimeout

func ShutdownWithTimeout(provider *Provider, timeout time.Duration) error

ShutdownWithTimeout gracefully shuts down the telemetry provider with a custom timeout

func ValidateExporterConfig

func ValidateExporterConfig(config *Config) error

ValidateExporterConfig validates the exporter configuration

func WithShutdownTimeout

func WithShutdownTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)

WithShutdownTimeout creates a context with a timeout for shutdown operations

Types

type ApplicationMetricsFilter

type ApplicationMetricsFilter struct {
	*DefaultMetricsFilter
}

ApplicationMetricsFilter filters to show only application-specific metrics

func NewApplicationMetricsFilter

func NewApplicationMetricsFilter() *ApplicationMetricsFilter

NewApplicationMetricsFilter creates a filter for application metrics only

type Config

type Config struct {
	Enabled            bool
	ServiceName        string
	ServiceVersion     string
	OTLPEndpoint       string
	OTLPHeaders        map[string]string
	OTLPInsecure       bool
	PrometheusEnabled  bool
	PrometheusEndpoint string
	JaegerEnabled      bool
	JaegerEndpoint     string
	TracingEnabled     bool
	TracingSampleRate  float64
	MetricsEnabled     bool
	MetricsInterval    int
	ResourceAttributes map[string]string
}

Config holds the telemetry configuration

func LoadConfigFromViper

func LoadConfigFromViper() (*Config, error)

LoadConfigFromViper loads telemetry configuration from Viper

type DefaultMetricsFilter

type DefaultMetricsFilter struct {
	IncludePatterns []*regexp.Regexp
	ExcludePatterns []*regexp.Regexp
	IncludePrefixes []string
	ExcludePrefixes []string
}

DefaultMetricsFilter implements basic filtering based on patterns

func NewDefaultMetricsFilter

func NewDefaultMetricsFilter() *DefaultMetricsFilter

NewDefaultMetricsFilter creates a new default metrics filter

func (*DefaultMetricsFilter) AddExcludePattern

func (f *DefaultMetricsFilter) AddExcludePattern(pattern string) error

AddExcludePattern adds a regex pattern for metrics to exclude

func (*DefaultMetricsFilter) AddExcludePrefix

func (f *DefaultMetricsFilter) AddExcludePrefix(prefix string)

AddExcludePrefix adds a prefix for metrics to exclude

func (*DefaultMetricsFilter) AddIncludePattern

func (f *DefaultMetricsFilter) AddIncludePattern(pattern string) error

AddIncludePattern adds a regex pattern for metrics to include

func (*DefaultMetricsFilter) AddIncludePrefix

func (f *DefaultMetricsFilter) AddIncludePrefix(prefix string)

AddIncludePrefix adds a prefix for metrics to include

func (*DefaultMetricsFilter) FilterRegistry

func (f *DefaultMetricsFilter) FilterRegistry(registry *prometheus.Registry) prometheus.Gatherer

FilterRegistry returns a filtered gatherer

func (*DefaultMetricsFilter) ShouldIncludeMetric

func (f *DefaultMetricsFilter) ShouldIncludeMetric(name string, _ map[string]string) bool

ShouldIncludeMetric determines if a metric should be included

type Exporter

type Exporter interface {
	Shutdown(context.Context) error
}

Exporter represents an OpenTelemetry exporter

type ExporterFactory

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

ExporterFactory creates exporters based on configuration

func NewExporterFactory

func NewExporterFactory(config *Config) *ExporterFactory

NewExporterFactory creates a new exporter factory

func (*ExporterFactory) CreateMetricExporters

func (f *ExporterFactory) CreateMetricExporters(ctx context.Context) ([]metric.Reader, error)

CreateMetricExporters creates metric exporters based on configuration

func (*ExporterFactory) CreateTraceExporters

func (f *ExporterFactory) CreateTraceExporters(ctx context.Context) ([]sdktrace.SpanExporter, error)

CreateTraceExporters creates trace exporters based on configuration

type HealthMetrics

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

HealthMetrics provides health-related metrics

func NewHealthMetrics

func NewHealthMetrics(meter metric.Meter, serviceName, serviceVersion string) (*HealthMetrics, error)

NewHealthMetrics creates health-related metrics

func (*HealthMetrics) RecordHealthCheck

func (hm *HealthMetrics) RecordHealthCheck(ctx context.Context, status string)

RecordHealthCheck records a health check metric

type MetricsFilter

type MetricsFilter interface {
	FilterRegistry(registry *prometheus.Registry) prometheus.Gatherer
	ShouldIncludeMetric(name string, labels map[string]string) bool
}

MetricsFilter defines interface for filtering metrics

func CreateFilterFromConfig

func CreateFilterFromConfig(_ *Config) MetricsFilter

CreateFilterFromConfig creates a metrics filter based on configuration

type MetricsHandler

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

MetricsHandler manages Prometheus metrics endpoint

func NewMetricsHandler

func NewMetricsHandler(provider *Provider, config *Config) (*MetricsHandler, error)

NewMetricsHandler creates a new metrics handler

func (*MetricsHandler) EchoHandler

func (h *MetricsHandler) EchoHandler() echo.HandlerFunc

EchoHandler returns an Echo handler for Prometheus metrics

func (*MetricsHandler) Handler

func (h *MetricsHandler) Handler() http.Handler

Handler returns the HTTP handler for Prometheus metrics

type Provider

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

Provider manages OpenTelemetry providers and their lifecycle

func Initialize

func Initialize(ctx context.Context) (*Provider, error)

Initialize sets up OpenTelemetry with the provided configuration

func InitializeWithConfig

func InitializeWithConfig(ctx context.Context, cfg *Config) (*Provider, error)

InitializeWithConfig sets up OpenTelemetry with a custom configuration

func MustInitialize

func MustInitialize(ctx context.Context) *Provider

MustInitialize initializes telemetry and panics on error

func NewProvider

func NewProvider(ctx context.Context, config *Config) (*Provider, error)

NewProvider creates a new telemetry provider with the given configuration

func (*Provider) GetMeter

func (p *Provider) GetMeter(name string, opts ...metric.MeterOption) metric.Meter

GetMeter returns a meter for the given name

func (*Provider) GetResource

func (p *Provider) GetResource() *resource.Resource

GetResource returns the telemetry resource

func (*Provider) GetTracer

func (p *Provider) GetTracer(name string, opts ...trace.TracerOption) trace.Tracer

GetTracer returns a tracer for the given name

func (*Provider) GetTracerProvider

func (p *Provider) GetTracerProvider() trace.TracerProvider

GetTracerProvider returns the underlying trace provider

func (*Provider) IsEnabled

func (p *Provider) IsEnabled() bool

IsEnabled returns whether telemetry is enabled

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all telemetry providers

type SystemMetricsFilter

type SystemMetricsFilter struct {
	*DefaultMetricsFilter
}

SystemMetricsFilter filters to show only system-level metrics

func NewSystemMetricsFilter

func NewSystemMetricsFilter() *SystemMetricsFilter

NewSystemMetricsFilter creates a filter for system metrics only

Jump to

Keyboard shortcuts

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