Skip to main content

Jetty

This guide explains how to instrument a Java application developed on Jetty server selecting Linux agent or Windows agent for trace ingestion.

Prerequisites

  • The Motadata Agent must be installed and running on the server where the Jetty-based application is deployed. Also, the otelcol should be running as part of the Motadata Agent. To check the agent status open a Linux terminal and run the below command:
service motadata-agent status
info

If the agent is not running, restart it using the below command:

service motadata-agent stop
service motadata-agent start
  • Java Version Must Be 8 or Higher. To check the version you can use the below command:
java -version
  • The Jetty installation directory (i.e. JETTY_HOME, JETTY_BASE) is available.
  • Required permissions to edit Jetty startup scripts or configuration files and restart Jetty.
  • Ensure the method used to start Jetty such as:
    • jetty.sh startup script, or
    • start.ini configuration file
  • Application should be developed on Jetty Framework version 9.x to 12.x.
info

You can verify the Jetty version by checking the VERSION.txt file available in the Jetty installation directory.

Configuration Steps

Step1: Register the Application Service in Motadata AIOps

Go to Menu > Settings > APM > Application Registration. Clicking the Application Registration button, you can register a new application.

From the application registration screen, select the instrumentation type Host/VM or Docker.

Java Trace Configuration

FieldDescription
Select AgentSelect the Host/VM where this application is running. You can configure Java application service for both Windows and Linux type agent.
elect LanguageSelect Java from the language icons.
Service NameProvide a unique and meaningful name (e.g., ERP).
Application PathSpecify the full path to the executable JAR file used to start the application. Ensure the path ends with .jar. (e.g home/motadata/app.jar)

Providing these details displays Setup Command to instrument your Java application. Add the following argument to your java -jar command and restart the service to collect Traces.

Step2: Configure Jetty for Instrumentation

Jetty instrumentation can be done using different methods. Follow the instructions based on how Jetty is started in your environment using CLI.

Jetty Started Using jetty.sh

Locate jetty.sh

Find the Jetty startup script at one of the following locations:

<JETTY_HOME>/bin/jetty.sh

Replace the <JETTY_HOME> with your directory path.

for example, your directory is installed at /usr/local/jetty/ path then,

/usr/local/jetty/bin/jetty.sh

Stop Jetty

Use the below command to stop Jetty:

<JETTY_HOME>/bin/jetty.sh stop

Replace the <JETTY_HOME> with your directory path.

Modify jetty.sh

To modify, first navigate to the directory:

cd <JETTY_HOME>/bin

Open the file:

vi jetty.sh
info

You can use nano if preferred in your organization.

Then, add the following lines near the section where JAVA_OPTIONS is defined:

JAVA_OPTIONS="${JAVA_OPTIONS} \
-javaagent:/motadata/motadata/instrumentation/agents/java/motadata-javaagent.jar
-Dotel.javaagent.configuration-file=/motadata/motadata/config/<ServiceName>.properties

Replace the <ServiceName> part with the exact service name, you have registered in Motadata AIOps.

Alternatively, you can paste the command snippet copied from the Instrumenting Java Application card. Ensure while pasting, your snippet starts with -javaagent: and includes everything up to .properties".

Now, you can Save the file and exit from the editor.

note

Make sure to add this script near JAVA_OPTIONS without affecting the existing configuration.

Start Jetty

Use the below command to start Jetty:

<JETTY_HOME>/bin/jetty.sh start

Replace the <JETTY_HOME> with your directory path.

Ensure Jetty starts successfully and the Java agent is loaded without errors.

info

You can use any other restart method that is standard for your application.

Step3: Configure Attributes and Parameters

After configuring the application, you can provide the below details:

FieldDescription
Service Attributes(Tags)Add key–value tags to your application for better filtering and organizing data in Explorer. Attribute keys must be in lowercase (for example, apm.env = prod). To add multiple Key-Value pairs you can click the add icon.
Add Custom ParametersAllows you to define custom sampling or tagging parameters for advanced use cases. These optional parameters are passed to the agent (for example, version=4).

Clicking the Apply Configuration button, the ingestion gets started.

Once the Application is Running, you need to verify the below points:

  • Confirm that the service has been registered successfully.
  • On the service registration screen, the Service Trace Collection Status should display "Running."
  • The traces will start appearing in the APM Explorer screen.