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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/lib/opentelemetry/sdk/resources/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def telemetry_sdk

resource_pairs.split(',').each do |pair|
key, value = pair.split('=')
resource_attributes[key] = value
resource_attributes[key.strip] = value
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 @@ -87,6 +87,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this trim values as well?

Suggested change
OpenTelemetry::TestHelpers.with_env('OTEL_RESOURCE_ATTRIBUTES' => 'important_foo=x, important_bar=y') do
OpenTelemetry::TestHelpers.with_env('OTEL_RESOURCE_ATTRIBUTES' => ' important_foo=x, important_bar=y ') do

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this but decided against it - I could add it in, not sure what other otel instrumentation agents do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be using Baggage format so should be trimming spance then URL decoding https://github.com/open-telemetry/opentelemetry-go/blob/main/sdk/resource/env.go#L92

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my first time ever writing ruby and I haven't been able to run the tests locally (got ruby 2 installed), but I have made the changes and hopefully they make sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait sorry I messed up the order, trim first! committing in a moment

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