-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add marker attribute for Log4j 2 #6680
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import java.util.List; | ||
import javax.annotation.Nullable; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.Marker; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.message.MapMessage; | ||
import org.apache.logging.log4j.message.Message; | ||
|
@@ -35,22 +36,27 @@ public final class LogEventMapper<T> { | |
private static final Cache<String, AttributeKey<String>> mapMessageAttributeKeyCache = | ||
Cache.bounded(100); | ||
|
||
private static final AttributeKey<String> LOG_MARKER = AttributeKey.stringKey("log4j.marker"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logback has markers too -- do we want to encode library name in the attribute name? I'm worried that we'll run into a situation similar to #5765, perhaps it'd be better to avoid it right from the start and just name it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trask Do you agree with @mateuszrzeszutek? Or would it be something we would like to discuss at the next OpenTelemetry Java + Instrumentation SIG? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mateuszrzeszutek I gave contradictory advice here: #6652 (comment)
I'm not sure what the best compromise here is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we're already prefixing MDC/context data with the library name ( |
||
|
||
private final ContextDataAccessor<T> contextDataAccessor; | ||
|
||
private final boolean captureExperimentalAttributes; | ||
private final boolean captureMapMessageAttributes; | ||
private final boolean captureMarkerAttribute; | ||
private final List<String> captureContextDataAttributes; | ||
private final boolean captureAllContextDataAttributes; | ||
|
||
public LogEventMapper( | ||
ContextDataAccessor<T> contextDataAccessor, | ||
boolean captureExperimentalAttributes, | ||
boolean captureMapMessageAttributes, | ||
boolean captureMarkerAttribute, | ||
List<String> captureContextDataAttributes) { | ||
|
||
this.contextDataAccessor = contextDataAccessor; | ||
this.captureExperimentalAttributes = captureExperimentalAttributes; | ||
this.captureMapMessageAttributes = captureMapMessageAttributes; | ||
this.captureMarkerAttribute = captureMarkerAttribute; | ||
this.captureContextDataAttributes = captureContextDataAttributes; | ||
this.captureAllContextDataAttributes = | ||
captureContextDataAttributes.size() == 1 && captureContextDataAttributes.get(0).equals("*"); | ||
|
@@ -72,13 +78,21 @@ public void mapLogEvent( | |
LogRecordBuilder builder, | ||
Message message, | ||
Level level, | ||
@Nullable Marker marker, | ||
@Nullable Throwable throwable, | ||
T contextData) { | ||
|
||
AttributesBuilder attributes = Attributes.builder(); | ||
|
||
captureMessage(builder, attributes, message); | ||
|
||
if (captureMarkerAttribute) { | ||
if (marker != null) { | ||
String markerName = marker.getName(); | ||
attributes.put(LOG_MARKER, markerName); | ||
} | ||
} | ||
|
||
if (level != null) { | ||
builder.setSeverity(levelToSeverity(level)); | ||
builder.setSeverityText(level.name()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it not possible to static import here due to conflicting
assertThat
signatures and/or because groovy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried to add a static import with IntelliJ and some assertions were failing after that.😅 After, I did not go further in this refactoring on the assertions.