obi

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 31 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FeatureAppO11y = Feature(1 << iota)
	FeatureNetO11y
)
View Source
const (
	LogConfigOptionYAML = LogConfigOption("yaml")
	LogConfigOptionJSON = LogConfigOption("json")
)
View Source
const (
	EbpfSourceTC                 = "tc"
	EbpfSourceSock               = "socket_filter"
	NetworkListenInterfacesWatch = "watch"
	NetworkListenInterfacesPoll  = "poll"
	NetworkAgentIPIfaceExternal  = "external"
	NetworkAgentIPIfaceLocal     = "local"
)
View Source
const ReporterLRUSize = 256

Variables

View Source
var DefaultConfig = Config{
	ChannelBufferLen: 10,
	LogLevel:         LogLevelInfo,
	ShutdownTimeout:  10 * time.Second,
	EnforceSysCaps:   false,
	EBPF: config.EBPFTracer{
		BatchLength:        100,
		BatchTimeout:       time.Second,
		HTTPRequestTimeout: 0,
		TCBackend:          config.TCBackendAuto,
		DNSRequestTimeout:  5 * time.Second,
		ContextPropagation: config.ContextPropagationDisabled,
		RedisDBCache: config.RedisDBCacheConfig{
			Enabled: false,
			MaxSize: 1000,
		},
		BufferSizes: config.EBPFBufferSizes{
			HTTP:     0,
			MySQL:    0,
			Postgres: 0,
		},
		MySQLPreparedStatementsCacheSize:    1024,
		PostgresPreparedStatementsCacheSize: 1024,
		MongoRequestsCacheSize:              1024,
		KafkaTopicUUIDCacheSize:             1024,
		OverrideBPFLoopEnabled:              false,
		PayloadExtraction: config.PayloadExtraction{
			HTTP: config.HTTPConfig{
				GraphQL: config.GraphQLConfig{
					Enabled: false,
				},
				Elasticsearch: config.ElasticsearchConfig{
					Enabled: false,
				},
				AWS: config.AWSConfig{
					Enabled: false,
				},
			},
		},
		MaxTransactionTime: 5 * time.Minute,
	},
	NameResolver: &transform.NameResolverConfig{
		Sources:  []transform.Source{transform.SourceK8s},
		CacheLen: 1024,
		CacheTTL: 5 * time.Minute,
	},
	Metrics: perapp.MetricsConfig{
		Features: export.FeatureApplicationRED,
	},
	OTELMetrics: otelcfg.MetricsConfig{
		Protocol:        otelcfg.ProtocolUnset,
		MetricsProtocol: otelcfg.ProtocolUnset,

		OTELIntervalMS:       60_000,
		Buckets:              export.DefaultBuckets,
		ReportersCacheLen:    ReporterLRUSize,
		HistogramAggregation: otel.AggregationExplicit,
		Instrumentations: []instrumentations.Instrumentation{
			instrumentations.InstrumentationALL,
		},
		TTL: defaultMetricsTTL,
	},
	Traces: otelcfg.TracesConfig{
		Protocol:          otelcfg.ProtocolUnset,
		TracesProtocol:    otelcfg.ProtocolUnset,
		MaxQueueSize:      4096,
		BatchTimeout:      15 * time.Second,
		ReportersCacheLen: ReporterLRUSize,
		Instrumentations: []instrumentations.Instrumentation{
			instrumentations.InstrumentationHTTP,
			instrumentations.InstrumentationGRPC,
			instrumentations.InstrumentationSQL,
			instrumentations.InstrumentationRedis,
			instrumentations.InstrumentationKafka,
			instrumentations.InstrumentationMongo,
		},
	},
	Prometheus: prom.PrometheusConfig{
		Path:    "/metrics",
		Buckets: export.DefaultBuckets,
		Instrumentations: []instrumentations.Instrumentation{
			instrumentations.InstrumentationALL,
		},
		TTL:                         defaultMetricsTTL,
		SpanMetricsServiceCacheSize: 10000,
	},
	TracePrinter: debug.TracePrinterDisabled,
	InternalMetrics: imetrics.Config{
		Exporter: imetrics.InternalMetricsExporterDisabled,
		Prometheus: imetrics.PrometheusConfig{
			Port: 0,
			Path: "/internal/metrics",
		},
		BpfMetricScrapeInterval: 15 * time.Second,
	},
	Attributes: Attributes{
		InstanceID: config.InstanceIDConfig{
			HostnameDNSResolution: true,
		},
		Kubernetes: transform.KubernetesDecorator{
			Enable:                kubeflags.EnabledDefault,
			InformersSyncTimeout:  30 * time.Second,
			InformersResyncPeriod: 30 * time.Minute,
			ResourceLabels:        kube.DefaultResourceLabels,
		},
		HostID: HostIDConfig{
			FetchTimeout: 500 * time.Millisecond,
		},
		RenameUnresolvedHosts:          "unresolved",
		RenameUnresolvedHostsOutgoing:  "outgoing",
		RenameUnresolvedHostsIncoming:  "incoming",
		MetricSpanNameAggregationLimit: 100,
	},
	Routes: &transform.RoutesConfig{
		Unmatch:                   transform.UnmatchDefault,
		WildcardChar:              "*",
		MaxPathSegmentCardinality: 10,
	},
	NetworkFlows: DefaultNetworkConfig,
	Discovery: services.DiscoveryConfig{
		ExcludeOTelInstrumentedServices: true,
		DefaultExcludeServices: services.RegexDefinitionCriteria{
			services.RegexSelector{
				Path: services.NewRegexp("(?:^|/)(beyla$|alloy$|otelcol[^/]*$)"),
			},
			services.RegexSelector{
				Metadata: map[string]*services.RegexpAttr{"k8s_namespace": &k8sDefaultNamespacesRegex},
			},
		},
		DefaultExcludeInstrument: services.GlobDefinitionCriteria{
			services.GlobAttributes{
				Path: services.NewGlob("{*beyla,*alloy,*ebpf-instrument,*otelcol,*otelcol-contrib,*otelcol-contrib[!/]*}"),
			},
			services.GlobAttributes{
				Metadata: map[string]*services.GlobAttr{"k8s_namespace": &k8sDefaultNamespacesGlob},
			},
		},
		MinProcessAge:         5 * time.Second,
		DefaultOtlpGRPCPort:   4317,
		RouteHarvesterTimeout: 10 * time.Second,
		RouteHarvestConfig: services.RouteHarvestingConfig{
			JavaHarvestDelay: 60 * time.Second,
		},
	},
	NodeJS: NodeJSConfig{
		Enabled: true,
	},
	Java: JavaConfig{
		Enabled: true,
		Timeout: 10 * time.Second,
	},
}
View Source
var DefaultNetworkConfig = NetworkConfig{
	Source:             EbpfSourceSock,
	AgentIPIface:       "external",
	AgentIPType:        "any",
	ExcludeInterfaces:  []string{"lo"},
	CacheMaxFlows:      5000,
	CacheActiveTimeout: 5 * time.Second,
	Deduper:            flowdef.DeduperFirstCome,
	Direction:          "both",
	ListenInterfaces:   "watch",
	ListenPollPeriod:   10 * time.Second,
	ReverseDNS: flow.ReverseDNS{
		Type:     flow.ReverseDNSNone,
		CacheLen: 256,
		CacheTTL: time.Hour,
	},
	GeoIP: flow.GeoIP{
		CacheLen: 512,
		CacheTTL: time.Hour,
	},
}

