Skip to content

Commit

Permalink
Consider OTLP export failures handleable errors (#1565)
Browse files Browse the repository at this point in the history
* Consider OTLP export failures handleable errors

* Update exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb

Co-authored-by: Francis Bogsanyi <[email protected]>

* Update exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb

Co-authored-by: Francis Bogsanyi <[email protected]>

* don't cache uri_string

* fixup test

* Use log_failure in backoff?

* Make unexpected response its own case

* use variables that exist

* use variables that exist

* Drop extraneous argument

* Formatting

* just use log_request_failure

---------

Co-authored-by: Francis Bogsanyi <[email protected]>
  • Loading branch information
plantfansam and fbogsany authored Jan 22, 2024
1 parent e7d4545 commit d08bc1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
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 })
log_request_failure(response.code)
FAILURE
when Net::HTTPBadRequest, Net::HTTPClientError, Net::HTTPServerError
log_status(response.body)
Expand All @@ -180,6 +179,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
redo if backoff?(retry_after: 0, retry_count: retry_count += 1, reason: response.code)
else
@http.finish
log_request_failure(response.code)
FAILURE
end
rescue Net::OpenTimeout, Net::ReadTimeout
Expand Down Expand Up @@ -222,11 +222,16 @@ def log_status(body)
klass_or_nil = ::Google::Protobuf::DescriptorPool.generated_pool.lookup(detail.type_name).msgclass
detail.unpack(klass_or_nil) if klass_or_nil
end.compact
OpenTelemetry.handle_error(message: "OTLP exporter received rpc.Status{message=#{status.message}, details=#{details}}")
OpenTelemetry.handle_error(message: "OTLP exporter received rpc.Status{message=#{status.message}, details=#{details}} for uri=#{@uri}")
rescue StandardError => e
OpenTelemetry.handle_error(exception: e, message: 'unexpected error decoding rpc.Status in OTLP::Exporter#log_status')
end

def log_request_failure(response_code)
OpenTelemetry.handle_error(message: "OTLP exporter received http.code=#{response_code} for uri='#{@uri}' in OTLP::Exporter#send_bytes")
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response_code })
end

def measure_request_duration
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
Expand All @@ -241,7 +246,7 @@ def measure_request_duration
end

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 })
log_request_failure(reason)
return false if retry_count > RETRY_COUNT

sleep_interval = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@
result = exporter.export([span_data])

_(log_stream.string).must_match(
%r{ERROR -- : OpenTelemetry error: OTLP exporter received http\.code=404 for uri: '/v1/traces'}
%r{ERROR -- : OpenTelemetry error: OTLP exporter received http\.code=404 for uri='http://localhost:4318/v1/traces'}
)

_(result).must_equal(FAILURE)
Expand Down

0 comments on commit d08bc1a

Please sign in to comment.