lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.14.0 vs lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.15.0
- old
+ new
@@ -39,30 +39,29 @@
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'
raise ArgumentError, 'headers must be comma-separated k=v pairs or a Hash' unless valid_headers?(headers)
- uri = if endpoint == ENV['OTEL_EXPORTER_OTLP_ENDPOINT']
- URI("#{endpoint}/v1/traces")
- else
- URI(endpoint)
- end
+ @uri = if endpoint == ENV['OTEL_EXPORTER_OTLP_ENDPOINT']
+ URI("#{endpoint}/v1/traces")
+ else
+ URI(endpoint)
+ end
- @http = Net::HTTP.new(uri.host, uri.port)
- @http.use_ssl = uri.scheme == 'https'
+ @http = Net::HTTP.new(@uri.host, @uri.port)
+ @http.use_ssl = @uri.scheme == 'https'
@http.ca_file = certificate_file unless certificate_file.nil?
@http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT
- @path = uri.path
+ @path = @uri.path
@headers = case headers
when String then CSV.parse(headers, col_sep: '=', row_sep: ',').to_h
when Hash then headers
end
@timeout = timeout.to_f
@compression = compression
@metrics_reporter = metrics_reporter || OpenTelemetry::SDK::Trace::Export::MetricsReporter
-
@shutdown = false
end
# Called to export sampled {OpenTelemetry::SDK::Trace::SpanData} structs.
#
@@ -114,14 +113,25 @@
false
rescue URI::InvalidURIError
true
end
+ # The around_request is a private method that provides an extension
+ # point for the exporters network calls. The default behaviour
+ # is to not trace these operations.
+ #
+ # An example use case would be to prepend a patch, or extend this class
+ # and override this method's behaviour to explicitly trace the HTTP request.
+ # This would allow you to trace your export pipeline.
+ def around_request
+ OpenTelemetry::Common::Utilities.untraced { yield }
+ end
+
def send_bytes(bytes, timeout:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
retry_count = 0
timeout ||= @timeout
start_time = Time.now
- OpenTelemetry::Common::Utilities.untraced do # rubocop:disable Metrics/BlockLength
+ around_request do # rubocop:disable Metrics/BlockLength
request = Net::HTTP::Post.new(@path)
request.body = if @compression == 'gzip'
request.add_field('Content-Encoding', 'gzip')
Zlib.gzip(bytes)
else