Skip to content

Conversation

trask
Copy link
Member

@trask trask commented Oct 1, 2025

Resolves #4956

@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests were moved to the shared testing base class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests were mostly redundant with the javaagent tests which were moved to the new shared base class

}

@Test
void logWithSpan() { // Does not work for log replay, but it is not likely to occur because
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant with the new shared base class tests

<OpenTelemetry name="OpenTelemetryAppender" numLogsCapturedBeforeOtelInstall="1" captureMapMessageAttributes="true" captureMarkerAttribute="true" captureContextDataAttributes="key1,key2" captureExperimentalAttributes="true" captureCodeAttributes="true"/>
</Appenders>
<Loggers>
<Logger name="TestLogger" level="All">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestLogger is still used by library tests which were not redundant with common tests

trask added 6 commits October 2, 2025 08:27
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.
…odeAttributes

Changed addCodeLocationAttributes() from static to instance method to enable
overriding in subclasses. Library tests now override this method to return
empty list since the log4j2.xml configuration lacks captureCodeAttributes.

The async logger condition is preserved in both base implementation and
override to maintain consistency across all test scenarios.
- 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)
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)
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

@trask trask force-pushed the unify-log4j2-appender-tests branch from 679f376 to 5b21e7f Compare October 3, 2025 02:30
…a/io/opentelemetry/instrumentation/log4j/appender/v2_17/AbstractLog4j2Test.java
@trask trask marked this pull request as ready for review October 3, 2025 03:13
@trask trask requested a review from a team as a code owner October 3, 2025 03:13
}

protected static List<AttributeAssertion> threadAttributesAssertions() {
return Arrays.asList(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do static imports for asList and stringKey and make all of the test methods not public

@trask trask force-pushed the unify-log4j2-appender-tests branch from 3f45b8b to e9cf224 Compare October 3, 2025 16:03
@trask trask marked this pull request as draft October 4, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify tests between log4j-appender-2.16 javaagent and library instrumentation
2 participants