Skip to content

Commit 2dda0ff

Browse files
authored
feat: OTEL_EXPORTER_JAEGER_TIMEOUT env var (#881)
1 parent e54b63e commit 2dda0ff

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

exporter/jaeger/lib/opentelemetry/exporter/jaeger/agent_exporter.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AgentExporter
1515

1616
def initialize(host: ENV.fetch('OTEL_EXPORTER_JAEGER_AGENT_HOST', 'localhost'),
1717
port: ENV.fetch('OTEL_EXPORTER_JAEGER_AGENT_PORT', 6831),
18+
timeout: ENV.fetch('OTEL_EXPORTER_JAEGER_TIMEOUT', 10),
1819
max_packet_size: 65_000)
1920
transport = Transport.new(host, port)
2021
protocol = ::Thrift::CompactProtocol.new(transport)
@@ -23,6 +24,7 @@ def initialize(host: ENV.fetch('OTEL_EXPORTER_JAEGER_AGENT_HOST', 'localhost'),
2324
@shutdown = false
2425
@sizing_transport = SizingTransport.new
2526
@sizing_protocol = ::Thrift::CompactProtocol.new(@sizing_transport)
27+
@timeout = timeout.to_f
2628
end
2729

2830
# Called to export sampled {OpenTelemetry::SDK::Trace::SpanData} structs.
@@ -35,6 +37,7 @@ def initialize(host: ENV.fetch('OTEL_EXPORTER_JAEGER_AGENT_HOST', 'localhost'),
3537
def export(span_data, timeout: nil)
3638
return FAILURE if @shutdown
3739

40+
timeout ||= @timeout
3841
start_time = OpenTelemetry::Common::Utilities.timeout_timestamp
3942
encoded_batches(span_data) do |batch|
4043
return FAILURE if @shutdown || OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time)&.zero?

exporter/jaeger/lib/opentelemetry/exporter/jaeger/collector_exporter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def self.ssl_verify_mode
2828
def initialize(endpoint: ENV.fetch('OTEL_EXPORTER_JAEGER_ENDPOINT', 'http://localhost:14268/api/traces'),
2929
username: ENV['OTEL_EXPORTER_JAEGER_USER'],
3030
password: ENV['OTEL_EXPORTER_JAEGER_PASSWORD'],
31+
timeout: ENV.fetch('OTEL_EXPORTER_JAEGER_TIMEOUT', 10),
3132
ssl_verify_mode: CollectorExporter.ssl_verify_mode)
3233
raise ArgumentError, "invalid url for Jaeger::CollectorExporter #{endpoint}" if invalid_url?(endpoint)
3334
raise ArgumentError, 'username and password should either both be nil or both be set' if username.nil? != password.nil?

exporter/jaeger/test/opentelemetry/exporters/jaeger/agent_exporter_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
exporter = OpenTelemetry::Exporter::Jaeger::AgentExporter.new(host: '127.0.0.1', port: 6831)
1212
_(exporter).wont_be_nil
1313
end
14+
15+
it 'sets parameters from the environment' do
16+
exp = with_env('OTEL_EXPORTER_JAEGER_TIMEOUT' => '42') do
17+
OpenTelemetry::Exporter::Jaeger::AgentExporter.new
18+
end
19+
_(exp.instance_variable_get(:@timeout)).must_equal 42.0
20+
end
21+
22+
it 'prefers explicit parameters rather than the environment' do
23+
exp = with_env('OTEL_EXPORTER_JAEGER_TIMEOUT' => '42') do
24+
OpenTelemetry::Exporter::Jaeger::AgentExporter.new(timeout: 60)
25+
end
26+
_(exp.instance_variable_get(:@timeout)).must_equal 60.0
27+
end
1428
end
1529

1630
describe '#export' do

0 commit comments

Comments
 (0)