config

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 2 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

This section is empty.

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 {
	ServiceCfg                 string `env:"OTEL_SERVICE_NAME"`
	ExporterProtocolCfg        string `env:"OTEL_EXPORTER_OTLP_PROTOCOL"`         // Specifies the OTLP transport protocol to be used for all telemetry data.
	ExporterTraceProtocolCfg   string `env:"OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"`  // Specifies the OTLP transport protocol to be used for trace data.
	ExporterMetricsProtocolCfg string `env:"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL"` // Specifies the OTLP transport protocol to be used for metric data.
	TestExporterCfg            bool   `env:"OTEL_EXPORTER_OTLP_TEST"`             // Specifies whether the OTLP exporter should be used in test mode.
}

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.

func (Monitoring) ExporterTracesProtocol

func (d Monitoring) ExporterTracesProtocol() string

ExporterTracesProtocol returns the protocol used by the OTLP Trace exporter.

func (Monitoring) IsTestExporter

func (d Monitoring) IsTestExporter() bool

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

func (Monitoring) Service

func (d Monitoring) Service() string

Service returns the service name for application tagging.

type MonitoringConfig

type MonitoringConfig interface {
	Service() string
	ExporterTracesProtocol() string
	ExporterMetricsProtocol() string
	IsTestExporter() bool
}

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