lib/aspecto/opentelemetry/configurator.rb in aspecto-opentelemetry-0.1.6 vs lib/aspecto/opentelemetry/configurator.rb in aspecto-opentelemetry-0.1.7.rc0
- old
+ new
@@ -4,40 +4,54 @@
module OpenTelemetry
# Aspecto OpenTelemetry Distro Configurator
class Configurator
TRUTHY_VALUES = %w[1 T t true TRUE True].freeze
- def initialize
+ def initialize # rubocop:disable Metrics/AbcSize
# initialize config options from environment variables.
# they can later be overwritten with configurator attribute setters
# that have precedence over env
@override_resource_attributes = {}
self.aspecto_auth = ENV["ASPECTO_AUTH"]
self.log_level = ENV.fetch("OTEL_LOG_LEVEL", Logger::ERROR)
self.env = ENV["ASPECTO_ENV"] if ENV["ASPECTO_ENV"]
self.sampling_ratio = Float(ENV.fetch("ASPECTO_SAMPLING_RATIO", 1.0))
self.otel_exporter_otlp_traces_endpoint = ENV.fetch("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://otelcol.aspecto.io/v1/trace")
- self.require_config_for_traces = TRUTHY_VALUES.include?(ENV["ASPECTO_REQUIRE_CONFIG_FOR_TRACES"]&.strip)
+ self.require_config_for_traces = self.class.bool_env_variable "ASPECTO_REQUIRE_CONFIG_FOR_TRACES", false
+
+ # b3 propagattor
+ self.extract_b3_context = self.class.bool_env_variable "ASPECTO_EXTRACT_B3_CONTEXT", false
+ self.inject_b3_context_single_header = self.class.bool_env_variable "ASPECTO_INJECT_B3_CONTEXT_SINGLE_HEADER", false
+ self.inject_b3_context_multi_header = self.class.bool_env_variable "ASPECTO_INJECT_B3_CONTEXT_MULTI_HEADER", false
end
def service_name=(service_name)
@override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME] = service_name
end
def env=(env)
@override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT] = env
end
- attr_accessor :sampling_ratio, :log_level, :otel_exporter_otlp_traces_endpoint, :require_config_for_traces
+ attr_accessor :sampling_ratio, :log_level, :otel_exporter_otlp_traces_endpoint, :require_config_for_traces, :extract_b3_context, :inject_b3_context_single_header, :inject_b3_context_multi_header
attr_reader :aspecto_auth
def aspecto_auth=(aspecto_auth)
@override_resource_attributes["aspecto.token"] = aspecto_auth
@aspecto_auth = aspecto_auth
end
def config_override_resource
::OpenTelemetry::SDK::Resources::Resource.create(@override_resource_attributes)
+ end
+
+ def self.bool_env_variable(env_variable_name, default_value)
+ env_value = ENV[env_variable_name]
+ if env_value.nil?
+ default_value
+ else
+ TRUTHY_VALUES.include?(env_value.strip)
+ end
end
end
end
end