Skip to content

Conversation

@philsttr
Copy link
Contributor

@philsttr philsttr commented Nov 21, 2025

Partially implements #15119. Only for logback.

Added a new captureTemplate option to the logback OpenTelemetryAppender. Default is false.
The new option captures the unformatted log message template in the log.body.template log event attribute proposed in open-telemetry/semantic-conventions#1283.

For example:

logger.info("My favorite color is: {}", favoriteColor);

will result in the log.body.template attribute being set to My favorite color is: {}

When captureTemplate is true, the template is always captured, even if no arguments are provided.

Enable in the library by configuring the OpenTelemetryAppender with <captureTemplate>true</captureTemplate>.
Enable in the javaagent by setting otel.instrumentation.logback-appender.experimental.capture-template=true.

The existing captureArguments option previously enabled both capturing the template and arguments. However, it was only documented to capture the arguments. Now captureArguments only enables capturing arguments (not the message template). This is a backwards incompatible change to an experimental config option. Users currently setting captureArguments=true would now need to set both captureArguments=true and captureTemplate=true to maintain close to the previous behavior. It won't be exact, because the previous behavior only captured the template if arguments were provided.

This PR only implements this change for logback (not log4j, jboss-logmanager, or java-util-logging). Others could be done in future PRs.

@philsttr philsttr requested a review from a team as a code owner November 21, 2025 18:06
@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Nov 21, 2025
Added a new `captureTemplate` option to the logback `OpenTelemetryAppender`.  Default is false.
The new option captures the unformatted log message template in the `log.body.template` log event attribute.

Enable in the library by configuring the `OpenTelemetryAppender` with `<captureTemplate>true</captureTemplate>`.
Enable in the javaagent by setting `otel.instrumentation.logback-appender.experimental.capture-template=true`.

The existing `captureArguments` option previously enabled both capturing the template and arguments.
Now `captureArguments` only enables capturing arguments (not the message template).
This is a backwards incompatible change to an experimental config option.
Users currently setting `captureArguments=true` would now need to set both `captureArguments=true` and `captureTemplate=true` to maintain previous behavior.
@philsttr philsttr force-pushed the gh-15119-log-message-template branch from d14ed35 to 07ef9f9 Compare November 21, 2025 18:24
@philsttr
Copy link
Contributor Author

failing tests seem unrelated to changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant