Skip to content

Commit 582ae2d

Browse files
committed
Only set log template if message differs from template
1 parent 85d7417 commit 582ae2d

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ protected void captureLog(@NotNull LogRecord loggingEvent) {
154154
message = loggingEvent.getResourceBundle().getString(loggingEvent.getMessage());
155155
}
156156

157-
attributes.add(SentryAttribute.stringAttribute("sentry.message.template", message));
158-
159157
final @NotNull String formattedMessage = maybeFormatted(arguments, message);
158+
159+
if (!formattedMessage.equals(message)) {
160+
attributes.add(SentryAttribute.stringAttribute("sentry.message.template", message));
161+
}
162+
160163
final @NotNull SentryLogParameters params = SentryLogParameters.create(attributes);
161164
params.setOrigin("auto.log.jul");
162165

sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,14 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
222222
final @Nullable Object[] arguments = loggingEvent.getMessage().getParameters();
223223
final @NotNull SentryAttributes attributes = SentryAttributes.of();
224224

225-
attributes.add(
226-
SentryAttribute.stringAttribute(
227-
"sentry.message.template", loggingEvent.getMessage().getFormat()));
228-
225+
final @Nullable String nonFormattedMessage = loggingEvent.getMessage().getFormat();
229226
final @NotNull String formattedMessage = loggingEvent.getMessage().getFormattedMessage();
227+
228+
if (nonFormattedMessage != null && !formattedMessage.equals(nonFormattedMessage)) {
229+
attributes.add(
230+
SentryAttribute.stringAttribute("sentry.message.template", nonFormattedMessage));
231+
}
232+
230233
final @NotNull SentryLogParameters params = SentryLogParameters.create(attributes);
231234
params.setOrigin("auto.log.log4j2");
232235

sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,18 @@ protected void captureLog(@NotNull ILoggingEvent loggingEvent) {
183183

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

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

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

0 commit comments

Comments
 (0)