-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Fix NPE in APMTracer through RestController #128314
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
Conversation
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Hi @ldematte, I've created a changelog YAML for you. |
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.
Looks good, one question
@@ -560,10 +561,10 @@ private void startTrace(ThreadContext threadContext, RestChannel channel, String | |||
final Map<String, Object> attributes = Maps.newMapWithExpectedSize(req.getHeaders().size() + 3); | |||
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)); |
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.
How did we get a null in the first place? If the header was passed but empty wouldn't it be an empty string?
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.
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)
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.
💚 Backport successful
|
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.
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.