Skip to content

Commit 81f6d1d

Browse files
committed
More detailed error message for old default exporter
1 parent 21e5b71 commit 81f6d1d

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/trace_exporter.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,29 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/MethodLength
167167
response.body # Read and discard body
168168
SUCCESS
169169
when Net::HTTPServiceUnavailable, Net::HTTPTooManyRequests
170-
response.body # Read and discard body
170+
body = response.body
171171
redo if backoff?(retry_after: response['Retry-After'], retry_count: retry_count += 1, reason: response.code)
172172
OpenTelemetry.logger.error("OTLP::HTTP::TraceExporter: export failed with #{response.code} after #{retry_count} retries")
173-
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} after #{retry_count} retries")
173+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}) after #{retry_count} retries: #{body}")
174174
when Net::HTTPRequestTimeOut, Net::HTTPGatewayTimeOut, Net::HTTPBadGateway
175-
response.body # Read and discard body
175+
body = response.body
176176
redo if backoff?(retry_count: retry_count += 1, reason: response.code)
177177
OpenTelemetry.logger.error("OTLP::HTTP::TraceExporter: export failed with #{response.code} after #{retry_count} retries")
178-
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} after #{retry_count} retries")
178+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}) after #{retry_count} retries: #{body}")
179179
when Net::HTTPBadRequest, Net::HTTPClientError, Net::HTTPServerError
180-
log_status(response.body)
180+
body = response.body
181+
log_status(body)
181182
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
182-
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code}")
183+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}): #{body}")
183184
when Net::HTTPRedirection
184185
@http.finish
185186
handle_redirect(response['location'])
186187
redo if backoff?(retry_after: 0, retry_count: retry_count += 1, reason: response.code)
187188
else
188189
@http.finish
190+
body = response.body
189191
OpenTelemetry.logger.error("OTLP::HTTP::TraceExporter: export failed with unexpected HTTP response #{response.code}")
190-
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with unexpected HTTP response #{response.code}")
192+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with unexpected HTTP response #{response.code} (#{response.message}): #{body}")
191193
end
192194
rescue Net::OpenTimeout, Net::ReadTimeout => e
193195
retry if backoff?(retry_count: retry_count += 1, reason: 'timeout')

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def initialize(endpoint: nil,
7676
# @param [optional Numeric] timeout An optional timeout in seconds.
7777
# @return [Integer] the result of the export.
7878
def export(span_data, timeout: nil)
79-
return FAILURE if @shutdown
79+
return OpenTelemetry::SDK::Trace::Export.failure(message: 'exporter is shutdown') if @shutdown
8080

8181
send_bytes(encode(span_data), timeout: timeout)
8282
end
@@ -146,7 +146,7 @@ def around_request
146146
end
147147

148148
def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
149-
return FAILURE if bytes.nil?
149+
return OpenTelemetry::SDK::Trace::Export.failure(message: 'send_bytes called with nil bytes') if bytes.nil?
150150

151151
@metrics_reporter.record_value('otel.otlp_exporter.message.uncompressed_size', value: bytes.bytesize)
152152

@@ -168,7 +168,7 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
168168

169169
around_request do
170170
remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)
171-
return FAILURE if remaining_timeout.zero?
171+
return OpenTelemetry::SDK::Trace::Export.failure(message: 'timeout exceeded before sending request') if remaining_timeout.zero?
172172

173173
@http.open_timeout = remaining_timeout
174174
@http.read_timeout = remaining_timeout
@@ -181,52 +181,55 @@ def send_bytes(bytes, timeout:) # rubocop:disable Metrics/CyclomaticComplexity,
181181
response.body # Read and discard body
182182
SUCCESS
183183
when Net::HTTPServiceUnavailable, Net::HTTPTooManyRequests
184-
response.body # Read and discard body
184+
body = response.body
185185
redo if backoff?(retry_after: response['Retry-After'], retry_count: retry_count += 1, reason: response.code)
186-
FAILURE
186+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}) after #{retry_count} retries: #{body}")
187187
when Net::HTTPRequestTimeOut, Net::HTTPGatewayTimeOut, Net::HTTPBadGateway
188-
response.body # Read and discard body
188+
body = response.body
189189
redo if backoff?(retry_count: retry_count += 1, reason: response.code)
190-
FAILURE
190+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}) after #{retry_count} retries: #{body}")
191191
when Net::HTTPNotFound
192+
body = response.body
192193
log_request_failure(response.code)
193-
FAILURE
194+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}): #{body}")
194195
when Net::HTTPBadRequest, Net::HTTPClientError, Net::HTTPServerError
195-
log_status(response.body)
196+
body = response.body
197+
log_status(body)
196198
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
197-
FAILURE
199+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with HTTP #{response.code} (#{response.message}): #{body}")
198200
when Net::HTTPRedirection
199201
@http.finish
200202
handle_redirect(response['location'])
201203
redo if backoff?(retry_after: 0, retry_count: retry_count += 1, reason: response.code)
202204
else
203205
@http.finish
206+
body = response.body
204207
log_request_failure(response.code)
205-
FAILURE
208+
OpenTelemetry::SDK::Trace::Export.failure(message: "export failed with unexpected HTTP response #{response.code} (#{response.message}): #{body}")
206209
end
207-
rescue Net::OpenTimeout, Net::ReadTimeout
210+
rescue Net::OpenTimeout, Net::ReadTimeout => e
208211
retry if backoff?(retry_count: retry_count += 1, reason: 'timeout')
209-
return FAILURE
212+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: "export failed due to #{e.class} after #{retry_count} retries")
210213
rescue OpenSSL::SSL::SSLError => e
211214
retry if backoff?(retry_count: retry_count += 1, reason: 'openssl_error')
212215
OpenTelemetry.handle_error(exception: e, message: 'SSL error in OTLP::Exporter#send_bytes')
213-
return FAILURE
214-
rescue SocketError
216+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: 'SSL error in OTLP::Exporter#send_bytes')
217+
rescue SocketError => e
215218
retry if backoff?(retry_count: retry_count += 1, reason: 'socket_error')
216-
return FAILURE
219+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: "export failed due to SocketError after #{retry_count} retries: #{e.message}")
217220
rescue SystemCallError => e
218221
retry if backoff?(retry_count: retry_count += 1, reason: e.class.name)
219-
return FAILURE
220-
rescue EOFError
222+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: "export failed due to #{e.class} after #{retry_count} retries: #{e.message}")
223+
rescue EOFError => e
221224
retry if backoff?(retry_count: retry_count += 1, reason: 'eof_error')
222-
return FAILURE
223-
rescue Zlib::DataError
225+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: "export failed due to EOFError after #{retry_count} retries: #{e.message}")
226+
rescue Zlib::DataError => e
224227
retry if backoff?(retry_count: retry_count += 1, reason: 'zlib_error')
225-
return FAILURE
228+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: "export failed due to Zlib::DataError after #{retry_count} retries: #{e.message}")
226229
rescue StandardError => e
227230
OpenTelemetry.handle_error(exception: e, message: 'unexpected error in OTLP::Exporter#send_bytes')
228231
@metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => e.class.to_s })
229-
return FAILURE
232+
return OpenTelemetry::SDK::Trace::Export.failure(error: e, message: 'unexpected error in OTLP::Exporter#send_bytes')
230233
end
231234
ensure
232235
# Reset timeouts to defaults for the next call.

0 commit comments

Comments
 (0)