File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed
instrumentation/log4j/log4j-appender-2.17
library/src/test/java/io/opentelemetry/instrumentation/log4j/appender/v2_17
testing/src/main/java/io/opentelemetry/instrumentation/log4j/appender/v2_17 Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change 77
88import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
99import io .opentelemetry .instrumentation .testing .junit .LibraryInstrumentationExtension ;
10+ import io .opentelemetry .sdk .testing .assertj .AttributeAssertion ;
11+ import java .util .ArrayList ;
12+ import java .util .List ;
1013import org .junit .jupiter .api .AfterAll ;
1114import org .junit .jupiter .api .BeforeEach ;
1215import 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}
Original file line number Diff line number Diff 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" ));
You can’t perform that action at this time.
0 commit comments