Add option for logback to capture message template #15423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially implements #15119. Only for logback.
Added a new
captureTemplateoption to the logbackOpenTelemetryAppender. Default isfalse.The new option captures the unformatted log message template in the
log.body.templatelog event attribute proposed in open-telemetry/semantic-conventions#1283.For example:
will result in the
log.body.templateattribute being set toMy favorite color is: {}When
captureTemplateis true, the template is always captured, even if no arguments are provided.Enable in the library by configuring the
OpenTelemetryAppenderwith<captureTemplate>true</captureTemplate>.Enable in the javaagent by setting
otel.instrumentation.logback-appender.experimental.capture-template=true.The existing
captureArgumentsoption previously enabled both capturing the template and arguments. However, it was only documented to capture the arguments. NowcaptureArgumentsonly enables capturing arguments (not the message template). This is a backwards incompatible change to an experimental config option. Users currently settingcaptureArguments=truewould now need to set bothcaptureArguments=trueandcaptureTemplate=trueto 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.