open-telemetry / open-telemetry/opentelemetry-cpp

[BUG] Elasticsearch exporter decides bulk success by substring instead of the errors field

Open
#4,295 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
C++
Stars
1.4k
Forks
632
Avg merge
1d 13h
Merged PRs (30d)
75

Description

Both export paths decide whether a bulk write succeeded by looking for a substring in the response body.

https://github.com/open-telemetry/opentelemetry-cpp/blob/9d38caf20eacb2618bcd5d9536aba0efcc2990aa/exporters/elasticsearch/src/es_log_record_exporter.cc#L248

https://github.com/open-telemetry/opentelemetry-cpp/blob/9d38caf20eacb2618bcd5d9536aba0efcc2990aa/exporters/elasticsearch/src/es_log_record_exporter.cc#L451

if (body_.find("\"failed\" : 0") == std::string::npos)

Three problems with that test.

failed is not the bulk outcome. In a bulk response, failed appears under _shards for an individual item. The result for the batch as a whole is the top level errors boolean. A body where one item has "failed": 0 and another item failed outright still matches the substring and is reported as a success.

It depends on pretty-printed spacing. The literal contains " : ". Elasticsearch only formats that way when the request asks for it, so a compact response never matches and a completely successful export is reported as a failure.

The asynchronous path ignores the HTTP status. AsyncResponseHandler::OnResponse only inspects the body, so a 4xx or 5xx with a body that happens to contain the substring is treated as a success. The synchronous path does check the status, in ResponseHandler::OnResponse.

Suggested fix

Parse the body and check the top level errors field, and check the HTTP status on both paths. nlohmann/json.hpp is already included by this file and already linked in both the CMake and Bazel targets, so this needs no new dependency. A malformed or unparseable body should count as a failure rather than being ignored.

I would like to work on this one.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in exporters/elasticsearch/src/es_log_record_exporter.cc at the synchronous and asynchronous OnResponse handlers referenced around lines 248 and 451. Read how each handler currently evaluates the response body and HTTP status. Done means both paths use the top-level errors field, honor HTTP status, and treat malformed bodies as failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, elasticsearch
Domain
backend, search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.