Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Only set log template for logging integrations if formatted message differs from template ([#4682](https://github.com/getsentry/sentry-java/pull/4682))

### Features

- Add support for Spring Boot 4 and Spring 7 ([#4601](https://github.com/getsentry/sentry-java/pull/4601))
Expand Down
7 changes: 5 additions & 2 deletions sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ protected void captureLog(@NotNull LogRecord loggingEvent) {
message = loggingEvent.getResourceBundle().getString(loggingEvent.getMessage());
}

attributes.add(SentryAttribute.stringAttribute("sentry.message.template", message));

final @NotNull String formattedMessage = maybeFormatted(arguments, message);

if (!formattedMessage.equals(message)) {
attributes.add(SentryAttribute.stringAttribute("sentry.message.template", message));
}
Comment thread
lcian marked this conversation as resolved.

final @NotNull SentryLogParameters params = SentryLogParameters.create(attributes);
params.setOrigin("auto.log.jul");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,14 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
final @Nullable Object[] arguments = loggingEvent.getMessage().getParameters();
final @NotNull SentryAttributes attributes = SentryAttributes.of();

attributes.add(
SentryAttribute.stringAttribute(
"sentry.message.template", loggingEvent.getMessage().getFormat()));

final @Nullable String nonFormattedMessage = loggingEvent.getMessage().getFormat();
final @NotNull String formattedMessage = loggingEvent.getMessage().getFormattedMessage();

if (nonFormattedMessage != null && !formattedMessage.equals(nonFormattedMessage)) {
attributes.add(
SentryAttribute.stringAttribute("sentry.message.template", nonFormattedMessage));
}

final @NotNull SentryLogParameters params = SentryLogParameters.create(attributes);
params.setOrigin("auto.log.log4j2");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,18 @@ protected void captureLog(@NotNull ILoggingEvent loggingEvent) {

@Nullable Object[] arguments = null;
final @NotNull SentryAttributes attributes = SentryAttributes.of();
final @NotNull String formattedMessage = formatted(loggingEvent);

// if encoder is set we treat message+params as PII as encoders may be used to mask/strip PII
if (encoder == null || ScopesAdapter.getInstance().getOptions().isSendDefaultPii()) {
attributes.add(
SentryAttribute.stringAttribute("sentry.message.template", loggingEvent.getMessage()));
final @Nullable String nonFormattedMessage = loggingEvent.getMessage();
if (nonFormattedMessage != null && !formattedMessage.equals(nonFormattedMessage)) {
attributes.add(
SentryAttribute.stringAttribute("sentry.message.template", nonFormattedMessage));
}
arguments = loggingEvent.getArgumentArray();
}

final @NotNull String formattedMessage = formatted(loggingEvent);
final @NotNull SentryLogParameters params = SentryLogParameters.create(attributes);
params.setOrigin("auto.log.logback");

Expand Down
Loading