-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Improve agent logging and refactor internals #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this 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 aSet<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 theParametersclass 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.
agent/src/main/java/com/appland/appmap/output/v1/Parameters.java
Outdated
Show resolved
Hide resolved
agent/src/main/java/com/appland/appmap/output/v1/Parameters.java
Outdated
Show resolved
Hide resolved
agent/src/main/java/com/appland/appmap/transform/ClassFileTransformer.java
Outdated
Show resolved
Hide resolved
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.
b7276e9 to
0cb2362
Compare
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:
yyyy-MM-dd HH:mm:ss [thread] AppMap level: messagefor consistency and readability.AppMapConfig.toString()method has been updated to provide a more detailed and structured output of the configuration.Refactored Parameter Name Resolution:
LocalVariableAttributehas been extracted into a newgetParameterNamesmethod within theParametersclass. This improves code clarity and maintainability.Improved Instrumentation Hooks:
Hook.applyhas been refactored to return aSet<ApplicationAction>, indicating the type of instrumentation applied (ByteBuddy or Javassist).ClassFileTransformerto conditionally apply theAppMapInstrumentedannotation only when ByteBuddy instrumentation is used, optimizing the process.These changes contribute to a more robust, debuggable, and maintainable AppMap agent.