lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.23.0 vs lib/opentelemetry/exporter/otlp/exporter.rb in opentelemetry-exporter-otlp-0.24.0
- old
+ new
@@ -43,22 +43,22 @@
else
OpenSSL::SSL::VERIFY_PEER
end
end
- def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/traces'), # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
+ def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT', 'OTEL_EXPORTER_OTLP_ENDPOINT', default: 'http://localhost:4318/v1/traces'), # rubocop:disable Metrics/CyclomaticComplexity
certificate_file: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE', 'OTEL_EXPORTER_OTLP_CERTIFICATE'),
ssl_verify_mode: Exporter.ssl_verify_mode,
headers: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_HEADERS', 'OTEL_EXPORTER_OTLP_HEADERS', default: {}),
compression: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION', 'OTEL_EXPORTER_OTLP_COMPRESSION', default: 'gzip'),
timeout: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT', 'OTEL_EXPORTER_OTLP_TIMEOUT', default: 10),
metrics_reporter: nil)
raise ArgumentError, "invalid url for OTLP::Exporter #{endpoint}" unless OpenTelemetry::Common::Utilities.valid_url?(endpoint)
raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil? || %w[gzip none].include?(compression)
@uri = if endpoint == ENV['OTEL_EXPORTER_OTLP_ENDPOINT']
- URI("#{endpoint}/v1/traces")
+ URI.join(endpoint, 'v1/traces')
else
URI(endpoint)
end
@http = http_connection(@uri, ssl_verify_mode, certificate_file)
@@ -126,11 +126,11 @@
#
# 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 }
+ OpenTelemetry::Common::Utilities.untraced { yield } # rubocop:disable Style/ExplicitBlockArgument
end
def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
return FAILURE if bytes.nil?
@@ -150,11 +150,11 @@
retry_count = 0
timeout ||= @timeout
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
- around_request do # rubocop:disable Metrics/BlockLength
+ around_request do
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
@@ -172,10 +172,14 @@
FAILURE
when Net::HTTPRequestTimeOut, Net::HTTPGatewayTimeOut, Net::HTTPBadGateway
response.body # Read and discard body
redo if backoff?(retry_count: retry_count += 1, reason: response.code)
FAILURE
+ when Net::HTTPNotFound
+ OpenTelemetry.handle_error(message: "OTLP exporter received http.code=404 for uri: '#{@path}'")
+ @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
+ FAILURE
when Net::HTTPBadRequest, Net::HTTPClientError, Net::HTTPServerError
log_status(response.body)
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
FAILURE
when Net::HTTPRedirection
@@ -242,11 +246,11 @@
value: duration_ms,
labels: { 'status' => response&.code || 'unknown' })
end
end
- def backoff?(retry_after: nil, retry_count:, reason:)
+ def backoff?(retry_count:, reason:, retry_after: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => reason })
return false if retry_count > RETRY_COUNT
sleep_interval = nil
unless retry_after.nil?
@@ -268,25 +272,25 @@
sleep(sleep_interval)
true
end
- def encode(span_data) # rubocop:disable Metrics/MethodLength
+ def encode(span_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
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|
Opentelemetry::Proto::Trace::V1::ResourceSpans.new(
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
),
- instrumentation_library_spans: span_datas
- .group_by(&:instrumentation_library)
+ scope_spans: span_datas
+ .group_by(&:instrumentation_scope)
.map do |il, sds|
- Opentelemetry::Proto::Trace::V1::InstrumentationLibrarySpans.new(
- instrumentation_library: Opentelemetry::Proto::Common::V1::InstrumentationLibrary.new(
+ Opentelemetry::Proto::Trace::V1::ScopeSpans.new(
+ scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
name: il.name,
version: il.version
),
spans: sds.map { |sd| as_otlp_span(sd) }
)
@@ -298,10 +302,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/MethodLength
+ def as_otlp_span(span_data) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
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,