-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[exporter/elasticsearch] fix panic when encoding scope attributes #40098
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
[exporter/elasticsearch] fix panic when encoding scope attributes #40098
Conversation
6fd6d65
to
85b7f41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, code lgtm. One issue with the changelog
85b7f41
to
0b2be72
Compare
0b2be72
to
56ef63b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to merge after a code owner reviews this.
@@ -449,11 +449,12 @@ func durationAsMicroseconds(start, end time.Time) int64 { | |||
|
|||
func scopeToAttributes(scope pcommon.InstrumentationScope) pcommon.Map { | |||
attrs := pcommon.NewMap() | |||
|
|||
scope.Attributes().CopyTo(attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reordering has the consequence that if a scope attribute named "name" or "version" exists, it will be overridden by scope name or version. I believe in general this is the right thing to do, with the exception of when the scope name or version is empty.
I'd like to see a follow-up change to only set scope name and version as attributes if they aren't empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the contribution!
…en-telemetry#40098) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Previously, the code attempted to cast scope attribute values to strings, leading to a panic when incompatible types were encountered. When mapping scope to attributes, instead of trying to cast them to string now it just creates a new Map for the attributes and copies the cope entries to the new map. This avoids any cast and preserves the original types. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37701 <!--Describe what testing was performed and which tests were added.--> #### Testing Run the exporter with the config that originally causes the panic, see config below. Running it on main will panic, running it on this PR will not panic. ``` ./bin/otelcontribcol_linux_amd64 --config otel-test.yaml ``` ``` receivers: hostmetrics: metadata_collection_interval: 1s scrapers: cpu: {} exporters: elasticsearch: mapping: mode: none endpoint: <redacted> user: <redacted> password: <redacted> flush: interval: 1s service: pipelines: logs: receivers: [hostmetrics] processors: [] exporters: [elasticsearch] ``` <!--Describe the documentation added.--> #### Documentation N/A <!--Please delete paragraphs that you did not use before submitting.-->
…en-telemetry#40098) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Previously, the code attempted to cast scope attribute values to strings, leading to a panic when incompatible types were encountered. When mapping scope to attributes, instead of trying to cast them to string now it just creates a new Map for the attributes and copies the cope entries to the new map. This avoids any cast and preserves the original types. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#37701 <!--Describe what testing was performed and which tests were added.--> #### Testing Run the exporter with the config that originally causes the panic, see config below. Running it on main will panic, running it on this PR will not panic. ``` ./bin/otelcontribcol_linux_amd64 --config otel-test.yaml ``` ``` receivers: hostmetrics: metadata_collection_interval: 1s scrapers: cpu: {} exporters: elasticsearch: mapping: mode: none endpoint: <redacted> user: <redacted> password: <redacted> flush: interval: 1s service: pipelines: logs: receivers: [hostmetrics] processors: [] exporters: [elasticsearch] ``` <!--Describe the documentation added.--> #### Documentation N/A <!--Please delete paragraphs that you did not use before submitting.-->
Description
Previously, the code attempted to cast scope attribute values to strings, leading to a panic when incompatible types were encountered.
When mapping scope to attributes, instead of trying to cast them to string now it just creates a new Map for the attributes and copies the cope entries to the new map. This avoids any cast and preserves the original types.
Link to tracking issue
Fixes #37701
Testing
Run the exporter with the config that originally causes the panic, see config below.
Running it on main will panic, running it on this PR will not panic.
Documentation
N/A