Functions

func CheckOSCapabilities

func CheckOSCapabilities(config *Config) error

func CheckOSSupport

func CheckOSSupport() error

CheckOSSupport returns an error if the running operating system does not support the minimum required Beyla features.

func KernelVersion

func KernelVersion() (major, minor int)

func ValidateAgentIPIface

func ValidateAgentIPIface(fl validator.FieldLevel) bool

ValidateAgentIPIface checks if the string starts with "name:" and then checks if there is something after "name:"

Types

type Attributes

type Attributes struct {
	Kubernetes           transform.KubernetesDecorator `yaml:"kubernetes"`
	InstanceID           config.InstanceIDConfig       `yaml:"instance_id"`
	Select               attributes.Selection          `yaml:"select"`
	HostID               HostIDConfig                  `yaml:"host_id"`
	ExtraGroupAttributes map[string][]attr.Name        `yaml:"extra_group_attributes"`

	// RenameUnresolvedHosts will replace HostName and PeerName attributes when they are empty or contain
	// unresolved IP addresses to reduce cardinality.
	// Set this value to the empty string to disable this feature.
	RenameUnresolvedHosts         string `yaml:"rename_unresolved_hosts" env:"OTEL_EBPF_RENAME_UNRESOLVED_HOSTS"`
	RenameUnresolvedHostsOutgoing string `yaml:"rename_unresolved_hosts_outgoing" env:"OTEL_EBPF_RENAME_UNRESOLVED_HOSTS_OUTGOING"`
	RenameUnresolvedHostsIncoming string `yaml:"rename_unresolved_hosts_incoming" env:"OTEL_EBPF_RENAME_UNRESOLVED_HOSTS_INCOMING"`

	// MetricSpanNameAggregationLimit works PER SERVICE and only relates to span_metrics.
	// When the span_name cardinality surpasses this limit, the span_name will be reported as AGGREGATED.
	// If the value <= 0, it is disabled.
	MetricSpanNameAggregationLimit int `yaml:"metric_span_names_limit" env:"OTEL_EBPF_METRIC_SPAN_NAMES_LIMIT"`
}

