Class: Aspecto::OpenTelemetry::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/aspecto/opentelemetry/configurator.rb

Overview

Aspecto OpenTelemetry Distro Configurator

Constant Summary collapse

TRUTHY_VALUES =
%w[1 T t true TRUE True].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

rubocop:disable Metrics/AbcSize



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aspecto/opentelemetry/configurator.rb', line 9

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 = 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

Instance Attribute Details

#aspecto_authObject

Returns the value of attribute aspecto_auth.



36
37
38
# File 'lib/aspecto/opentelemetry/configurator.rb', line 36

def aspecto_auth
  @aspecto_auth
end

#extract_b3_contextObject

Returns the value of attribute extract_b3_context.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def extract_b3_context
  @extract_b3_context
end

#inject_b3_context_multi_headerObject

Returns the value of attribute inject_b3_context_multi_header.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def inject_b3_context_multi_header
  @inject_b3_context_multi_header
end

#inject_b3_context_single_headerObject

Returns the value of attribute inject_b3_context_single_header.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def inject_b3_context_single_header
  @inject_b3_context_single_header
end

#log_levelObject

Returns the value of attribute log_level.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def log_level
  @log_level
end

#otel_exporter_otlp_traces_endpointObject

Returns the value of attribute otel_exporter_otlp_traces_endpoint.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def otel_exporter_otlp_traces_endpoint
  @otel_exporter_otlp_traces_endpoint
end

#require_config_for_tracesObject

Returns the value of attribute require_config_for_traces.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def require_config_for_traces
  @require_config_for_traces
end

#sampling_ratioObject

Returns the value of attribute sampling_ratio.



35
36
37
# File 'lib/aspecto/opentelemetry/configurator.rb', line 35

def sampling_ratio
  @sampling_ratio
end

Class Method Details

.bool_env_variable(env_variable_name, default_value) ⇒ Object



47
48
49
50
51
52
# File 'lib/aspecto/opentelemetry/configurator.rb', line 47

def self.bool_env_variable(env_variable_name, default_value)
  env_value = ENV[env_variable_name]
  return default_value if env_value.nil?

  TRUTHY_VALUES.include?(env_value.strip)
end

Instance Method Details

#config_override_resourceObject



43
44
45
# File 'lib/aspecto/opentelemetry/configurator.rb', line 43

def config_override_resource
  ::OpenTelemetry::SDK::Resources::Resource.create(@override_resource_attributes)
end

#env=(env) ⇒ Object



31
32
33
# File 'lib/aspecto/opentelemetry/configurator.rb', line 31

def env=(env)
  @override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::DEPLOYMENT_ENVIRONMENT] = env
end

#service_name=(service_name) ⇒ Object



27
28
29
# File 'lib/aspecto/opentelemetry/configurator.rb', line 27

def service_name=(service_name)
  @override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME] = service_name
end