Documentation
¶
Overview ¶
Package common defines the necessary types to configure the application. This minimal configuration is tailored for logging.
Index ¶
- Constants
- func LoadConfig[T any | BaseConfig](cfg T, defaults map[string]any, paths ...string) error
- func LoadValueFromSourceRef(cred SourceRef) ([]byte, error)
- func UpdateConfigVersion(cfg *BaseConfig, buildInfo string) error
- type Application
- type Audit
- type BaseConfig
- type BasicAuth
- type BuildInfo
- type CredentialFile
- type FileFormat
- type GRPCClient
- type GRPCClientAttributes
- type GRPCServer
- type GRPCServerAttributes
- type Loader
- type Log
- type Logger
- type LoggerFields
- type LoggerFieldsMasking
- type LoggerFormat
- type LoggerFormatter
- type LoggerOTel
- type LoggerTime
- type LoggerTimeType
- type MTLS
- type Metric
- type Option
- type Prometheus
- type Protocol
- type SecretRef
- type SecretType
- type SourceRef
- type SourceValueType
- type Status
- type Telemetry
- type Trace
Constants ¶
const ( AttrService = "service" AttrLabels = "labels" AttrName = "name" AttrRequestID = "requestId" AttrOperation = "operation" AttrEnvironment = "environment" )
const ( // Logger format types. JSONLoggerFormat LoggerFormat = "json" TextLoggerFormat LoggerFormat = "text" // Logger time types. UnixTimeLogger LoggerTimeType = "unix" PatternTimeLogger LoggerTimeType = "pattern" GRPCProtocol Protocol = "grpc" HTTPProtocol Protocol = "http" InsecureSecretType SecretType = "insecure" MTLSSecretType SecretType = "mtls" ApiTokenSecretType SecretType = "api-token" BasicSecretType SecretType = "basic" EmbeddedSourceValue SourceValueType = "embedded" EnvSourceValue SourceValueType = "env" FileSourceValue SourceValueType = "file" JSONFileFormat FileFormat = "json" BinaryFileFormat FileFormat = "binary" )
Variables ¶
This section is empty.
Functions ¶
func LoadConfig ¶
LoadConfig is a convenience function to load the config file from the specified paths
func LoadValueFromSourceRef ¶
func UpdateConfigVersion ¶
func UpdateConfigVersion(cfg *BaseConfig, buildInfo string) error
Types ¶
type Application ¶
type Application struct {
Name string `yaml:"name" json:"name"`
Environment string `yaml:"environment" json:"environment"`
Labels map[string]string `yaml:"labels" json:"labels"`
BuildInfo BuildInfo
RuntimeBuildInfo *debug.BuildInfo
}
Application holds minimal application configuration.
type Audit ¶
type Audit struct {
Endpoint string `yaml:"endpoint" json:"endpoint"`
// Potential mTLS for the endpoint.
MTLS *MTLS `yaml:"mtls" json:"mtls"`
// Potential BasicAuth for the endpoint.
BasicAuth *BasicAuth `yaml:"basicAuth" json:"basicAuth"`
// Optional set of additional properties to be added to OTLP log object. Must be added as a literal string to maintain casing.
AdditionalProperties string `yaml:"additionalProperties" json:"additionalProperties"`
}
Audit holds the audit log library configuration.
type BaseConfig ¶
type BaseConfig struct {
Application Application `yaml:"application" json:"application"`
Status Status `yaml:"status" json:"status"`
Logger Logger `yaml:"logger" json:"logger"`
Telemetry Telemetry `yaml:"telemetry" json:"telemetry"`
Audit Audit `yaml:"audit" json:"audit"`
}
type BasicAuth ¶
type BasicAuth struct {
Username SourceRef `yaml:"username" json:"username"`
Password SourceRef `yaml:"password" json:"password"`
}
BasicAuth holds basic auth configuration for audit library.
type BuildInfo ¶
type BuildInfo struct {
Branch string `json:"branch"`
BuildWorkflowId string `json:"buildWorkflowId"`
Org string `json:"org"`
Product string `json:"product"`
ReleaseMetadata string `json:"releaseMetadata"`
Repo string `json:"repo"`
SHA string `json:"sha"`
SecurityScan string `json:"securityScan"`
Version string `json:"version"`
// contains filtered or unexported fields
}
BuildInfo holds metadata about the build
type CredentialFile ¶
type CredentialFile struct {
Path string `yaml:"path" json:"path"`
Format FileFormat `yaml:"format" json:"format"`
JSONPath string `yaml:"jsonPath" json:"jsonPath"`
}
CredentialFile describes a file-based credential.
type GRPCClient ¶
type GRPCClient struct {
Address string `yaml:"address" json:"address"`
Attributes GRPCClientAttributes `yaml:"attributes" json:"attributes"`
}
GRPCClient specifies the gRPC client configuration e.g. used by the gRPC health check client.
type GRPCClientAttributes ¶
type GRPCServer ¶
type GRPCServer struct {
Address string `yaml:"address" json:"address"`
MaxRecvMsgSize int `yaml:"maxRecvMsgSize" json:"maxRecvMsgSize"`
EfPolMinTime int `yaml:"efPolMinTime" json:"efPolMinTime"`
EfPolPermitWithoutStream bool `yaml:"efPolPermitWithoutStream" json:"efPolPermitWithoutStream"`
Attributes GRPCServerAttributes `yaml:"attributes" json:"attributes"`
}
GRPCServer specifies the gRPC server configuration e.g. used by the business gRPC server if any.
type GRPCServerAttributes ¶
type GRPCServerAttributes struct {
MaxConnectionIdle int `yaml:"maxConnectionIdle" json:"maxConnectionIdle"`
MaxConnectionAge int `yaml:"maxConnectionAge" json:"maxConnectionAge"`
MaxConnectionAgeGrace int `yaml:"maxConnectionAgeGrace" json:"maxConnectionAgeGrace"`
Time int `yaml:"time" json:"time"`
Timeout int `yaml:"timeout" json:"timeout"`
}
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is used to load configuration from a `config.yaml` file. It supports loading from multiple paths and can override values with environment variables. It is instantiated by using the NewLoader function that supports multiple options.
func (*Loader) LoadConfig ¶
LoadConfig loads the config from the specified paths and environment variables
type Log ¶
type Log struct {
Enabled bool `yaml:"enabled" json:"enabled"`
Protocol Protocol `yaml:"protocol" json:"protocol"`
Host SourceRef `yaml:"host" json:"host"`
URL string `yaml:"url" json:"url"`
SecretRef SecretRef `yaml:"secretRef" json:"secretRef"`
}
Log defines settings for structured logging export.
type Logger ¶
type Logger struct {
Source bool `yaml:"source" json:"source"`
Format LoggerFormat `yaml:"format" json:"format"`
Level string `yaml:"level" json:"level"`
Formatter LoggerFormatter `yaml:"formatter" json:"formatter"`
}
Logger holds the configuration for logging.
type LoggerFields ¶
type LoggerFields struct {
Time string `yaml:"time" json:"time"`
Error string `yaml:"error" json:"error"`
Level string `yaml:"level" json:"level"`
Message string `yaml:"message" json:"message"`
OTel LoggerOTel `yaml:"otel" json:"otel"`
Masking LoggerFieldsMasking `yaml:"masking" json:"masking"`
}
LoggerFields holds the mapping of log attributes.
type LoggerFieldsMasking ¶
type LoggerFieldsMasking struct {
PII []string `yaml:"pii" json:"pii"`
Other map[string]string `yaml:"other" json:"other"`
}
LoggerFieldsMasking holds configuration for masking log fields.
type LoggerFormatter ¶
type LoggerFormatter struct {
Time LoggerTime `yaml:"time" json:"time"`
Fields LoggerFields `yaml:"fields" json:"fields"`
}
LoggerFormatter holds the logger formatter configuration.
type LoggerOTel ¶
type LoggerOTel struct {
TraceID string `yaml:"traceId" json:"traceId"`
SpanID string `yaml:"spanId" json:"spanId"`
}
LoggerOtel holds configuration for the OpenTelemetry fields.
type LoggerTime ¶
type LoggerTime struct {
Type LoggerTimeType `yaml:"type" json:"type"`
Pattern string `yaml:"pattern" json:"pattern"`
Precision string `yaml:"precision" json:"precision"`
}
LoggerTime holds configuration for the time formatting in logs.
type LoggerTimeType ¶
type LoggerTimeType string
LoggerTimeType is used to specify the type of time formatting.
type MTLS ¶
type MTLS struct {
Cert SourceRef `yaml:"cert" json:"cert"`
CertKey SourceRef `yaml:"certKey" json:"certKey"`
ServerCA SourceRef `yaml:"serverCa" json:"serverCa"`
}
MTLS holds mTLS configuration for audit library.
type Metric ¶
type Metric struct {
Enabled bool `yaml:"enabled" json:"enabled"`
Protocol Protocol `yaml:"protocol" json:"protocol"`
Host SourceRef `yaml:"host" json:"host"`
URL string `yaml:"url" json:"url"`
SecretRef SecretRef `yaml:"secretRef" json:"secretRef"`
Prometheus Prometheus `yaml:"prometheus" json:"prometheus"`
}
Metric defines settings for metrics export and Prometheus.
type Option ¶
type Option func(*Loader)
func WithDefaults ¶
WithDefaults sets the default values for the config loader
func WithEnvOverride ¶
WithEnvOverride activates the environment variable override option with an optional prefix To override a config value, the environment variable should be named as: <ENVPREFIX>_<KEY1>_<KEY2>_<KEY3>_... (all uppercase) If the prefix is not set, the environment variable should be named as: <KEY1>_<KEY2>_<KEY3>_... (all uppercase)
type Prometheus ¶
type Prometheus struct {
Enabled bool `yaml:"enabled" json:"enabled"`
}
Prometheus defines configuration for Prometheus integration.
type SecretRef ¶
type SecretRef struct {
Type SecretType `yaml:"type" json:"type"`
MTLS MTLS `yaml:"mtls" json:"mtls"`
APIToken SourceRef `yaml:"apiToken" json:"apiToken"`
Basic BasicAuth `yaml:"basic" json:"basic"`
}
SecretRef defines how credentials or certificates are provided.
type SecretType ¶
type SecretType string
SecretType defines the type of secret used for authentication.
type SourceRef ¶
type SourceRef struct {
Source SourceValueType `yaml:"source" json:"source"`
Env string `yaml:"env" json:"env"`
File CredentialFile `yaml:"file" json:"file"`
Value string `yaml:"value" json:"value"`
}
SourceRef defines a reference to a source for retrieving a value.
type SourceValueType ¶
type SourceValueType string
SourceValueType represents the source type for retrieving configuration values.
type Telemetry ¶
type Telemetry struct {
DynatraceOneAgent bool `yaml:"dynatraceOneAgent" json:"dynatraceOneAgent"`
Traces Trace `yaml:"traces" json:"traces"`
Metrics Metric `yaml:"metrics" json:"metrics"`
Logs Log `yaml:"logs" json:"logs"`
}
Telemetry defines the configuration for telemetry components.
type Trace ¶
type Trace struct {
Enabled bool `yaml:"enabled" json:"enabled"`
Protocol Protocol `yaml:"protocol" json:"protocol"`
Host SourceRef `yaml:"host" json:"host"`
URL string `yaml:"url" json:"url"`
SecretRef SecretRef `yaml:"secretRef" json:"secretRef"`
}
Trace defines settings for distributed tracing.