Attributes configures the decoration of some extra attributes that will be added to each span

type Config

type Config struct {
	EBPF config.EBPFTracer `yaml:"ebpf"`

	// NetworkFlows configuration for Network Observability feature
	NetworkFlows NetworkConfig `yaml:"network"`

	Filters filter.AttributesConfig `yaml:"filter"`

	Attributes Attributes `yaml:"attributes"`
	// Routes is an optional node. If not set, data will be directly forwarded to exporters.
	Routes       *transform.RoutesConfig       `yaml:"routes"`
	NameResolver *transform.NameResolverConfig `yaml:"name_resolver"`
	OTELMetrics  otelcfg.MetricsConfig         `yaml:"otel_metrics_export"`
	Traces       otelcfg.TracesConfig          `yaml:"otel_traces_export"`
	Prometheus   prom.PrometheusConfig         `yaml:"prometheus_export"`
	TracePrinter debug.TracePrinter            `yaml:"trace_printer" env:"OTEL_EBPF_TRACE_PRINTER"`

	// Exec allows selecting the instrumented executable whose complete path contains the Exec value.
	// Deprecated: Use OTEL_EBPF_AUTO_TARGET_EXE
	Exec services.RegexpAttr `yaml:"executable_path" env:"OTEL_EBPF_EXECUTABLE_PATH"`

	// AutoTargetExe selects the executable to instrument matching a Glob against the executable path.
	// To set this value via YAML, use discovery > instrument.
	// It also accepts OTEL_GO_AUTO_TARGET_EXE for compatibility with opentelemetry-go-instrumentation
	AutoTargetExe services.GlobAttr `env:"OTEL_EBPF_AUTO_TARGET_EXE,expand" envDefault:"${OTEL_GO_AUTO_TARGET_EXE}"`

	// Port allows selecting the instrumented executable that owns the Port value. If this value is set (and
	// different to zero), the value of the Exec property won't take effect.
	// It's important to emphasize that if your process opens multiple HTTP/GRPC ports, the auto-instrumenter
	// will instrument all the service calls in all the ports, not only the port specified here.
	Port services.PortEnum `yaml:"open_port" env:"OTEL_EBPF_OPEN_PORT"`

	// ServiceName is taken from either OTEL_EBPF_SERVICE_NAME env var or OTEL_SERVICE_NAME (for OTEL spec compatibility)
	// Using env and envDefault is a trick to get the value either from one of either variables.
	// Deprecated: Service name should be set in the instrumentation target (env vars, kube metadata...)
	// as this is a reminiscence of past times when we only supported one executable per instance.
	ServiceName string `yaml:"service_name" env:"OTEL_SERVICE_NAME,expand" envDefault:"${OTEL_EBPF_SERVICE_NAME}"`
	// Deprecated: Service namespace should be set in the instrumentation target (env vars, kube metadata...)
	// as this is a reminiscence of past times when we only supported one executable per instance.
	ServiceNamespace string `yaml:"service_namespace" env:"OTEL_EBPF_SERVICE_NAMESPACE"`

	// Metrics is a placeholder for the progressive support of the OTEL declarative configuration.
	Metrics perapp.MetricsConfig `yaml:"metrics"`

	// Discovery configuration
	Discovery services.DiscoveryConfig `yaml:"discovery"`

	LogLevel LogLevel `yaml:"log_level" env:"OTEL_EBPF_LOG_LEVEL"`

	// Timeout for a graceful shutdown
	ShutdownTimeout time.Duration `yaml:"shutdown_timeout" env:"OTEL_EBPF_SHUTDOWN_TIMEOUT"`

	// Check for required system capabilities and bail if they are not
	// present. If set to 'false', OBI will still print a list of missing
	// capabilities, but the execution will continue
	EnforceSysCaps bool `yaml:"enforce_sys_caps" env:"OTEL_EBPF_ENFORCE_SYS_CAPS"`

	ChannelBufferLen int             `yaml:"channel_buffer_len" env:"OTEL_EBPF_CHANNEL_BUFFER_LEN"`
	ProfilePort      int             `yaml:"profile_port" env:"OTEL_EBPF_PROFILE_PORT"`
	InternalMetrics  imetrics.Config `yaml:"internal_metrics"`

	// LogConfig enables the logging of the configuration on startup.
	LogConfig LogConfigOption `yaml:"log_config" env:"OTEL_EBPF_LOG_CONFIG"`

	NodeJS NodeJSConfig `yaml:"nodejs"`
	Java   JavaConfig   `yaml:"javaagent"`
}

