lib/opentelemetry/exporter/zipkin/exporter.rb in opentelemetry-exporter-zipkin-0.19.3 vs lib/opentelemetry/exporter/zipkin/exporter.rb in opentelemetry-exporter-zipkin-0.20.0

- old
+ new

@@ -25,14 +25,14 @@ KEEP_ALIVE_TIMEOUT = 30 RETRY_COUNT = 5 WRITE_TIMEOUT_SUPPORTED = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6') private_constant(:KEEP_ALIVE_TIMEOUT, :RETRY_COUNT, :WRITE_TIMEOUT_SUPPORTED) - def initialize(endpoint: config_opt('OTEL_EXPORTER_ZIPKIN_ENDPOINT', default: 'http://localhost:9411/api/v2/spans'), - headers: config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_HEADERS', 'OTEL_EXPORTER_ZIPKIN_HEADERS'), - timeout: config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_TIMEOUT', 'OTEL_EXPORTER_ZIPKIN_TIMEOUT', default: 10)) - raise ArgumentError, "invalid url for Zipkin::Exporter #{endpoint}" if invalid_url?(endpoint) + def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_ENDPOINT', default: 'http://localhost:9411/api/v2/spans'), + headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_HEADERS', 'OTEL_EXPORTER_ZIPKIN_HEADERS'), + timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_ZIPKIN_TRACES_TIMEOUT', 'OTEL_EXPORTER_ZIPKIN_TIMEOUT', default: 10)) + raise ArgumentError, "invalid url for Zipkin::Exporter #{endpoint}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint) raise ArgumentError, 'headers must be comma-separated k=v pairs or a Hash' unless valid_headers?(headers) @uri = if endpoint == ENV['OTEL_EXPORTER_ZIPKIN_ENDPOINT'] URI("#{endpoint}/api/v2/spans") else @@ -92,32 +92,15 @@ SUCCESS end private - def config_opt(*env_vars, default: nil) - env_vars.each do |env_var| - val = ENV[env_var] - return val unless val.nil? - end - default - end - def encode_spans(span_data) span_data.map! { |span| Transformer.to_zipkin_span(span, span.resource) } end def around_request OpenTelemetry::Common::Utilities.untraced { yield } - end - - def invalid_url?(url) - return true if url.nil? || url.strip.empty? - - URI(url) - false - rescue URI::InvalidURIError - true end def valid_headers?(headers) return true if headers.nil? || headers.is_a?(Hash) return false unless headers.is_a?(String)