Skip to content

Commit 3523c95

Browse files
committed
Restore async logger condition in Log4j2 tests
The async logger condition was removed in the previous commit which caused testAsyncLogger to fail. AsyncLogger doesn't capture source location attributes by default in non-latest dependency tests, so this check is needed to return empty code location attributes in that case.
1 parent b4a73bf commit 3523c95

File tree

1 file changed

+11
-5
lines changed
  • instrumentation/log4j/log4j-appender-2.17/testing/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17

1 file changed

+11
-5
lines changed

instrumentation/log4j/log4j-appender-2.17/testing/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17/AbstractLog4j2Test.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,17 @@ protected static void performLogging(
266266
}
267267

268268
protected static List<AttributeAssertion> addCodeLocationAttributes(String methodName) {
269-
// Code attributes are enabled in both javaagent and library test configurations
270-
List<AttributeAssertion> assertions = new ArrayList<>();
271-
assertions.addAll(codeFunctionAssertions(AbstractLog4j2Test.class, methodName));
272-
assertions.addAll(codeFileAndLineAssertions("AbstractLog4j2Test.java"));
273-
return assertions;
269+
String selector = System.getProperty("Log4j2.contextSelector");
270+
boolean async = selector != null && selector.endsWith("AsyncLoggerContextSelector");
271+
if (async && !Boolean.getBoolean("testLatestDeps")) {
272+
// source info is not available by default when async logger is used in non latest dep tests
273+
return new ArrayList<>();
274+
}
275+
276+
List<AttributeAssertion> result = new ArrayList<>();
277+
result.addAll(codeFunctionAssertions(AbstractLog4j2Test.class, methodName));
278+
result.addAll(codeFileAndLineAssertions("AbstractLog4j2Test.java"));
279+
return result;
274280
}
275281

276282
@FunctionalInterface

0 commit comments

Comments
 (0)