This document explains how AppMap's remote recording feature integrates with a Tomcat application and provides a guide to troubleshooting common issues.
AppMap's remote recording functionality is enabled by a Java agent that instruments your application at runtime. When used with a Tomcat application, the agent injects a javax.servlet.Filter named RemoteRecordingFilter into the application's filter chain. This filter is responsible for intercepting and handling HTTP requests related to remote recording.
Here's a step-by-step breakdown of the process:
- Java Agent Attachment: The AppMap Java agent is attached to the Tomcat JVM using the
-javaagentflag. - Instrumentation: The agent instruments the
javax.servlet.ServletContextclass to inject theRemoteRecordingFilterinto the application's filter chain. This is done dynamically at runtime. - Request Interception: The
RemoteRecordingFilterintercepts all incoming HTTP requests to the application. - Request Handling: The filter checks if the request URI matches the AppMap remote recording endpoints (
/_appmap/recordand/_appmap/record/checkpoint).- If the request is for a remote recording endpoint, the filter handles the request by calling the
RemoteRecordingManager. TheRemoteRecordingManageris responsible for starting, stopping, and managing recording sessions. - If the request is not for a remote recording endpoint, the filter passes the request on to the next filter in the chain, and eventually to the application.
- If the request is for a remote recording endpoint, the filter handles the request by calling the
This approach allows AppMap to control recording sessions without requiring any changes to the application's source code.
Here are some common reasons why remote recording might fail to work for a specific application, and how to troubleshoot them:
- Symptom: Remote recording endpoints are not available (e.g., return a 404 error).
- Troubleshooting:
- Ensure that the
-javaagentflag is correctly configured in your Tomcat startup script. The flag should point to the location of the AppMap agent JAR file. - Check the Tomcat logs for any errors related to the AppMap agent.
- Ensure that the
- Symptom: The
RemoteRecordingFilteris not injected into the filter chain. - Troubleshooting:
- Ensure that you are using a supported version of Tomcat and the Servlet API.
- Check for any class loading issues in your application. If your application uses a complex class loader hierarchy, it's possible that the agent is unable to correctly instrument the
ServletContext.
- Symptom: Requests to the remote recording endpoints are being handled by your application instead of the AppMap agent.
- Troubleshooting:
- Ensure that your application does not have any servlets or controllers that are mapped to the
/_appmap/recordor/_appmap/record/checkpointURLs.
- Ensure that your application does not have any servlets or controllers that are mapped to the
- Symptom: The
RemoteRecordingFilteris unable to process requests due to incompatible request or response objects. - Troubleshooting:
- If your application uses custom
HttpServletRequestorHttpServletResponsewrappers, they may not be compatible with the AppMap agent. The agent uses reflection to interact with these objects, and may not be able to handle custom implementations.
- If your application uses custom
- Symptom: A security framework (e.g., Spring Security) is blocking requests to the remote recording endpoints.
- Troubleshooting:
- Configure your security framework to allow anonymous access to the
/_appmap/recordand/_appmap/record/checkpointURLs.
- Configure your security framework to allow anonymous access to the
- Symptom: Another filter in the filter chain is interfering with the
RemoteRecordingFilter. - Troubleshooting:
- Try changing the order of the filters in your
web.xmlfile to ensure that theRemoteRecordingFilteris executed before any other filters that might interfere with it. TheRemoteRecordingFilteris designed to have the highest precedence, but this can be overridden by other filters.
- Try changing the order of the filters in your