Dynatrace OneAgent SDK for Java: End-to-end monitoring for proprietary Java frameworks

Beginning with Dynatrace OneAgent v1.135, Dynatrace provides beta support for custom tracing in Java applications. We’re proud to announce that this valuable new functionality is made possible by the beta release of new Dynatrace OneAgent SDK.

Dynatrace OneAgent SDK for Java

To use the OneAgent SDK for Java, you’ll need access to the source code of the Java application you want to monitor. The SDK enables you to instrument your application manually. Remote call tracing is supported, and more functionality will be announced in the coming weeks.

The best way to get started is by checking out the GitHub repository. The repository includes all the necessary SDK documentation and hosts the SDK’s API documentation.

Once you’ve compiled your Java application with the OneAgent SDK for Java, you can run it through your pipeline and deploy it. Instrumentation has no performance impact on your application and remains dormant on systems where Dynatrace OneAgent is not installed.

Integrating into your application

If you want to integrate the OneAgent SDK into your application, just add the following maven dependency:

<dependency>
     <groupId>com.dynatrace.oneagent.sdk.java</groupId>
     <artifactId>oneagent-sdk</artifactId>
     <version>1.0.3</version>
     <scope>compile</scope>
    </dependency>
If you prefer to integrate the SDK using a plain JAR file, just download them from Maven Central – Dynatrace OneAgent SDK for Java. The source and Javadoc are also available there.
The Dynatrace OneAgent SDK for Java has no further dependencies.

Tracing proprietary remote calls

For detailed technical documentation, you should go to the GitHub repository, but here is an example of a simple way to trace a remote call.

On the calling side of a remote call, it looks like this:

OutgoingRemoteCallTracer outgoingRemoteCall = OneAgentSDK.traceOutgoingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service", ChannelType.TCP_IP, "remoteHost:1234");
outgoingRemoteCall.setProtocolName("RMI/custom");
outgoingRemoteCall.start();
try {
    String tag = outgoingRemoteCall.getDynatraceStringTag();
    //make the call and transport the tag across
} catch (Throwable e) {
    outgoingRemoteCall.error(e);
} finally {
    outgoingRemoteCall.end();
}

On the server side of the remote call, it looks like this:

// remote call has been received
IncomingRemoteCallTracer incomingRemoteCall = OneAgentSDK.traceIncomingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service");
incomingRemoteCall.setDynatraceStringTag(tag);
incomingRemoteCall.start();
incomingRemoteCall.setProtocolName("RMI/custom");
try {
   // start the processing of the remote call
   doSomeWork();
} catch (Exception e) {
    incomingRemoteCall.error(e);
}finally{
    incomingRemoteCall.end();
}
The important thing here is that you need to transport the tag across the wire yourself.

Automatic detection and deep monitoring

Deploy your application on any Dynatrace OneAgent monitored system, or restart if it was already running at the time of the OneAgent installation. OneAgent will automatically detect that your application was instrumented with the SDK and will start monitoring it on a request level, just as it would do normally.

All things done with the SDK are fully compatible with our OneAgent. This means you will barely notice the difference between SDK and out-of-the-box functionality in the UI after you have completed the SDK instrumentation. You will see SDK instrumented remote calls in the form of RPC service services, and they will behave as any other service, with full access to all analysis and monitoring functionality. They will also be baselined and observed by Dynatrace AI during automatic problem analysis.

This SDK is of course fully compatible with the Dynatrace OneAgent SDK for C/C++, so you can trace requests from Java to C applications.
As you can see, we have a Tomcat Java application that makes a proprietary remote call to a native program written in C++.

We used the same Service, Endpoint, and method names on the Java side and native application side. The result is an end-to-end trace for a single transaction.

When we look at the code on the Java side of the request, we see that the SDK has added an SDK node that represents the remote call, including the time and CPU it consumed there.

We will add more functionality to the Java SDK over time.

Your feedback on the OneAgent SDK for Java is most welcome. The best way for you to do this is via our GitHub repository issue tracker. You can also comment on our roadmap thread in AnswerHub.

Prerequisites and Limitations: 

  • Dynatrace OneAgent 1.135 or higher
  • Dynatrace OneAgent SDK for Java is Beta
  • Dynatrace Managed 138 or higher/ Dynatrace SaaS is supported.

Those who know me know that I'm passionate about 3 things: rock climbing, physics, and performance. I've worked in performance monitoring and optimizations in enterprise environments for the better part of the last 10 years. Now as a Product Manager I am doing my best to build those experiences into Dynatrace.

Looking for answers?

Start a new discussion or ask for help in our Q&A forum.

Go to forum