Skip to content

Commit 2e5fd5e

Browse files
committed
Unify library config with captureCodeAttributes and smart verification
- Add captureCodeAttributes="true" to library/log4j2.xml - Remove override from library Log4j2Test, use base class method - Base class addCodeLocationAttributes() handles all scenarios: * Returns empty for AsyncLogger + older Log4j2 versions * Returns code location attributes otherwise - All tests pass (library and AsyncLogger)
1 parent 887837e commit 2e5fd5e

File tree

5 files changed

+347505
-18
lines changed

5 files changed

+347505
-18
lines changed

instrumentation/log4j/log4j-appender-2.17/library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/Log4j2Test.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
99
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
10-
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
11-
import java.util.ArrayList;
12-
import java.util.List;
1310
import org.junit.jupiter.api.AfterAll;
1411
import org.junit.jupiter.api.BeforeEach;
1512
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -33,18 +30,4 @@ static void cleanup() {
3330
protected InstrumentationExtension testing() {
3431
return testing;
3532
}
36-
37-
@Override
38-
protected List<AttributeAssertion> addCodeLocationAttributes(String methodName) {
39-
// Library test configuration doesn't have captureCodeAttributes="true"
40-
// so code location attributes should not be captured
41-
String selector = System.getProperty("Log4j2.contextSelector");
42-
boolean async = selector != null && selector.endsWith("AsyncLoggerContextSelector");
43-
if (async && !Boolean.getBoolean("testLatestDeps")) {
44-
// source info is not available by default when async logger is used in non latest dep tests
45-
return new ArrayList<>();
46-
}
47-
// For library tests without captureCodeAttributes, don't expect code location
48-
return new ArrayList<>();
49-
}
5033
}

instrumentation/log4j/log4j-appender-2.17/library/src/test/resources/log4j2.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{trace_id} spanId: %X{span_id} flags: %X{trace_flags} - %msg%n"/>
77
</Console>
88
<!-- TODO run tests both with and without experimental log attributes -->
9-
<OpenTelemetry name="OpenTelemetryAppender" numLogsCapturedBeforeOtelInstall="1" captureMapMessageAttributes="true" captureMarkerAttribute="true" captureContextDataAttributes="key1,key2" captureExperimentalAttributes="true" captureCodeAttributes="true"/>
9+
<OpenTelemetry name="OpenTelemetryAppender" numLogsCapturedBeforeOtelInstall="1" captureCodeAttributes="true" captureMapMessageAttributes="true" captureMarkerAttribute="true" captureContextDataAttributes="key1,key2" captureExperimentalAttributes="true"/>
1010
</Appenders>
1111
<Loggers>
1212
<Logger name="TestLogger" level="All">

0 commit comments

Comments
 (0)