Ops AI Java APM Configuration
Use the Middleware Java Agent (version 1.7.0 or higher) to provide Ops AI with rich, code-aware visibility into your Java services. The agent automatically captures exceptions, stack traces, and function bodies, and recognizes library files to provide cleaner signals, allowing Ops AI to analyze issues and suggest fixes with accurate context.
What you get
- Automatic error capture: exceptions + messages, stack traces with line numbers.
- Code context: function names and bodies, file paths and ranges, with library-file detection (Maven/Gradle caches, classpath JARs, etc.).
- Git awareness: auto-detects commit SHA and repo URL when a .git directory is present; simple env vars when it isn’t.
Step 1: Download the Middleware Java Agent
Get the latest JAR from the GitHub Release Page (ensure 1.7.0+ for Ops AI support). Store it in a path accessible to your runtime user.
Step 2: Run your Java Application with the Agent
Add -javaagent:<path-to-agent-jar> before your -jar argument, and provide your API key and service name. This attaches the agent at JVM startup, allowing it to instrument your app from the first classes that load.
1MW_API_KEY=<MW_API_KEY> \
2java -javaagent:<PATH-OF-MIDDLEWARE-JAVA-AGENT-JAR> \
3 -Dotel.service.name=<YOUR-SERVICE-NAME> \
4 -jar <YOUR-APP-JAR-FILE>.jarNotes on the flags
-javaagent:points to the full path of the Middleware agent JAR you downloaded.MW_API_KEYauthenticates your telemetry with Middleware.-Dotel.service.namesets the service identity you’ll use in the APM UI.
Exception Code Capturing (what’s collected)
The SDK automatically captures:
- Exception types and messages
- Stack traces with line numbers
- Function names and bodies
- File paths and line ranges
- Library file detection (for files in
~/.m2/repository/,~/.gradle/caches/,lib/,libs/, JAR files in classpath, and External JARs, Maven/Gradle dependencies ).
Source Control Metadata (auto vs manual)
- Automatic detection: If your service runs from a Git checkout, the agent automatically reads the commit SHA and repo URL. Nothing extra to configure.
- Manual configuration: If your build doesn’t include .git (e.g., container images), set the following environment variables so Ops AI can link incidents to the correct code version:
1MW_VCS_COMMIT_SHA=$(git rev-parse HEAD)
2MW_VCS_REPOSITORY_URL=$(git config --get remote.origin.url)Providing these ensures Middleware knows exactly which version is running, which helps Ops AI suggest the correct fix (and create a solution PR) against the correct code.
Turning Ops AI off (if you need to)
Ops AI support is on by default for the Java agent. To disable it, set MW_OPSAI_SUPPORT=false alongside your startup command:
1MW_OPSAI_SUPPORT=false \ # Here
2MW_API_KEY=<MW_API_KEY> \
3 java -javaagent:<PATH-OF-MIDDLEWARE-JAVA-AGENT-JAR> \
4 -Dotel.service.name=<YOUR-SERVICE-NAME> \
5 -jar <YOUR-APP-JAR-FILE>.jarValidate & Troubleshoot
- Agent attached? The
-javaagentflag must appear before-jar. If the service starts but no data appears, re-check the agent path and order. - Service not visible? Verify
MW_API_KEYis present and-Dotel.service.nameis set to the name you expect to filter on. - Commit mapping missing? If the UI lacks code/commit context, ensure the app runs from a Git checkout. Alternatively, export the two VCS environment variables during deployment.
- Need to pause Ops AI behavior? Use
MW_OPSAI_SUPPORT=falseas shown above.
Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.