Skip to content

Commit 5a62c9f

Browse files
committed
add to context inside util function
1 parent 817e001 commit 5a62c9f

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ SentryEvent createEvent(final @NotNull LogRecord record) {
320320
// initialized somewhere else
321321
final List<String> contextTags = ScopesAdapter.getInstance().getOptions().getContextTags();
322322
LoggerPropertiesUtil.applyPropertiesToEvent(event, contextTags, mdcProperties);
323-
// put the rest of mdc tags in contexts
324-
if (!mdcProperties.isEmpty()) {
325-
event.getContexts().put("MDC", mdcProperties);
326-
}
327323
}
328324
}
329325
event.setExtra(THREAD_ID, record.getThreadID());

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,6 @@ protected void captureLog(@NotNull LogEvent loggingEvent) {
286286
// initialized somewhere else
287287
final List<String> contextTags = scopes.getOptions().getContextTags();
288288
LoggerPropertiesUtil.applyPropertiesToEvent(event, contextTags, contextData);
289-
// put the rest of mdc tags in contexts
290-
if (!contextData.isEmpty()) {
291-
event.getContexts().put("Context Data", contextData);
292-
}
293289
}
294290

295291
return event;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ protected void append(@NotNull ILoggingEvent eventObject) {
154154
// initialized somewhere else
155155
final List<String> contextTags = ScopesAdapter.getInstance().getOptions().getContextTags();
156156
LoggerPropertiesUtil.applyPropertiesToEvent(event, contextTags, mdcProperties);
157-
// put the rest of mdc tags in contexts
158-
if (!mdcProperties.isEmpty()) {
159-
event.getContexts().put("MDC", mdcProperties);
160-
}
161157
}
162158

163159
return event;

sentry/src/main/java/io/sentry/util/LoggerPropertiesUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
public final class LoggerPropertiesUtil {
1515

1616
/**
17-
* Applies logger properties from a map to a Sentry event as tags. Only the properties with keys
18-
* that are found in `targetKeys` will be applied as tags.
17+
* Applies logger properties from a map to a Sentry event as tags and context. The properties that
18+
* have keys matching any of the `targetKeys` will be applied as tags, while the others will be
19+
* reported in the `MDC` context.
1920
*
2021
* @param event the Sentry event to add tags to
2122
* @param targetKeys the list of property keys to apply as tags
@@ -34,6 +35,9 @@ public static void applyPropertiesToEvent(
3435
properties.remove(key);
3536
}
3637
}
38+
if (!properties.isEmpty()) {
39+
event.getContexts().put("MDC", properties);
40+
}
3741
}
3842
}
3943

0 commit comments

Comments
 (0)