Skip to content

Add marker attribute for Log4j 2 - #6680

Merged
trask merged 2 commits into
open-telemetry:mainfrom
jeanbisutti:log4j2-marker
Sep 22, 2022
Merged

Add marker attribute for Log4j 2#6680
trask merged 2 commits into
open-telemetry:mainfrom
jeanbisutti:log4j2-marker

Conversation

@jeanbisutti

Copy link
Copy Markdown
Member

No description provided.

@jeanbisutti
jeanbisutti requested a review from a team September 20, 2022 14:02

@trask trask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx!

Comment on lines -61 to +64
assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE)).isEqualTo(IllegalStateException.getName())
assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE)).isEqualTo("hello")
assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE)).contains(Log4j2Test.name)
OpenTelemetryAssertions.assertThat(log.getAttributes()).containsEntry(SemanticAttributes.EXCEPTION_TYPE, IllegalStateException.getName())
OpenTelemetryAssertions.assertThat(log.getAttributes()).containsEntry(SemanticAttributes.EXCEPTION_MESSAGE, "hello")
OpenTelemetryAssertions.assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE)).contains(Log4j2Test.name)

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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.

Comment on lines -156 to +162
new LogEventMapper<>(ContextDataAccessorImpl.INSTANCE, false, true, singletonList("*"));
new LogEventMapper<>(
ContextDataAccessorImpl.INSTANCE, false, true, false, singletonList("*"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be worth introducing LogEventMapperBuilder in the future

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, same thing for Logback instrumentation.

private static final Cache<String, AttributeKey<String>> mapMessageAttributeKeyCache =
Cache.bounded(100);

private static final AttributeKey<String> LOG_MARKER = AttributeKey.stringKey("log4j.marker");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 log.marker or sth similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateuszrzeszutek I gave contradictory advice here: #6652 (comment)

so that it doesn't look like a spec'd attribute

I'm not sure what the best compromise here is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 (log4j.context_data...), so I suppose doing the same for markers is not out of place.
I guess we can merge it as it is -- we'll most likely have to rename things anyway once the log semantic conventions start to take shape.

…roovy/Log4j2Test.groovy

Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
@trask
trask merged commit 429f083 into open-telemetry:main Sep 22, 2022
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 23, 2022
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 31, 2022
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Dec 4, 2022
Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants