Skip to content

Commit 246f256

Browse files
chrisholmesrobertlaurinfbogsany
authored
fix: handle OTLP exporter 404s discretely (#1261)
* fix: handle plain/text responses when logging The otel-collecor uses a 404 with a plain/text content-type when the exporter path doesn't match the one configured by the colletor. This commit adds a check to handle this content type. * fix: log message for 404s * Update exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb Co-authored-by: Robert <[email protected]> Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent b230191 commit 246f256

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
174174
response.body # Read and discard body
175175
redo if backoff?(retry_count: retry_count += 1, reason: response.code)
176176
FAILURE
177+
when Net::HTTPNotFound
178+
OpenTelemetry.handle_error(message: "OTLP exporter received http.code=404 for uri: '#{@path}'")
179+
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
180+
FAILURE
177181
when Net::HTTPBadRequest, Net::HTTPClientError, Net::HTTPServerError
178182
log_status(response.body)
179183
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })

exporter/otlp/test/opentelemetry/exporter/otlp/exporter_test.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@
404404

405405
details = [::Google::Protobuf::Any.pack(::Google::Protobuf::StringValue.new(value: 'you are a bad request'))]
406406
status = ::Google::Rpc::Status.encode(::Google::Rpc::Status.new(code: 1, message: 'bad request', details: details))
407-
stub_request(:post, 'http://localhost:4318/v1/traces').to_return(status: 400, body: status)
407+
stub_request(:post, 'http://localhost:4318/v1/traces').to_return(status: 400, body: status, headers: { 'Content-Type' => 'application/x-protobuf' })
408408
span_data = OpenTelemetry::TestHelpers.create_span_data
409409

410410
result = exporter.export([span_data])
@@ -418,6 +418,25 @@
418418
OpenTelemetry.logger = logger
419419
end
420420

421+
it 'logs a specific message when there is a 404' do
422+
log_stream = StringIO.new
423+
logger = OpenTelemetry.logger
424+
OpenTelemetry.logger = ::Logger.new(log_stream)
425+
426+
stub_request(:post, 'http://localhost:4318/v1/traces').to_return(status: 404, body: "Not Found\n")
427+
span_data = OpenTelemetry::TestHelpers.create_span_data
428+
429+
result = exporter.export([span_data])
430+
431+
_(log_stream.string).must_match(
432+
%r{ERROR -- : OpenTelemetry error: OTLP exporter received http\.code=404 for uri: '/v1/traces'}
433+
)
434+
435+
_(result).must_equal(FAILURE)
436+
ensure
437+
OpenTelemetry.logger = logger
438+
end
439+
421440
it 'handles Zlib gzip compression errors' do
422441
stub_request(:post, 'http://localhost:4318/v1/traces').to_raise(Zlib::DataError.new('data error'))
423442
span_data = OpenTelemetry::TestHelpers.create_span_data

0 commit comments

Comments
 (0)