Skip to content

Commit 5b21e7f

Browse files
committed
split
1 parent 83db767 commit 5b21e7f

File tree

2 files changed

+17
-16
lines changed
  • instrumentation/log4j/log4j-appender-2.17

2 files changed

+17
-16
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
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;
1013
import org.junit.jupiter.api.AfterAll;
1114
import org.junit.jupiter.api.BeforeEach;
1215
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -30,4 +33,17 @@ static void cleanup() {
3033
protected InstrumentationExtension testing() {
3134
return testing;
3235
}
36+
37+
@Override
38+
protected List<AttributeAssertion> addCodeLocationAttributes(String methodName) {
39+
// For library tests, AsyncLogger can't capture code location in older versions
40+
String selector = System.getProperty("Log4j2.contextSelector");
41+
boolean async = selector != null && selector.endsWith("AsyncLoggerContextSelector");
42+
if (async && !Boolean.getBoolean("testLatestDeps")) {
43+
// source info is not available by default when async logger is used in non latest dep tests
44+
return new ArrayList<>();
45+
}
46+
47+
return super.addCodeLocationAttributes(methodName);
48+
}
3349
}

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,8 @@ protected static void performLogging(
266266
}
267267

268268
protected List<AttributeAssertion> addCodeLocationAttributes(String methodName) {
269-
// For javaagent tests, code location is always captured (even with AsyncLogger)
269+
// Javaagent tests always capture code location (even with AsyncLogger)
270270
// 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-
}
284-
}
285-
286271
List<AttributeAssertion> result = new ArrayList<>();
287272
result.addAll(codeFunctionAssertions(AbstractLog4j2Test.class, methodName));
288273
result.addAll(codeFileAndLineAssertions("AbstractLog4j2Test.java"));

0 commit comments

Comments
 (0)