instrument_config (instrument v1.0.0)

View Source

SDK configuration from environment variables.

This module reads OpenTelemetry SDK configuration from OTEL_* environment variables and applies them to the instrument library.

Supported Environment Variables

- OTEL_SERVICE_NAME - Service name for resource - OTEL_TRACES_SAMPLER - Sampler to use (always_on, always_off, traceidratio, parentbased_always_on, etc.) - OTEL_TRACES_SAMPLER_ARG - Sampler argument (e.g., probability for traceidratio) - OTEL_PROPAGATORS - Comma-separated list of propagators - OTEL_BSP_SCHEDULE_DELAY - Batch span processor delay in ms - OTEL_BSP_MAX_QUEUE_SIZE - Max queue size for batch processor - OTEL_BSP_MAX_EXPORT_BATCH_SIZE - Max batch size for export - OTEL_EXPORTER_OTLP_ENDPOINT - OTLP exporter endpoint - OTEL_EXPORTER_OTLP_TRACES_ENDPOINT - OTLP traces endpoint - OTEL_EXPORTER_OTLP_METRICS_ENDPOINT - OTLP metrics endpoint - OTEL_EXPORTER_OTLP_LOGS_ENDPOINT - OTLP logs endpoint - OTEL_LOG_LEVEL - Log level (debug, info, warning, error)

Summary

Functions

Auto-registers exporters based on environment variables. Supports standard OTel env vars (OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER) and legacy OTEL_EXPORTERS. Supported values: otlp, console, none.

Auto-registers span processor based on config. Reads from application env {span_processor, {Module, Config}} or uses batch processor with OTEL_BSP_* settings if exporter is available.

Disables a specific exporter. Disabled exporters will not receive spans for export.

Enables a specific exporter.

Gets a configuration value.

Gets a configuration value with default.

Gets batch processor configuration.

Gets list of configured exporters from OTEL_EXPORTERS.

Gets the log level.

Gets the per-metric cardinality limit. Reads from OTEL_METRIC_CARDINALITY_LIMIT env var, defaults to 2000. When a vector metric reaches this many distinct label sets, subsequent label sets are aggregated into a single overflow series identified by otel.metric.overflow=true.

Gets the OTLP endpoint.

Gets a specific OTLP endpoint (traces, metrics, logs).

Maximum number of OTLP export attempts per batch. Reads from OTEL_EXPORTER_OTLP_MAX_RETRIES, defaults to 3.

Initial delay between OTLP retries in milliseconds. Reads from OTEL_EXPORTER_OTLP_RETRY_INITIAL_DELAY_MS, defaults to 1000.

Maximum delay between OTLP retries in milliseconds. Reads from OTEL_EXPORTER_OTLP_RETRY_MAX_DELAY_MS, defaults to 30000.

Gets the configured propagators.

Gets resource attributes from application config.

Gets the configured sampler.

Gets the SDK version dynamically from app metadata. Checks instrumentation_scope_version env first, then app vsn, then fallback.

Gets the service name.

Gets the service version.

Gets the span attribute count limit. Reads from OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT env var, defaults to 128.

Gets the per-attribute value length limit. Reads from OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, returns unlimited when unset (the spec default). When set, string and binary attribute values longer than the limit are truncated; list elements are truncated individually.

Gets the per-event attribute count limit. Reads from OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT env var, defaults to 128.

Gets the span event count limit. Reads from OTEL_SPAN_EVENT_COUNT_LIMIT env var, defaults to 128.

Gets the per-link attribute count limit. Reads from OTEL_LINK_ATTRIBUTE_COUNT_LIMIT env var, defaults to 128.

Gets the span link count limit. Reads from OTEL_SPAN_LINK_COUNT_LIMIT env var, defaults to 128.

Checks if a span processor will be registered. Returns true if either span_processor app config is set, or batch processor env vars are set with an available exporter.

Initializes configuration from environment variables.

Checks if an exporter is enabled.

Checks if the flight recorder is enabled. Note: This reads from instrument_flight_recorder's persistent_term for consistency.

Checks if tracing is globally enabled.

Checks if verbose tracing is enabled. Verbose tracing captures additional attributes but has higher overhead. WARNING: Not recommended for high-throughput production use.

Sets a configuration value.

Enables or disables the flight recorder. This is a convenience wrapper around instrument_flight_recorder:enable/disable.

Enables or disables tracing globally. When disabled, span creation is skipped entirely for maximum performance.

Enables or disables verbose tracing. When enabled, more detailed attributes are captured. WARNING: Verbose tracing has significant performance overhead.

Functions

auto_register_exporters()

-spec auto_register_exporters() -> ok.

Auto-registers exporters based on environment variables. Supports standard OTel env vars (OTEL_TRACES_EXPORTER, OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER) and legacy OTEL_EXPORTERS. Supported values: otlp, console, none.

auto_register_span_processor()

-spec auto_register_span_processor() -> ok.

Auto-registers span processor based on config. Reads from application env {span_processor, {Module, Config}} or uses batch processor with OTEL_BSP_* settings if exporter is available.

disable_exporter(Module)

-spec disable_exporter(module()) -> ok.

Disables a specific exporter. Disabled exporters will not receive spans for export.

enable_exporter(Module)

