lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.20.6 vs lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.21.0

- old
+ new

@@ -42,15 +42,15 @@ else OpenSSL::SSL::VERIFY_PEER end end - def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'https://localhost:4318/v1/traces'), # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength + def initialize(endpoint: config_opt('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'https://localhost:4318/v1/traces'), # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity certificate_file: config_opt('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'), ssl_verify_mode: Exporter.ssl_verify_mode, headers: config_opt('OTEL_EXPORTER_OTLP_TRACES_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS', default: {}), - compression: config_opt('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION'), + compression: config_opt('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION', default: 'gzip'), timeout: config_opt('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10), metrics_reporter: nil) raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" if invalid_url?(endpoint) raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil? || compression == 'gzip' @@ -58,15 +58,11 @@ URI("#{endpoint}/v1/traces") else URI(endpoint) end - @http = Net::HTTP.new(@uri.host, @uri.port) - @http.use_ssl = @uri.scheme == 'https' - @http.verify_mode = ssl_verify_mode - @http.ca_file = certificate_file unless certificate_file.nil? - @http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT + @http = http_connection(@uri, ssl_verify_mode, certificate_file) @path = @uri.path @headers = case headers when String then parse_headers(headers) when Hash then headers @@ -111,9 +107,18 @@ @http.finish if @http.started? SUCCESS end private + + def http_connection(uri, ssl_verify_mode, certificate_file) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = uri.scheme == 'https' + http.verify_mode = ssl_verify_mode + http.ca_file = certificate_file unless certificate_file.nil? + http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT + http + end def config_opt(*env_vars, default: nil) env_vars.each do |env_var| val = ENV[env_var] return val unless val.nil?