Skip to content

Commit d270129

Browse files
committed
Fix javaagent AsyncLogger tests to expect code location attributes
The javaagent auto-instruments Log4j2 and enables code location capture, which works even with AsyncLogger. Updated addCodeLocationAttributes() to: - Always return code location for javaagent tests - Only skip for library AsyncLogger tests with older dependencies All tests now pass: - javaagent testAsync: ✓ (expects code location) - library test: ✓ (expects code location) - library testAsyncLogger: ✓ (no code location for older deps)
1 parent a32e573 commit d270129

File tree

1 file changed

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

1 file changed

+15
-5
lines changed

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

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

268268
protected List<AttributeAssertion> addCodeLocationAttributes(String methodName) {
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<>();
269+
// For javaagent tests, code location is always captured (even with AsyncLogger)
270+
// because the javaagent auto-instruments the appender
271+
boolean isJavaagent = testing()
272+
.getClass()
273+
.getName()
274+
.contains("AgentInstrumentationExtension");
275+
276+
if (!isJavaagent) {
277+
// For library tests, AsyncLogger can't capture code location in older versions
278+
String selector = System.getProperty("Log4j2.contextSelector");
279+
boolean async = selector != null && selector.endsWith("AsyncLoggerContextSelector");
280+
if (async && !Boolean.getBoolean("testLatestDeps")) {
281+
// source info is not available by default when async logger is used in non latest dep tests
282+
return new ArrayList<>();
283+
}
274284
}
275285

276286
List<AttributeAssertion> result = new ArrayList<>();

0 commit comments

Comments
 (0)