Skip to content

Conversation

Copy link

Copilot AI commented Jul 19, 2025

This PR removes unused code from the ApplicationInsights-Java repository, specifically addressing duplicate code that was marked with a TODO comment for removal.

Changes Made

1. Removed Duplicate Sampling Logic

  • File: agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java
  • Issue: Lines 178-182 contained duplicate sampling percentage logic that was also present in RuntimeConfigurator.updateSampling()
  • Fix: Removed the duplicate code block and corresponding TODO comment
// REMOVED: Duplicate logic that was also in RuntimeConfigurator.updateSampling()
if (configuration.sampling.percentage != null) {
  BytecodeUtilImpl.samplingPercentage = configuration.sampling.percentage.floatValue();
} else {
  BytecodeUtilImpl.samplingPercentage = 100;
}

The RuntimeConfigurator.updateSampling() method is called later in the initialization flow and properly handles setting the sampling percentage, making this duplication unnecessary.

2. Improved Build Configuration

  • File: .gitignore
  • Added: /buildSrc/.kotlin/ to prevent Kotlin build artifacts from being committed
  • Removed: Accidentally committed build error log file (buildSrc/.kotlin/errors/errors-1752940067370.log)

Validation

  • ✅ All code compiles successfully
  • ✅ Style checks (Spotless) pass
  • ✅ Build process completes without errors
  • ✅ Changes are minimal and surgical (only 7 lines changed total)
  • ✅ No functionality impacted - the same sampling logic executes via RuntimeConfigurator.updateSampling()

Analysis

After comprehensive analysis of the codebase, this duplicate sampling percentage logic was the clear case of unused code that could be safely eliminated. Other potential candidates (like ETW test applications, @SuppressWarnings classes, etc.) represent legitimate architectural decisions rather than genuinely unused code.

Fixes #78.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Remove unused code Remove unused duplicate code and improve build configuration Jul 19, 2025
Copilot AI requested a review from trask July 19, 2025 16:09
Copilot finished work on behalf of trask July 19, 2025 16:09
Copilot AI requested a review from trask July 19, 2025 16:13
Copilot finished work on behalf of trask July 19, 2025 16:13
@trask trask marked this pull request as ready for review July 19, 2025 16:27
@trask trask merged commit eccfa1a into main Jul 19, 2025
135 of 140 checks passed
trask added a commit that referenced this pull request Jul 21, 2025
* Initial plan

* Initial analysis of repository for unused code identification

Co-authored-by: trask <[email protected]>

* Remove duplicate sampling percentage logic from SecondEntryPoint

Co-authored-by: trask <[email protected]>

* Add Kotlin build artifacts to .gitignore and remove committed build artifact

Co-authored-by: trask <[email protected]>

* Revert .gitignore changes as requested

Co-authored-by: trask <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: trask <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
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.

Remove unused code

2 participants