Skip to content

Conversation

@dividedmind
Copy link
Contributor

This PR includes several improvements to the AppMap agent, focusing on logging, configuration output, and internal refactoring for better maintainability and robustness.

Key Changes:

  • Enhanced Logging and Configuration Output:

    • The agent's logging format has been standardized to yyyy-MM-dd HH:mm:ss [thread] AppMap level: message for consistency and readability.
    • The AppMapConfig.toString() method has been updated to provide a more detailed and structured output of the configuration.
    • Log levels for system properties have been adjusted from info to debug for cleaner default logs.
  • Refactored Parameter Name Resolution:

    • The logic for resolving parameter names from LocalVariableAttribute has been extracted into a new getParameterNames method within the Parameters class. This improves code clarity and maintainability.
    • The new method now correctly traverses all local variable tables as suggested by the specification and reduces log noise when debug information is unavailable.
  • Improved Instrumentation Hooks:

    • Hook.apply has been refactored to return a Set<ApplicationAction>, indicating the type of instrumentation applied (ByteBuddy or Javassist).
    • This allows the ClassFileTransformer to conditionally apply the AppMapInstrumented annotation only when ByteBuddy instrumentation is used, optimizing the process.
    • Added better error handling and logging for Javassist instrumentation failures.

These changes contribute to a more robust, debuggable, and maintainable AppMap agent.

The AppMap agent's logging has been enhanced for better readability and
detail. This includes:

- Setting a standardized log format for all messages to
  yyyy-MM-dd HH:mm:ss [thread] AppMap level: message.
- Refining the AppMapConfig toString() method to provide a more
  structured and comprehensive output of the configuration details,
  including name, config file path, and package information.
- Adjusting log levels for system properties output in Agent.java from
  info to debug, and removing a redundant stack trace in debug mode
  for cleaner logs.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the AppMap agent's internal instrumentation logic and improves logging and configuration output. The main goal is to enhance maintainability, debuggability, and code clarity while optimizing the instrumentation process.

Key changes:

  • Refactored Hook.apply() to return a Set<ApplicationAction> that indicates which instrumentation types were applied (ByteBuddy marking vs Javassist instrumentation), allowing conditional annotation of classes
  • Extracted parameter name resolution logic into a dedicated getParameterNames() method in the Parameters class with improved handling of LocalVariableTable attributes
  • Standardized logging format and adjusted log levels for cleaner output, plus improved AppMapConfig.toString() for better configuration visibility

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Hook.java Refactored apply() method to return Set<ApplicationAction>, added exception handling with suppression after first occurrence, and improved logging for instrumentation actions
ClassFileTransformer.java Updated to use new Hook.apply() return type for conditional ByteBuddy annotation application, optimizing the instrumentation process
Parameters.java Extracted parameter name resolution into getParameterNames() method, renamed clone() to freshCopy(), removed unused imports, and improved JavaDoc formatting
AppMapConfig.java Added standardized logging format configuration and replaced JSON-based toString() with a custom YAML-like formatted output
Agent.java Changed system properties logging from info to debug level for cleaner default output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The logic for extracting parameter names from `LocalVariableAttribute`
was quite complex and interleaved with the parameter value construction.
This commit extracts that logic into a new private static method
`getParameterNames` to improve readability and maintainability of the
`Parameters` constructor.

As opposed to the previous implementation, the new method traverses all
local variable tables (as the spec suggests there can be several) and
doesn't spam the logs if debug info is missing.

Additionally:
- Updated `Parameters` constructor to use the new `getParameterNames` method.
- Replaced `this.staticParameters.clone()` with
  `this.staticParameters.freshCopy()` for clarity, as it's not a deep
  clone but a copy of value types, kinds and names.
- Cleaned up unused imports and removed `clear()` method as it's not
  used and modifies the object unexpectedly.
- Made minor improvements to null checks and error handling within
  `Parameters` methods for robustness.
Refactor `Hook.apply` to return a `Set<ApplicationAction>` indicating
whether the method was marked for ByteBuddy instrumentation or
instrumented by Javassist. This allows `ClassFileTransformer` to
conditionally apply the `AppMapInstrumented` annotation only when
ByteBuddy instrumentation is actually needed.

Additionally, add improved logging for Javassist instrumentation failures
and guard against excessive logging of these exceptions.
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.

2 participants