Skip to content

Commit 21babd0

Browse files
pkanalfbogsany
andauthored
fix: OTEL_EXPORTER_OTLP_ENDPOINT appends the correct path with a trailing slash (#1339)
* fix: OTEL_EXPORTER_OTLP_ENDPOINT appends the correct path with a trailing slash * use File.join * use URI.join Co-authored-by: Francis Bogsanyi <[email protected]> * remove constant Co-authored-by: Francis Bogsanyi <[email protected]> * remove extra empty line Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent 6727391 commit 21babd0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def initialize(endpoint: OpenTelemetry::Common::Utilities.config_opt('OTEL_EXPOR
5656
raise ArgumentError, "unsupported compression key #{compression}" unless compression.nil? || %w[gzip none].include?(compression)
5757

5858
@uri = if endpoint == ENV['OTEL_EXPORTER_OTLP_ENDPOINT']
59-
URI("#{endpoint}/v1/traces")
59+
URI.join(endpoint, 'v1/traces')
6060
else
6161
URI(endpoint)
6262
end

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@
110110
_(http.port).must_equal 4321
111111
end
112112

113+
it 'appends the correct path if OTEL_EXPORTER_OTLP_ENDPOINT has a trailing slash' do
114+
exp = OpenTelemetry::TestHelpers.with_env(
115+
'OTEL_EXPORTER_OTLP_ENDPOINT' => 'https://localhost:1234/'
116+
) do
117+
OpenTelemetry::Exporter::OTLP::Exporter.new()
118+
end
119+
_(exp.instance_variable_get(:@path)).must_equal '/v1/traces'
120+
end
121+
122+
it 'appends the correct path if OTEL_EXPORTER_OTLP_ENDPOINT does not have a trailing slash' do
123+
exp = OpenTelemetry::TestHelpers.with_env(
124+
'OTEL_EXPORTER_OTLP_ENDPOINT' => 'https://localhost:1234'
125+
) do
126+
OpenTelemetry::Exporter::OTLP::Exporter.new()
127+
end
128+
_(exp.instance_variable_get(:@path)).must_equal '/v1/traces'
129+
end
130+
113131
it 'restricts explicit headers to a String or Hash' do
114132
exp = OpenTelemetry::Exporter::OTLP::Exporter.new(headers: { 'token' => 'über' })
115133
_(exp.instance_variable_get(:@headers)).must_equal('token' => 'über')

0 commit comments

Comments
 (0)