Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up whitespace in OTEL_RESOURCE_ATTRIBUTES #1541

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdk/lib/opentelemetry/sdk/resources/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: Apache-2.0

require 'uri'

module OpenTelemetry
module SDK
module Resources
Expand Down Expand Up @@ -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? }
Expand Down
7 changes: 7 additions & 0 deletions sdk/test/opentelemetry/sdk/configurator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading