Skip to content

Conversation

ldematte
Copy link
Contributor

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.

@ldematte ldematte added >bug :Core/Infra/REST API REST infrastructure and utilities auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 labels May 22, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label May 22, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Collaborator

Hi @ldematte, I've created a changelog YAML for you.

@ldematte ldematte requested a review from a team May 22, 2025 14:51
Copy link
Member

@rjernst rjernst left a 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

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));
Copy link
Member

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?

Copy link
Contributor Author

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)

@ldematte ldematte merged commit 6bf5316 into elastic:main May 23, 2025
18 checks passed
@ldematte ldematte deleted the fix-apm-traces-npe branch May 23, 2025 07:32
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.
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.19
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team v8.19.0 v9.1.0

3 participants