func LoadConfig

func LoadConfig(file io.Reader) (*Config, error)

LoadConfig overrides configuration in the following order (from less to most priority) 1 - Default configuration (defaultConfig variable) 2 - Contents of the provided file reader (nillable) 3 - Environment variables

func (*Config) Enabled

func (c *Config) Enabled(feature Feature) bool

Enabled checks if a given OBI feature is enabled according to the global configuration

func (*Config) ExternalLogger

func (c *Config) ExternalLogger(handler slog.Handler, debugMode bool)

ExternalLogger sets the logging capabilities of OBI. Used for integrating OBI with an external logging system (for example Alloy) TODO: maybe this method has too many responsibilities, as it affects the global logger.

func (*Config) SpanMetricsEnabledForTraces

func (c *Config) SpanMetricsEnabledForTraces() bool

func (*Config) Validate

func (c *Config) Validate() error

Validate configuration

type ConfigError

type ConfigError string

func (ConfigError) Error

func (e ConfigError) Error() string

type CustomValidations

type CustomValidations map[string]validator.Func

CustomValidations is a map of tag:function for custom validations

type Feature

type Feature uint

Features that can be enabled in OBI (can be at the same time): App O11y and/or Net O11y

type HostIDConfig

type HostIDConfig struct {
	// Override allows overriding the reported host.id in OBI
	Override string `yaml:"override" env:"OTEL_EBPF_HOST_ID"`
	// FetchTimeout specifies the timeout for trying to fetch the HostID from diverse Cloud Providers
	FetchTimeout time.Duration `yaml:"fetch_timeout" env:"OTEL_EBPF_HOST_ID_FETCH_TIMEOUT"`
}

type JavaConfig added in v0.4.0

type JavaConfig struct {
	Enabled              bool          `yaml:"enabled" env:"OTEL_EBPF_JAVAAGENT_ENABLED"`
	Debug                bool          `yaml:"debug" env:"OTEL_EBPF_JAVAAGENT_DEBUG"`
	DebugInstrumentation bool          `yaml:"debug_instrumentation" env:"OTEL_EBPF_JAVAAGENT_DEBUG_INSTRUMENTATION"`
	Timeout              time.Duration `yaml:"attach_timeout" env:"OTEL_EBPF_JAVAAGENT_ATTACH_TIMEOUT" validate:"gte=0"`
}

