lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.22.0 vs lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.23.0

- old
+ new

@@ -129,27 +129,32 @@ # 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 + def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity return FAILURE if bytes.nil? + @metrics_reporter.record_value('otel.otlp_exporter.message.uncompressed_size', value: bytes.bytesize) + + request = Net::HTTP::Post.new(@path) + if @compression == 'gzip' + request.add_field('Content-Encoding', 'gzip') + body = Zlib.gzip(bytes) + @metrics_reporter.record_value('otel.otlp_exporter.message.compressed_size', value: body.bytesize) + else + body = bytes + end + request.body = body + request.add_field('Content-Type', 'application/x-protobuf') + @headers.each { |key, value| request.add_field(key, value) } + retry_count = 0 timeout ||= @timeout start_time = OpenTelemetry::Common::Utilities.timeout_timestamp - 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 - bytes - end - request.add_field('Content-Type', 'application/x-protobuf') - @headers.each { |key, value| request.add_field(key, value) } + around_request do # rubocop:disable Metrics/BlockLength remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) return FAILURE if remaining_timeout.zero? @http.open_timeout = remaining_timeout @http.read_timeout = remaining_timeout @@ -263,11 +268,11 @@ sleep(sleep_interval) true end - def encode(span_data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def encode(span_data) # rubocop:disable Metrics/MethodLength Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.encode( Opentelemetry::Proto::Collector::Trace::V1::ExportTraceServiceRequest.new( resource_spans: span_data .group_by(&:resource) .map do |resource, span_datas| @@ -293,10 +298,10 @@ rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#encode') nil end - def as_otlp_span(span_data) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def as_otlp_span(span_data) # rubocop:disable Metrics/MethodLength Opentelemetry::Proto::Trace::V1::Span.new( trace_id: span_data.trace_id, span_id: span_data.span_id, trace_state: span_data.tracestate.to_s, parent_span_id: span_data.parent_span_id == OpenTelemetry::Trace::INVALID_SPAN_ID ? nil : span_data.parent_span_id,