Skip to content

[TRACE] OTLP HTTP exporter console logs issues #1702

@marcalff

Description

@marcalff

Using the OTLP HTTP exporter, and printing debug logs generated by otlp_http_client.cc leads to the following data:

2022-10-20T22:00:14.654921Z 0 [...] [OTEL DEBUG] /.../opentelemetry-cpp/opentelemetry-cpp-1.6.1/exporters/otlp/src/otlp_http_client.cc:126 [OTLP HTTP Client] Export success, Status:200Header:        Content-Length : 0^M,   Content-Type : application/x-protobuf^M,        Date : Thu, 20 Oct 2022 22:00:14 GMT^M,Body:

Note how "Status:200Header:" is printed, without spaces or comma to separate status from header.

Note how fields are printed sometime as "field:value", sometime as "field : value"
Because of this, logs are harder to parse that necessary.

If using spaces before and after ":", and a "," plus space to separate fields, then please use this consistently.

For example, print "Status : 200, Header :" instead.

The code printing this log is exporter::otlp::ResponseHandler::BuildResponseLogMessage

  std::string BuildResponseLogMessage(http_client::Response &response,
                                      const std::string &body) noexcept
  {
    std::stringstream ss;
    ss << "Status:" << response.GetStatusCode() << "Header:";
    response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name,
                                 opentelemetry::nostd::string_view header_value) {
      ss << "\t" << header_name.data() << " : " << header_value.data() << ",";
      return true;
    });
    ss << "Body:" << body;

    return ss.str();
  }

Also, as seen when reading the code in exporter::otlp::ResponseHandler::OnResponse,

      if (response.GetStatusCode() != 200 && response.GetStatusCode() != 202)
      {
        log_message = BuildResponseLogMessage(response, body_);

        OTEL_INTERNAL_LOG_ERROR("OTLP HTTP Client] Export failed, " << log_message);
        result = sdk::common::ExportResult::kFailure;
      }

      if (console_debug_)
      {
        if (log_message.empty())
        {
          log_message = BuildResponseLogMessage(response, body_);
        }
        OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Client] Export success, " << log_message);
      }
    }

The OTEL_INTERNAL_LOG_DEBUG() log statement prints "Export success", including on failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions