open-telemetry / opentelemetry-cpp

The OpenTelemetry C++ Client
https://opentelemetry.io/
Apache License 2.0
850 stars 403 forks source link

Is formating for log messages actually implemented? #2628

Open GeorgViehoever opened 6 months ago

GeorgViehoever commented 6 months ago

I am trying to use formatting for log messages as suggested in https://github.com/open-telemetry/opentelemetry-cpp/blob/e86ceba79dc5999c7b3655fd006847a360b351a0/api/include/opentelemetry/logs/logger.h#L287. It does not seem to work. Q: Is it actually implemented? Q: Do you have an example code for me? Something like:

 std::map<std::string, std::string> labelsTrace = {{"userId", "myUserId"}};
    logger->Trace(
          "traceLogMessage of user {userId}";
          labelsTrace);
lalitb commented 6 months ago

Perhaps this needs to be documented better. The formatting of the message is not done by OpenTelemetry SDK, but the onus is on upstream agents or exporters who want the support.

GeorgViehoever commented 5 months ago

I suggest to make this into a bug that requests to improve documentation. I believe I found nothing to this effect in the Docs or any code comments.

github-actions[bot] commented 3 months ago

This issue was marked as stale due to lack of activity.

punya commented 1 month ago

Does the Logging API spec include support for a format string? (I wasn't able to find it.)

I was under the impression that the user-facing API should adhere closely to the spec. @ThomsonTan who originally added the API might know more about the design. For example, was the goal to propose format strings to the spec with C++ as a reference implementation?

lalitb commented 1 month ago

I was under the impression that the user-facing API should adhere closely to the spec.

The otel-cpp logging API has two parts

  1. user-facing API
  2. bridge-api (rest of the code under opentelemetry::logs namespace)

Otel specs only specify the bridge-api which is used to create appenders for the use-facing API. The specs doesn't specify a user-facing API, as most languages already have their own logging frameworks.

Regarding format string, it is only part of user-facing api, and get referenced as LogRecord::body in bridge-api. The custom exporters, or upstream agents can do the actual formatting (if required).