Fix NPE in APMTracer through RestController#128314
Merged
ldematte merged 2 commits intoelastic:mainfrom May 23, 2025
Merged
Conversation
Collaborator
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Collaborator
|
Hi @ldematte, I've created a changelog YAML for you. |
rjernst
approved these changes
May 23, 2025
| req.getHeaders().forEach((key, values) -> { | ||
| final String lowerKey = key.toLowerCase(Locale.ROOT).replace('-', '_'); | ||
| attributes.put("http.request.headers." + lowerKey, values.size() == 1 ? values.get(0) : String.join("; ", values)); | ||
| attributes.put("http.request.headers." + lowerKey, values == null ? "" : String.join("; ", values)); |
Member
There was a problem hiding this comment.
How did we get a null in the first place? If the header was passed but empty wouldn't it be an empty string?
Contributor
Author
There was a problem hiding this comment.
I think there is a possibility for the map to contain a key mapping to a null list; we wrap headers from netty HttpHeaders in Netty4HttpRequest like this:
// Map.get() implementation
public List<String> get(Object key) {
return key instanceof String ? httpHeaders.getAll((String) key) : null;
}
It's probably remote, but I decided to err on the safe side.
(To be precise, we did not get a null here, the null was in the http.method attribute, but I wanted to be sure this was not possible elsewhere too)
ldematte
added a commit
to ldematte/elasticsearch
that referenced
this pull request
May 23, 2025
Our APMTracer doesn't like nulls - this is a sensible thing, as APM in general does not allow nulls (it only allows a precise set of types). This PR changes the attribute to a sentinel "" in place of null values. It also makes a small change to APMTracer to give a better error message in case of null values in attributes.
Collaborator
💚 Backport successful
|
elasticsearchmachine
pushed a commit
that referenced
this pull request
May 23, 2025
Our APMTracer doesn't like nulls - this is a sensible thing, as APM in general does not allow nulls (it only allows a precise set of types). This PR changes the attribute to a sentinel "" in place of null values. It also makes a small change to APMTracer to give a better error message in case of null values in attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Our APMTracer doesn't like nulls - this is a sensible thing, as APM in general does not allow nulls (it only allows a precise set of types).
This PR changes the attribute to a sentinel "" in place of null values. It also makes a small change to APMTracer to give a better error message in case of null values in attributes.