class Aspecto::OpenTelemetry::Configurator

Aspecto OpenTelemetry Distro Configurator

Constants

TRUTHY_VALUES

Attributes

aspecto_auth[R]
extract_b3_context[RW]
inject_b3_context_multi_header[RW]
inject_b3_context_single_header[RW]
log_level[RW]
otel_exporter_otlp_traces_endpoint[RW]
require_config_for_traces[RW]
sampling_ratio[RW]

Public Class Methods

bool_env_variable(env_variable_name, default_value) click to toggle source
# 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
new() click to toggle source
# 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

Public Instance Methods

aspecto_auth=(aspecto_auth) click to toggle source
# File lib/aspecto/opentelemetry/configurator.rb, line 38
def aspecto_auth=(aspecto_auth)
  @override_resource_attributes["aspecto.token"] = aspecto_auth
  @aspecto_auth = aspecto_auth
end
config_override_resource() click to toggle source
# File lib/aspecto/opentelemetry/configurator.rb, line 43
def config_override_resource
  ::OpenTelemetry::SDK::Resources::Resource.create(@override_resource_attributes)
end
env=(env) click to toggle source
# 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) click to toggle source
# File lib/aspecto/opentelemetry/configurator.rb, line 27
def service_name=(service_name)
  @override_resource_attributes[::OpenTelemetry::SemanticConventions::Resource::SERVICE_NAME] = service_name
end