Define custom Java services

Before you can create a custom Java service, ensure that your system meets the following prerequisites:

  • Dynatrace version 1.144
  • OneAgent version 1.133

How to define a custom Java service

Consider creating a custom service that is based on a particular incarnation of a component. In this example, we have created a sample service called Booking for the EasyTravel application:

  1. Select all the methods that you want to monitor.

    These methods must exist across all components. As long as the same method signature exists across all classes, you can use the base class or an interface to select these methods.

  2. Go to Settings > Server-side service monitoring > Custom service detection.

  3. Under the Java services tab, click Define Java services.

    define a custom service

    • The Monitor all subclasses of the specified class section displays the class that defines the class search scope.
    • The Annotation filter section displays the annotations that are used to match the specific implementations of the class that you are interested in.
  4. Click the Edit scope button to view the processes that are available in the process group.

  5. Select the process that contains the desired entry point.

  6. To view all the annotations that exist in that class, click Continue.

    view annotations

  7. Select one or more of the annotations provided by your custom service classes.

  8. To widen the class match, select an interface or superclass as the basis for the match.

  9. To load the inheritance of superclasses, click the Load inheritance button and expand the list of annotations.

    annotation list

    The custom service monitors the getId method in all implementations of com.dynatrace.easytravel.jpa.Base that have the javax.persistence.Entity annotation.


    The resulting request list for the new custom service looks like the following screen:

    new custom service

Therefore, instead of just looking for one specific implementation (the Booking class) or all implementations of the base class, you can just tell Dynatrace to monitor all implementations of an interface or base class that feature defined annotations. This makes it possible to use Spring controllers and similar concepts to define custom services.

Indirect matching in all superclasses

This feature looks for the specified annotations in all superclasses and interfaces. This makes indirect matching possible, where the annotation is on a base class not directly related to the interface match.

As an example, look at the following class hierarchy:

public interface component
  boolean executeService();
public abstract class BaseServiceA
public class MyServiceA extends BaseServiceA implements Component

While you can easily define a custom service based on the Component interface method executeService, you may want only those implementations that have the MyComponent annotation. To do this:

  1. Define the custom service for MyServiceA.

    Here, MyServiceA acts as a template.

  2. Edit the scope to use the Component interface and the MyComponent annotation.


Annotation matches by application

A number of frameworks rely solely on annotations. In such cases, you may not always be able to define an interface or base class. To handle such scenarios, Dynatrace gives you the ability to monitor all classes that match the annotation filter in a certain package.

The Edit scope page offers an additional option for this express purpose: Use all classes and interfaces with selected annotations and names starting with… This option is greyed out until you select an annotation.

Edit scope

Once you select an annotation, you can select the Use all classes and interfaces… option and specify a package match instead of an interface. Dynatrace then looks for any class that starts with the given string which has the selected annotations within itself or any of its superclasses and interfaces.

selected annotations

The result looks like the following screen:


With this option, you can also perform the following actions:

  • You can instrument your own Enterprise Java Beans (EJBs) using EJB annotation and your package.
  • You can instrument your own Spring controllers by using the Spring controller annotation and your package.