Sha256: ec64d3c33902001fb60092c6d67d556b722ca07afa1036d88eb8fafd3b76939e

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Aspecto
  module OpenTelemetry
    # Aspecto OpenTelemetry Distro Configurator
    class Configurator
      def initialize
        # 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))
      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
      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aspecto-opentelemetry-0.1.1 lib/aspecto/opentelemetry/configurator.rb
aspecto-opentelemetry-0.1.0 lib/aspecto/opentelemetry/configurator.rb