diff --git a/sdk/lib/opentelemetry/sdk/resources/resource.rb b/sdk/lib/opentelemetry/sdk/resources/resource.rb index e05acf19a..c157b9049 100644 --- a/sdk/lib/opentelemetry/sdk/resources/resource.rb +++ b/sdk/lib/opentelemetry/sdk/resources/resource.rb @@ -4,6 +4,8 @@ # # SPDX-License-Identifier: Apache-2.0 +require 'uri' + module OpenTelemetry module SDK module Resources @@ -46,7 +48,7 @@ def telemetry_sdk resource_pairs.split(',').each do |pair| key, value = pair.split('=') - resource_attributes[key] = value + resource_attributes[key.strip] = URI.decode_www_form_component(value.strip) end resource_attributes.delete_if { |_key, value| value.nil? || value.empty? } diff --git a/sdk/test/opentelemetry/sdk/configurator_test.rb b/sdk/test/opentelemetry/sdk/configurator_test.rb index 50e6c18ef..57e350eb7 100644 --- a/sdk/test/opentelemetry/sdk/configurator_test.rb +++ b/sdk/test/opentelemetry/sdk/configurator_test.rb @@ -108,6 +108,13 @@ _(configurator_resource_attributes).must_equal(expected_resource_attributes) end end + + it 'cleans up whitespace in user provided resources' do + OpenTelemetry::TestHelpers.with_env('OTEL_RESOURCE_ATTRIBUTES' => ' important_foo=x, important_bar=y ') do + configurator.resource = OpenTelemetry::SDK::Resources::Resource.create() + _(configurator_resource_attributes).must_equal(default_resource_attributes.merge('important_foo' => 'x', 'important_bar' => 'y')) + end + end end end