Documentation
¶
Overview ¶
Package config handles command-line argument parsing and OpenTelemetry configuration.
Index ¶
- func DetectSymlinkMode(mode string) (bool, error)
- func FormatVersionString(version, commit, date string) string
- type AmbientConfig
- type AmbientLimits
- type AmbientMatch
- type AmbientOTEL
- type AmbientRule
- type Config
- type CustomAttribute
- type EnvConfig
- type OTELConfig
- func (c *OTELConfig) EndpointHost() string
- func (c *OTELConfig) EndpointOptions() []otlptracehttp.Option
- func (c *OTELConfig) GetEndpoint() string
- func (c *OTELConfig) InsecureReason() string
- func (c *OTELConfig) IsInsecure() bool
- func (c *OTELConfig) ParseResourceAttributes() []attribute.KeyValue
- func (c *OTELConfig) ShutdownTimeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectSymlinkMode ¶ added in v0.5.1
DetectSymlinkMode determines if the binary is invoked via symlink. Returns true if symlink mode should be used, false for trace CLI mode.
func FormatVersionString ¶ added in v0.5.1
FormatVersionString constructs a formatted version string from components.
Types ¶
type AmbientConfig ¶ added in v0.5.0
type AmbientConfig struct {
Rules []AmbientRule `yaml:"rules"`
Limits AmbientLimits `yaml:"limits"`
OTEL AmbientOTEL `yaml:"otel"`
}
AmbientConfig holds the configuration for daemon mode.
func LoadAmbientConfig ¶ added in v0.5.0
func LoadAmbientConfig(path string) (*AmbientConfig, error)
LoadAmbientConfig loads and validates a daemon mode config from a YAML file.
type AmbientLimits ¶ added in v0.5.0
type AmbientLimits struct {
MaxConcurrentSessions int `yaml:"max_concurrent_sessions"`
MaxPIDsPerSession int `yaml:"max_pids_per_session"`
MaxTotalPIDs int `yaml:"max_total_pids"`
SessionTimeout time.Duration `yaml:"session_timeout"`
RingBufferSize int `yaml:"ring_buffer_size"`
}
AmbientLimits defines resource limits for the daemon.
type AmbientMatch ¶ added in v0.5.0
type AmbientMatch struct {
Command string `yaml:"command"` // glob pattern matched against comm (16-char kernel name)
IsContainerInit bool `yaml:"is_container_init"` // match processes that are PID 1 in a non-root PID namespace
}
AmbientMatch defines the criteria for matching a process. At least one of Command or IsContainerInit must be set. When both are set, both must match.
type AmbientOTEL ¶ added in v0.5.0
type AmbientOTEL struct {
Endpoint string `yaml:"endpoint"`
ServiceName string `yaml:"service_name"`
}
AmbientOTEL allows overriding OTEL settings in the config file.
type AmbientRule ¶ added in v0.5.0
type AmbientRule struct {
Name string `yaml:"name"`
Match AmbientMatch `yaml:"match"`
Attributes map[string]string `yaml:"attributes"`
SkipEmptyValues bool `yaml:"skip_empty_values"`
TraceID string `yaml:"trace_id"`
ParentID string `yaml:"parent_id"`
AddDebugAttributes bool `yaml:"add_debug_attributes"`
// ContextStarved marks this rule's root process as unable to carry useful
// context on its own (e.g. `runc exec`: the injector's execve envp lacks
// the CI_* variables we want for trace_id/attrs — those live on some
// descendant's exec event, potentially several levels below).
//
// When true, a match does NOT start an OTEL session immediately. Instead,
// a pending session is held; every descendant exec (at any depth) is
// tried against the rule's Expr expressions (trace_id / parent_id /
// attributes), and the session materializes at the first descendant
// whose metadata makes any expression resolve to a non-empty value.
// If no descendant resolves before session_timeout, the pending session
// is dropped.
ContextStarved bool `yaml:"context_starved"`
}
AmbientRule defines a process matching rule and its tracing configuration.
type Config ¶
type Config struct {
// Command is the executable to run
Command string
// Args are the arguments to pass to the command
Args []string
// TraceID is an optional value for the OpenTelemetry trace ID.
// Literal strings or "expr:"-prefixed expressions are accepted.
// If empty, the OpenTelemetry SDK will auto-generate a random trace ID.
TraceID string
// ParentID is an optional value for the OpenTelemetry parent span ID.
// Literal strings or "expr:"-prefixed expressions are accepted.
// If empty, the root span will have no parent.
ParentID string
// CustomAttributes are user-defined span attributes (literal or expr:-prefixed values)
CustomAttributes []CustomAttribute
// SkipEmptyValues omits custom attributes whose value evaluates to an empty string
SkipEmptyValues bool
// AddDebugAttributes emits debug.* span attributes (argv, environ, trace/parent-id
// provenance). May leak secrets; opt-in only.
AddDebugAttributes bool
}
Config holds the parsed command-line configuration.
func BuildTraceConfig ¶ added in v0.5.1
func BuildTraceConfig(envCfg *EnvConfig, traceID, parentID string, cliAttrs []CustomAttribute, skipEmptyValues, addDebugAttributes bool, cmdArgs []string) (*Config, error)
BuildTraceConfig merges CLI-provided values with environment config to produce a Config. CLI values take precedence over environment values.
func ParseSymlinkMode ¶ added in v0.5.1
ParseSymlinkMode handles configuration when invoked via symlink. Resolves the actual shell binary and passes all args to it.
func (*Config) FullCommand ¶
FullCommand returns the command and all its arguments as a slice.
type CustomAttribute ¶
CustomAttribute represents a custom span attribute. Expression holds the raw value: either a literal string or an "expr:"-prefixed expression.
func CustomAttributesForRule ¶ added in v0.5.0
func CustomAttributesForRule(r *AmbientRule) []CustomAttribute
CustomAttributesForRule converts a rule's attributes map to CustomAttribute slice.
func ParseAttribute ¶ added in v0.5.1
func ParseAttribute(s string) (CustomAttribute, bool)
ParseAttribute parses a single "NAME=VALUE" string into a CustomAttribute. Returns the attribute and true on success, or zero value and false if invalid (with a warning logged).
func ParseAttributeString ¶ added in v0.2.0
func ParseAttributeString(attrStr string) ([]CustomAttribute, error)
ParseAttributeString parses semicolon-separated NAME=VALUE pairs. Format: "name1=value1;name2=value2;name3=expr:env[\"FOO\"]".
type EnvConfig ¶ added in v0.2.0
type EnvConfig struct {
TraceID string `env:"PROCESS_TRACER_TRACE_ID"`
ParentID string `env:"PROCESS_TRACER_PARENT_ID"`
Attributes string `env:"PROCESS_TRACER_ATTRIBUTES"`
Mode string `env:"PROCESS_TRACER_MODE" envDefault:"auto"`
ShellBinary string `env:"PROCESS_TRACER_SHELL_BINARY"`
}
EnvConfig holds process-tracer configuration from environment variables.
func ParseEnvConfig ¶ added in v0.2.0
ParseEnvConfig parses process-tracer configuration from environment variables.
type OTELConfig ¶
type OTELConfig struct {
ServiceName string `env:"OTEL_SERVICE_NAME" envDefault:"sched_trace"`
ResourceAttributes string `env:"OTEL_RESOURCE_ATTRIBUTES" envDefault:""`
ExporterEndpoint string `env:"OTEL_EXPORTER_OTLP_ENDPOINT" envDefault:""`
Insecure string `env:"OTEL_EXPORTER_OTLP_INSECURE" envDefault:""`
ShutdownTimeoutMs int `env:"PROCESS_TRACER_SHUTDOWN_TIMEOUT_MS" envDefault:"200"`
}
OTELConfig holds OpenTelemetry configuration from environment variables.
The following env vars are parsed and managed by us:
- OTEL_SERVICE_NAME — service name (default: "sched_trace")
- OTEL_RESOURCE_ATTRIBUTES — comma-separated key=value resource attributes
- OTEL_EXPORTER_OTLP_ENDPOINT — base endpoint URL or host:port (default: localhost:4318)
- OTEL_EXPORTER_OTLP_INSECURE — force plain HTTP when "true" (default: auto-detect from endpoint)
- PROCESS_TRACER_SHUTDOWN_TIMEOUT_MS — max time in ms to flush spans at exit (default: 200)
The following env vars are handled natively by the otlptracehttp library. We do not parse them, but they are effective at runtime:
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT — traces-specific endpoint (overrides OTEL_EXPORTER_OTLP_ENDPOINT)
- OTEL_EXPORTER_OTLP_HEADERS / _TRACES_HEADERS — request headers (W3C Baggage format)
- OTEL_EXPORTER_OTLP_TIMEOUT / _TRACES_TIMEOUT — export timeout in ms (default: 10000)
- OTEL_EXPORTER_OTLP_COMPRESSION / _TRACES_COMPRESSION — "gzip" to enable compression
- OTEL_EXPORTER_OTLP_CERTIFICATE / _TRACES_CERTIFICATE — path to server CA certificate (TLS)
- OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE / _TRACES_CLIENT_CERTIFICATE — client cert for mTLS
- OTEL_EXPORTER_OTLP_CLIENT_KEY / _TRACES_CLIENT_KEY — client private key for mTLS
func ParseOTELConfig ¶
func ParseOTELConfig() (*OTELConfig, error)
ParseOTELConfig parses OTEL configuration from environment variables.
func (*OTELConfig) EndpointHost ¶ added in v0.3.1
func (c *OTELConfig) EndpointHost() string
EndpointHost extracts just the host (without scheme/port) for display purposes.
func (*OTELConfig) EndpointOptions ¶ added in v0.3.1
func (c *OTELConfig) EndpointOptions() []otlptracehttp.Option
EndpointOptions returns the otlptracehttp options for endpoint and TLS configuration.
func (*OTELConfig) GetEndpoint ¶
func (c *OTELConfig) GetEndpoint() string
GetEndpoint returns the configured endpoint string, or the default.
func (*OTELConfig) InsecureReason ¶ added in v0.3.1
func (c *OTELConfig) InsecureReason() string
InsecureReason returns a human-readable reason for the TLS mode decision.
func (*OTELConfig) IsInsecure ¶ added in v0.3.1
func (c *OTELConfig) IsInsecure() bool
IsInsecure determines whether to use plain HTTP based on configuration. Priority: explicit OTEL_EXPORTER_OTLP_INSECURE > endpoint scheme > localhost heuristic.
func (*OTELConfig) ParseResourceAttributes ¶
func (c *OTELConfig) ParseResourceAttributes() []attribute.KeyValue
ParseResourceAttributes parses the OTEL_RESOURCE_ATTRIBUTES string. Format: key1=value1,key2=value2.
func (*OTELConfig) ShutdownTimeout ¶ added in v0.4.0
func (c *OTELConfig) ShutdownTimeout() time.Duration
ShutdownTimeout returns the configured shutdown timeout as a time.Duration.