envvarconfigsource

package
v0.100.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Environment Variable Config Source (Alpha)

Use the environmental variable config source instead of direct references to environment variables in the config to inject YAML fragments or to have default values in case the selected environment variable is undefined. For simple environment variable expansion without support for YAML fragments or defaults see Collector Configuration Environment Variables

Configuration

Under the config_sources: use env: or env/<name>: to create an environment variable config source. The following parameters are available to customize environment variable config sources:

config_sources:
  env:
    # defaults is used to create a set of fallbacks in case the original env var is
    # undefined in the environment.
    defaults:
      MY_ENV_VAR: my env var value

By default, the config source will cause an error if it tries to inject an environment variable that is not defined or not specified on the defaults section. That behavior can be controlled via the optional parameters when invoking the config source, example:

config_sources:
  env:
    defaults:
      BACKED_BY_DEFAULTS_ENV_VAR: some_value

components:
  component_0:
    # Not an error if ENV_VAR_NAME is undefined since 'optional' is set to true,
    # the resulting value is "/data/token".
    not_required_field: ${env:ENV_VAR_NAME?optional=true}/data/token 

  component_1:
    # It will be an error if ENV_VAR_NAME is undefined, the config will fail to load.
    required_field: ${env:ENV_VAR_NAME}/data/token 

  component_2:
    # Not an error if BACKED_BY_DEFAULTS_ENV_VAR is undefined, because the 'defaults'
    # of the config source.
    required_field: ${env:BACKED_BY_DEFAULTS_ENV_VAR}/data/token 

Injecting YAML Fragments

The typical case to use the environment variable config source is when one wants to inject YAML fragments. The example below shows how this can be done on Linux and Windows when running the collector from your current session. For guidance on setting service environment variables for your installation please see the related Linux and Windows installer documentation.

  1. Use the env config source environment variables in your configuration:
config_sources:
  env:
    defaults:
      JAEGER_PROTOCOLS: "{ protocols: { grpc: , } }"
      OTLP_PROTOCOLS: "{ grpc: , }"

receivers:
  jaeger:
    ${env:JAEGER_PROTOCOLS}
  otlp:
    protocols:
      ${env:OTLP_PROTOCOLS}
...
  1. Export the environment variables for your session before running the collector:
  • Linux:
export OTLP_PROTOCOLS="{ grpc: , http: , }"
export JAEGER_PROTOCOLS="{ protocols: { grpc: , thrift_binary: , thrift_compact: , thrift_http: , } }"
otelcol --config <your-configuration.yaml>
  • Windows:
set OTLP_PROTOCOLS={ grpc: , http: , }
set JAEGER_PROTOCOLS={ protocols: { grpc: , thrift_binary: , thrift_compact: , thrift_http: , } }
otelcol.exe --config <your-configuration.yaml>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFactory

func NewFactory() configsource.Factory

NewFactory creates a factory for Vault ConfigSource objects.

Types

type Config

type Config struct {
	// Defaults specify a map to fallback if a given environment variable is not defined.
	Defaults map[string]any `mapstructure:"defaults"`

	configsource.SourceSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
}

Config holds the configuration for the creation of environment variable config source objects.

Jump to

Keyboard shortcuts

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