Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 30, 2025

Plan: Unify tests between log4j-appender-2.17 javaagent and library instrumentation

Based on my analysis of the repository structure and the issue requirements, I will:

  • Create a testing module under instrumentation/log4j/log4j-appender-2.17/
  • Extract common test code from both javaagent and library tests into the testing module
  • Create a base test class that both javaagent and library tests can extend
  • Update javaagent tests to extend the base test class
  • Add new library test that extends the base test class
  • Remove duplicative tests from AbstractOpenTelemetryAppenderTest
  • Add the testing module as a test dependency to both javaagent and library modules
  • Register the testing module in settings.gradle.kts
  • Fix library test configuration to match javaagent behavior (log level, logger config)
  • Update test assertions to be flexible for both javaagent and library implementations
  • Refactor addCodeLocationAttributes to only handle code location attributes
  • Remove unnecessary dependencies (auto-value, explicit log4j-api)
  • Optimize log4j-core dependency scope (compileOnly vs api)

Summary

Successfully created a unified testing module for log4j-appender-2.17 that contains shared test code (AbstractLog4j2Test) which both javaagent and library instrumentation can extend. This follows the pattern used by other instrumentations in the repository (e.g., jsf-jakarta-common).

Key Changes:

  1. New testing module with shared AbstractLog4j2Test base class containing common tests
  2. Simplified javaagent test - now just extends the base class
  3. New library test - extends the base class to run the same tests
  4. Removed duplicative tests - AbstractOpenTelemetryAppenderTest now contains only library-specific tests (initializeWithBuilder), while common tests (logContextData, logStringMapMessage, etc.) are unified in AbstractLog4j2Test
  5. Updated log4j2.xml - configured "abc" logger to match test expectations (kept TestLogger for remaining library-specific tests)
  6. Flexible assertions - handles differences between javaagent and library (async logging, code attributes)
  7. Proper separation of concerns - addCodeLocationAttributes only handles code location, thread and test-specific attributes added separately
  8. Minimal dependencies - removed unnecessary auto-value and explicit log4j-api dependencies, optimized log4j-core to compileOnly

Both javaagent and library now share the same test suite, significantly reducing code duplication and ensuring consistent behavior. Library-specific tests (builder API, log replay, span propagation) remain in their respective test classes.

Fixes #4956

Original prompt

This section details on the original issue you should resolve

<issue_title>Unify tests between log4j-appender-2.16 javaagent and library instrumentation</issue_title>
<issue_description>Need to introduce testing module and have single (base) test for both javaagent and library instrumentation.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #4956

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Unify tests between log4j-appender-2.16 javaagent and library instrumentation Unify tests between log4j-appender-2.17 javaagent and library instrumentation Sep 30, 2025
Copilot finished work on behalf of trask September 30, 2025 19:16
@Copilot Copilot AI requested a review from trask September 30, 2025 19:16
@Copilot Copilot AI requested a review from trask September 30, 2025 19:36
Copilot finished work on behalf of trask September 30, 2025 19:36
@Copilot Copilot AI requested a review from trask September 30, 2025 20:31
Copilot finished work on behalf of trask September 30, 2025 20:31
Copilot finished work on behalf of trask September 30, 2025 20:44
Copilot finished work on behalf of trask September 30, 2025 21:04
Copilot finished work on behalf of trask September 30, 2025 21:11
@otelbot-java-instrumentation
Copy link
Contributor

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

@trask
Copy link
Member

trask commented Oct 3, 2025

superseded by #14859

@trask trask closed this Oct 3, 2025
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