config

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config provides the configuration for the logger and the monitoring. The package also provides the Otel convention for root labels.

Index

Constants

View Source
const (
	SERVICE_NAME       = string(semconv.ServiceNameKey)
	SERVICE_VERSION    = string(semconv.ServiceVersionKey)
	SERVICE_INTANCE_ID = string(semconv.ServiceInstanceIDKey)
)

attribute names for the common tags that will be applied to every trace, span and log

View Source
const (
	FILE_PATH             = string(semconv.CodeFilepathKey)
	LINE_NUMBER           = string(semconv.CodeLineNumberKey)
	FUNCTION_NAME         = string(semconv.CodeFunctionKey)
	FUNCTION_PACKAGE_NAME = string(semconv.CodeNamespaceKey)
)

attribute names for the caller tags that will be applied to every trace, span and log

View Source
const (
	LOG_MESSAGE_KEY  = "message"
	LOG_ERROR_KEY    = "error"
	LOG_METADATA_KEY = "metadata"
)

attribute names for the logger

View Source
const (
	EXPORTER_PROTOCOL = "otel.exporter.protocol"
)

exporter attributes

Variables

This section is empty.

Functions

func ResetMonitoringConfig added in v1.2.0

func ResetMonitoringConfig()

ResetMonitoringConfig resets the singleton state. This function is primarily intended for testing purposes.

Types

type Logger

type Logger struct {
	LogLevelCfg string `env:"LOG_LEVEL" envDefault:"info"`

	Monitoring
}

func NewLoggerConfig

func NewLoggerConfig(opts ...Option) Logger

LoggerConfig returns the Logger configuration from the environment.

func (Logger) LogLevel

func (l Logger) LogLevel() string

LogLevel returns the minimum log level for the logger. Possible values could be error, warn, info, debug

func (Logger) Service

func (l Logger) Service() string

Service returns the service name for application tagging.

type LoggerConfig

type LoggerConfig interface {
	LogLevel() string
	Service() string
}

type Monitoring

type Monitoring struct {
	// Generic configuration
	ServiceCfg      string `env:"OTEL_SERVICE_NAME"`
	TestExporterCfg bool   `env:"OTEL_EXPORTER_OTLP_TEST"` // Specifies whether the OTLP exporter should be used in test mode.
	// Exporter configuration
	ExporterProtocolCfg string `env:"OTEL_EXPORTER_OTLP_PROTOCOL"` // Specifies the OTLP transport protocol to be used for all telemetry data.
	// Traces configuration
	ExporterTraceProtocolCfg string `env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"` // Specifies the OTLP transport protocol to be used for trace data.
	// Metrics configuration
	ExporterMetricsProtocolCfg string  `env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL"` // Specifies the OTLP transport protocol to be used for metric data.
	MetricsIntervalCfg         float64 `env:"OTEL_METRICS_INTERVAL_SECONDS"`       // Specifies the interval at which metrics are exported.
}

func NewMonitoringConfig

func NewMonitoringConfig(opts ...Option) Monitoring

func (Monitoring) ExporterMetricsProtocol

func (d Monitoring) ExporterMetricsProtocol() string

ExporterMetricsProtocol returns the protocol used by the OTLP Metrics exporter. If both `OTEL_EXPORTER_OTLP_PROTOCOL` and `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL` are present, `OTEL_EXPORTER_OTLP_METRICS_PROTOCOL` takes higher precedence.

func (Monitoring) ExporterTracesProtocol

func (d Monitoring) ExporterTracesProtocol() string

ExporterTracesProtocol returns the protocol used by the OTLP Trace exporter. If both `OTEL_EXPORTER_OTLP_PROTOCOL` and `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` are present, `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` takes higher precedence.

func (Monitoring) IsTestExporter

func (d Monitoring) IsTestExporter() bool

IsTestExporter returns whether the OTLP exporter should be used in test mode.

func (Monitoring) MetricsInterval added in v1.2.0

func (d Monitoring) MetricsInterval() time.Duration

MetricsInterval returns the interval at which metrics are exported. If the metrics interval is not set, it returns the default metrics interval. If the metrics interval is set to a negative value, it returns the default metrics interval.

func (Monitoring) Service

func (d Monitoring) Service() string

Service returns the service name for application tagging.

type MonitoringConfig

type MonitoringConfig interface {
	// Generic configuration
	Service() string
	IsTestExporter() bool
	// Traces configuration
	ExporterTracesProtocol() string
	// Metrics configuration
	ExporterMetricsProtocol() string
	MetricsInterval() time.Duration
}

type Option

type Option func(*parseConfig)

Option is a function that modifies the parseConfig. The only implemented option is WithEnvironment, which is used for testing.

Jump to

Keyboard shortcuts

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