Skip to content

[DOCS] clarify logger format handling - #4149

Merged
dbarker merged 5 commits into
open-telemetry:mainfrom
SyedAsadRazaDevops:syedasadrazadevops/2628-logger-format-docs
Sep 11, 2026
Merged

dbarker merged 5 commits into
open-telemetry:mainfrom
SyedAsadRazaDevops:syedasadrazadevops/2628-logger-format-docs

Conversation

@SyedAsadRazaDevops

@SyedAsadRazaDevops SyedAsadRazaDevops commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Clarifies the logger API documentation for the format parameter. The current wording links to message templates, which can imply that placeholders are interpolated from attributes. This change documents the current behavior: the format string is stored as the log record body, and structured data should be passed through attributes.

Fixes #2628

Type of change

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change

Verification

  • git diff --check
  • scripts/assert-cncf-github-identity.ps1 -RepoPath upstreams\open-telemetry\opentelemetry-cpp

No runtime behavior changed.

@codecov

codecov Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (58d4197) to head (41670f7).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4149      +/-   ##
==========================================
+ Coverage   86.41%   86.42%   +0.01%     
==========================================
  Files         524      524              
  Lines       20421    20421              
==========================================
+ Hits        17644    17646       +2     
+ Misses       2777     2775       -2     
Files with missing lines Coverage Δ
api/include/opentelemetry/logs/logger.h 81.12% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

* @param severity severity of the log
* @param event_id event identifier of the log
* @param format an utf-8 string following https://messagetemplates.org/
* @param format a UTF-8 string stored as the log record body

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new note about no SDK-side interpolation is useful, but should we avoid removing the message-template intent entirely? My understanding is that format was kept as a user-facing API concept so custom exporters or upstream agents could interpret it as a message template, even though the OpenTelemetry spec does not require the SDK itself to format it. Maybe this should say that the SDK stores the string as the log record body and does not interpolate attributes, while preserving that exporters/agents may choose to interpret it as a message template.
cc @ThomsonTan - I believe he added the original comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original intention is recommending the user to pass in message-template. It is not required for SDK or exporter (we don't do that) to do the interpolation, but everything are there for the interpolation so it could be done later, like in the storage backend. Let's add clarification on this instead of revoing the intention.

@dbarker dbarker Sep 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec has some guidance on the ergonomic API to emit events now and this is new since the C++ event API was implemented.
https://opentelemetry.io/docs/specs/otel/logs/api/#ergonomic-api

Ergonomic API
Status: Development

Languages MAY additionally provide a more ergonomic and convenient logging API.

The ergonomic API SHOULD make it more convenient to emit event records following the event semantics.

The design of the ergonomic API SHOULD be idiomatic for its language.

I think the change to the comment in this PR is a good one as it clarifies what member of the log record the arg sets.

If we follow the event semantics then we should also rename the format arg to body and leave it to the caller to use as they wish (which may be a format string following https://messagetemplates.org/).

@dbarker dbarker added the pr:please-review This PR is ready for review label Aug 8, 2026

@dbarker dbarker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@dbarker dbarker removed the pr:please-review This PR is ready for review label Sep 11, 2026
@dbarker
dbarker enabled auto-merge (squash) September 11, 2026 15:00
@dbarker dbarker changed the title docs(logs): clarify logger format handling [DOCS] clarify logger format handling Sep 11, 2026
@dbarker
dbarker merged commit 0cd9e5b into open-telemetry:main Sep 11, 2026
77 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is formating for log messages actually implemented?

4 participants