From b0798713fb5c90c31d1c14736e1883965c689a01 Mon Sep 17 00:00:00 2001 From: Daniel Christo Date: Thu, 13 Nov 2025 16:54:31 -0500 Subject: [PATCH] test: add retry and status code handling tests to trace exporter --- .../exporter/otlp/http/trace_exporter_test.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/exporter/otlp-http/test/opentelemetry/exporter/otlp/http/trace_exporter_test.rb b/exporter/otlp-http/test/opentelemetry/exporter/otlp/http/trace_exporter_test.rb index 0281a6e97..fa21f546b 100644 --- a/exporter/otlp-http/test/opentelemetry/exporter/otlp/http/trace_exporter_test.rb +++ b/exporter/otlp-http/test/opentelemetry/exporter/otlp/http/trace_exporter_test.rb @@ -356,6 +356,55 @@ @retry_count = 0 end + describe 'HTTP status code retry behavior' do + describe 'retryable status codes' do + [ + { code: 429, name: 'Too Many Requests' }, + { code: 503, name: 'Service Unavailable' }, + { code: 408, name: 'Request Timeout' }, + { code: 504, name: 'Gateway Timeout' }, + { code: 502, name: 'Bad Gateway' } + ].each do |status| + it "retries on #{status[:code]} (#{status[:name]}) and eventually fails after max retries" do + request_stub = stub_request(:post, 'http://localhost:4318/v1/traces') + .to_return { { status: status[:code] } } + + span_data = OpenTelemetry::TestHelpers.create_span_data + empty_backoff_delay = ->(_) { nil } + + exporter.stub(:sleep, empty_backoff_delay) do + result = exporter.export([span_data]) + _(result).must_equal(export_failure) + + retry_count = OpenTelemetry::Exporter::OTLP::HTTP::TraceExporter.const_get(:RETRY_COUNT) + assert_requested(request_stub, times: 1 + retry_count) + end + end + end + end + + describe 'non-retryable status codes' do + [ + { code: 400, name: 'Bad Request' }, + { code: 401, name: 'Unauthorized' }, + { code: 403, name: 'Forbidden' }, + { code: 404, name: 'Not Found' }, + { code: 500, name: 'Internal Server Error' } + ].each do |status| + it "does not retry on #{status[:code]} (#{status[:name]})" do + request_stub = stub_request(:post, 'http://localhost:4318/v1/traces') + .to_return(status: status[:code]) + + span_data = OpenTelemetry::TestHelpers.create_span_data + result = exporter.export([span_data]) + + _(result).must_equal(export_failure) + assert_requested(request_stub, times: 1) + end + end + end + end + it 'returns FAILURE when shutdown' do exporter.shutdown result = exporter.export(nil)