Sha256: 39f76d9c7f194cd157c46cb5975c3dd5607ea7c933e57119affdbc5a72c7866c

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 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))
        self.otel_exporter_otlp_traces_endpoint = ENV.fetch("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "https://otelcol.aspecto.io/v1/trace")
      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
      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

4 entries across 4 versions & 1 rubygems

Version Path
aspecto-opentelemetry-0.1.5 lib/aspecto/opentelemetry/configurator.rb
aspecto-opentelemetry-0.1.4 lib/aspecto/opentelemetry/configurator.rb
aspecto-opentelemetry-0.1.3 lib/aspecto/opentelemetry/configurator.rb
aspecto-opentelemetry-0.1.2 lib/aspecto/opentelemetry/configurator.rb