type LogConfigOption

type LogConfigOption string

type LogLevel added in v0.3.0

type LogLevel string
const (
	LogLevelDebug LogLevel = "DEBUG"
	LogLevelInfo  LogLevel = "INFO"
	LogLevelWarn  LogLevel = "WARN"
	LogLevelError LogLevel = "ERROR"
)

type NetworkConfig

type NetworkConfig struct {
	// Enable network metrics.
	// Default value is false (disabled)
	// Deprecated: add "network" or "network_inter_zone" to OTEL_EBPF_METRICS_FEATURES
	// TODO OBI 3.0: remove
	Enable bool `yaml:"enable" env:"OTEL_EBPF_NETWORK_METRICS" validate:"boolean"`

	// Specify the source type for network events, e.g tc or socket_filter. The tc implementation
	// cannot be used when there are other tc eBPF probes, e.g. Cilium CNI.
	Source string `yaml:"source" env:"OTEL_EBPF_NETWORK_SOURCE"  validate:"oneof=tc socket_filter"`

	// AgentIP allows overriding the reported Agent IP address on each flow.
	AgentIP string `yaml:"agent_ip" env:"OTEL_EBPF_NETWORK_AGENT_IP" validate:"omitempty,ip"`

	// AgentIPIface specifies which interface should the agent pick the IP address from in order to
	// report it in the AgentIP field on each flow. Accepted values are: external (default), local,
	// or name:<interface name> (e.g. name:eth0).
	// If the AgentIP configuration property is set, this property has no effect.
	AgentIPIface string `yaml:"agent_ip_iface" env:"OTEL_EBPF_NETWORK_AGENT_IP_IFACE" validate:"agentIPIface"`
	// AgentIPType specifies which type of IP address (IPv4 or IPv6 or any) should the agent report
	// in the AgentID field of each flow. Accepted values are: any (default), ipv4, ipv6.
	// If the AgentIP configuration property is set, this property has no effect.
	AgentIPType string `yaml:"agent_ip_type" env:"OTEL_EBPF_NETWORK_AGENT_IP_TYPE" validate:"omitempty,oneof=any ipv4 ipv6"`
	// Interfaces contains the interface names from where flows will be collected. If empty, the agent
	// will fetch all the interfaces in the system, excepting the ones listed in ExcludeInterfaces.
	// If an entry is enclosed by slashes (e.g. `/br-/`), it will match as regular expression,
	// otherwise it will be matched as a case-sensitive string.
	Interfaces []string `yaml:"interfaces" env:"OTEL_EBPF_NETWORK_INTERFACES" envSeparator:"," validate:"-"`
	// ExcludeInterfaces contains the interface names that will be excluded from flow tracing. Default:
	// "lo" (loopback).
	// If an entry is enclosed by slashes (e.g. `/br-/`), it will match as regular expression,
	// otherwise it will be matched as a case-sensitive string.
	ExcludeInterfaces []string `yaml:"exclude_interfaces" env:"OTEL_EBPF_NETWORK_EXCLUDE_INTERFACES" envSeparator:"," validate:"-"`
	// Protocols causes OBI to drop flows whose transport protocol is not in this list.
	Protocols []string `yaml:"protocols" env:"OTEL_EBPF_NETWORK_PROTOCOLS" envSeparator:"," validate:"-"`
	// ExcludeProtocols causes OBI to drop flows whose transport protocol is in this list.
	// If the Protocols list is already defined, ExcludeProtocols has no effect.
	ExcludeProtocols []string `yaml:"exclude_protocols" env:"OTEL_EBPF_NETWORK_EXCLUDE_PROTOCOLS" envSeparator:"," validate:"-"`
	// CacheMaxFlows specifies how many flows can be accumulated in the accounting cache before
	// being flushed for its later export. Default value is 5000.
	// Decrease it if you see the "received message larger than max" error in OBI logs.
	CacheMaxFlows int `yaml:"cache_max_flows" env:"OTEL_EBPF_NETWORK_CACHE_MAX_FLOWS" validate:"gte=0"`
	// CacheActiveTimeout specifies the maximum duration that flows are kept in the accounting
	// cache before being flushed for its later export.
	CacheActiveTimeout time.Duration `yaml:"cache_active_timeout" env:"OTEL_EBPF_NETWORK_CACHE_ACTIVE_TIMEOUT" validate:"gte=0"`
	// Deduper specifies the deduper type. Accepted values are "none" (disabled) and "first_come".
	// When enabled, it will detect duplicate flows (flows that have been detected e.g. through
	// both the physical and a virtual interface).
	// "first_come" will forward only flows from the first interface the flows are received from.
	// Default value: first_come
	Deduper string `yaml:"deduper" env:"OTEL_EBPF_NETWORK_DEDUPER" validate:"oneof=none first_come"`
	// DeduperFCTTL specifies the expiry duration of the flows "first_come" deduplicator. After
	// a flow hasn't been received for that expiry time, the deduplicator forgets it. That means
	// that a flow from a connection that has been inactive during that period could be forwarded
	// again from a different interface.
	// If the value is not set, it will default to 2 * CacheActiveTimeout
	DeduperFCTTL time.Duration `yaml:"deduper_fc_ttl" env:"OTEL_EBPF_NETWORK_DEDUPER_FC_TTL" validate:"omitempty,gt=0"`
	// Direction allows selecting which flows to trace according to its direction. Accepted values
	// are "ingress", "egress" or "both" (default).
	Direction string `yaml:"direction" env:"OTEL_EBPF_NETWORK_DIRECTION" validate:"oneof=ingress egress both"`
	// Sampling holds the rate at which packets should be sampled and sent to the target collector.
	// E.g. if set to 100, one out of 100 packets, on average, will be sent to the target collector.
	Sampling int `yaml:"sampling" env:"OTEL_EBPF_NETWORK_SAMPLING" validate:"omitempty,gt=0"`
	// ListenInterfaces specifies the mechanism used by the agent to listen for added or removed
	// network interfaces. Accepted values are "watch" (default) or "poll".
	// If the value is "watch", interfaces are traced immediately after they are created. This is
	// the recommended setting for most configurations. "poll" value is a fallback mechanism that
	// periodically queries the current network interfaces (frequency specified by ListenPollPeriod).
	ListenInterfaces string `yaml:"listen_interfaces" env:"OTEL_EBPF_NETWORK_LISTEN_INTERFACES" validate:"oneof=watch poll"`
	// ListenPollPeriod specifies the periodicity to query the network interfaces when the
	// ListenInterfaces value is set to "poll".
	ListenPollPeriod time.Duration `yaml:"listen_poll_period" env:"OTEL_EBPF_NETWORK_LISTEN_POLL_PERIOD" validate:"gte=0"`

	GeoIP flow.GeoIP `yaml:"geo_ip"`

	// ReverseDNS allows flows that haven't been previously decorated with any source/destination name
	// to override the name with the network hostname of the source and destination IPs.
	// This is an experimental feature and it is not guaranteed to work on most virtualized environments
	// for external traffic.
	ReverseDNS flow.ReverseDNS `yaml:"reverse_dns"`
	// Print the network flows in the Standard Output, if true
	Print bool `yaml:"print_flows" env:"OTEL_EBPF_NETWORK_PRINT_FLOWS" validate:"boolean"`

	// CIDRs list, to be set as the "src.cidr" and "dst.cidr"
	// attribute as a function of the source and destination IP addresses.
	// If an IP does not match any address here, the attributes won't be set.
	// If an IP matches multiple CIDR definitions, the flow will be decorated with the
	// narrowest CIDR. By this reason, you can safely add a 0.0.0.0/0 entry to group there
	// all the traffic that does not match any of the other CIDRs.
	CIDRs cidr.Definitions `yaml:"cidrs" env:"OTEL_EBPF_NETWORK_CIDRS" envSeparator:"," validate:"omitempty,dive,cidr"`
}

type NodeJSConfig

type NodeJSConfig struct {
	Enabled bool `yaml:"enabled" env:"OTEL_EBPF_NODEJS_ENABLED"`
}

Jump to

Keyboard shortcuts

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