-spec enable_exporter(module()) -> ok.

Enables a specific exporter.

get(Key)

-spec get(atom()) -> term() | undefined.

Gets a configuration value.

get(Key, Default)

-spec get(atom(), term()) -> term().

Gets a configuration value with default.

get_batch_processor_config()

-spec get_batch_processor_config() -> map().

Gets batch processor configuration.

get_exporters()

-spec get_exporters() -> [atom()].

Gets list of configured exporters from OTEL_EXPORTERS.

get_log_level()

-spec get_log_level() -> debug | info | warning | error | undefined.

Gets the log level.

get_metric_cardinality_limit()

-spec get_metric_cardinality_limit() -> pos_integer().

Gets the per-metric cardinality limit. Reads from OTEL_METRIC_CARDINALITY_LIMIT env var, defaults to 2000. When a vector metric reaches this many distinct label sets, subsequent label sets are aggregated into a single overflow series identified by otel.metric.overflow=true.

get_otlp_endpoint()

-spec get_otlp_endpoint() -> binary() | undefined.

Gets the OTLP endpoint.

get_otlp_endpoint(_)

-spec get_otlp_endpoint(traces | metrics | logs) -> binary() | undefined.

Gets a specific OTLP endpoint (traces, metrics, logs).

get_otlp_max_retries()

-spec get_otlp_max_retries() -> non_neg_integer().

Maximum number of OTLP export attempts per batch. Reads from OTEL_EXPORTER_OTLP_MAX_RETRIES, defaults to 3.

get_otlp_retry_initial_delay_ms()

-spec get_otlp_retry_initial_delay_ms() -> pos_integer().

Initial delay between OTLP retries in milliseconds. Reads from OTEL_EXPORTER_OTLP_RETRY_INITIAL_DELAY_MS, defaults to 1000.

get_otlp_retry_max_delay_ms()

-spec get_otlp_retry_max_delay_ms() -> pos_integer().

Maximum delay between OTLP retries in milliseconds. Reads from OTEL_EXPORTER_OTLP_RETRY_MAX_DELAY_MS, defaults to 30000.

get_propagators()

-spec get_propagators() -> [module()] | undefined.

Gets the configured propagators.

get_resource_config()

-spec get_resource_config() -> map().

Gets resource attributes from application config.

get_sampler()

-spec get_sampler() -> {module(), term()} | undefined.

Gets the configured sampler.

get_sdk_version()

-spec get_sdk_version() -> binary().

Gets the SDK version dynamically from app metadata. Checks instrumentation_scope_version env first, then app vsn, then fallback.

get_service_name()

-spec get_service_name() -> binary() | undefined.

Gets the service name.

get_service_version()

-spec get_service_version() -> binary() | undefined.

Gets the service version.

get_span_attribute_count_limit()

-spec get_span_attribute_count_limit() -> pos_integer().

Gets the span attribute count limit. Reads from OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT env var, defaults to 128.

get_span_attribute_value_length_limit()

-spec get_span_attribute_value_length_limit() -> pos_integer() | unlimited.

Gets the per-attribute value length limit. Reads from OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, returns unlimited when unset (the spec default). When set, string and binary attribute values longer than the limit are truncated; list elements are truncated individually.

get_span_event_attribute_count_limit()

-spec get_span_event_attribute_count_limit() -> pos_integer().

Gets the per-event attribute count limit. Reads from OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT env var, defaults to 128.

get_span_event_count_limit()

-spec get_span_event_count_limit() -> pos_integer().

Gets the span event count limit. Reads from OTEL_SPAN_EVENT_COUNT_LIMIT env var, defaults to 128.

has_span_processor_config()

-spec has_span_processor_config() -> boolean().

Checks if a span processor will be registered. Returns true if either span_processor app config is set, or batch processor env vars are set with an available exporter.

init()

-spec init() -> ok.

Initializes configuration from environment variables.

is_exporter_enabled(Module)

-spec is_exporter_enabled(module()) -> boolean().

Checks if an exporter is enabled.

is_flight_recorder_enabled()

-spec is_flight_recorder_enabled() -> boolean().

Checks if the flight recorder is enabled. Note: This reads from instrument_flight_recorder's persistent_term for consistency.

is_tracing_enabled()

-spec is_tracing_enabled() -> boolean().

Checks if tracing is globally enabled.

is_verbose_tracing()

-spec is_verbose_tracing() -> boolean().

Checks if verbose tracing is enabled. Verbose tracing captures additional attributes but has higher overhead. WARNING: Not recommended for high-throughput production use.

set(Key, Value)

-spec set(atom(), term()) -> ok.

Sets a configuration value.

set_flight_recorder_enabled(_)

-spec set_flight_recorder_enabled(boolean()) -> ok.

Enables or disables the flight recorder. This is a convenience wrapper around instrument_flight_recorder:enable/disable.

set_tracing_enabled(Enabled)

-spec set_tracing_enabled(boolean()) -> ok.

Enables or disables tracing globally. When disabled, span creation is skipped entirely for maximum performance.

set_verbose_tracing(Enabled)

-spec set_verbose_tracing(boolean()) -> ok.

Enables or disables verbose tracing. When enabled, more detailed attributes are captured. WARNING: Verbose tracing has significant performance overhead.