Disclaimer: This SDK is currently in beta and still work in progress.
This SDK allows Dynatrace customers to instrument java applications. This is useful to enhance the visibility for proprietary frameworks or custom frameworks not directly supported by Dynatrace OneAgent out-of-the-box.
This is the official Java implementation of the Dynatrace OneAgent SDK.
- Package contents
- Requirements
- Integration
- API Concepts
- Features
- Further reading
- Help & Support
- Release notes
samples
: contains sample application, which demonstrates the usage of the SDK. see readme inside the samples directory for more detailsdocs
: contains the reference documentation (javadoc). The most recent version is also available online at https://dynatrace.github.io/OneAgent-SDK-for-Java/.LICENSE
: license under which the whole SDK and sample applications are published
- JRE 1.6 or higher
- Dynatrace OneAgent (required versions see below)
OneAgent SDK for Java | Required OneAgent version |
---|---|
1.4.0 | >=1.151 |
1.3.0 | >=1.149 |
1.2.0 | >=1.147 |
1.1.0 | >=1.143 |
1.0.3 | >=1.135 |
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.4.0</version>
<scope>compile</scope>
</dependency>
If you prefer to integrate the SDK using plain jar file, just download them from mavenCentral. You can find the download links for each version in the Release notes section.
The Dynatrace OneAgent SDK for Java has no further dependencies.
If the SDK can't connect to the OneAgent (see usage of SDKState in samples) or you you don't see the desired result in the Dynatrace UI, you can set the following system property to print debug information to standard out:
-Dcom.dynatrace.oneagent.sdk.debug=true
Additionally you should/have to ensure, that you have set a LoggingCallback
. For usage see class StdErrLoggingCallback
in remotecall-server
module (in samples/remotecall folder).
Common concepts of the Dynatrace OneAgent SDK are explained the Dynatrace OneAgent SDK repository.
Use OneAgentSDKFactory.createInstance() to obtain an OneAgentSDK instance. You should reuse this object over the whole application and if possible JVM lifetime:
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
switch (oneAgentSdk.getCurrentState()) {
case ACTIVE:
break;
case PERMANENTLY_INACTIVE:
break;
case TEMPORARILY_INACTIVE:
break;
default:
break;
}
It is good practice to check the SDK state regularly as it may change at every point of time (except PERMANENTLY_INACTIVE never changes over JVM lifetime).
To trace any kind of call you first need to create a Tracer. The Tracer object represents the logical and physical endpoint that you want to call. A Tracer serves two purposes. First to time the call (duraction, cpu and more) and report errors. That is why each Tracer has these three methods. The error method must be called only once, and it must be in between start and end.
void start();
void error(String message);
void end();
The second purpose of a Tracer is to allow tracing across process boundaries. To achieve that these kind of traces supply so called tags. Tags are strings or byte arrays that enable Dynatrace to trace a transaction end to end. As such the tag is the one information that you need to transport across these calls yourselfs.
The feature sets differ slightly with each language implementation. More functionality will be added over time, see Planned features for OneAgent SDK for details on upcoming features.
A more detailed specification of the features can be found in Dynatrace OneAgent SDK.
Feature | Required OneAgent SDK for Java version |
---|---|
Outgoing webrequests | >=1.4.0 |
Incoming webrequests | >=1.3.0 |
Custom request attributes | >=1.2.0 |
In process linking | >=1.1.0 |
Trace incoming and outgoing remote calls | >=1.0.3 |
You can use the SDK to trace proprietary IPC communication from one process to the other. This will enable you to see full Service Flow, PurePath and Smartscape topology for remoting technologies that Dynatrace is not aware of.
To trace any kind of remote call you first need to create a Tracer. The Tracer object represents the endpoint that you want to call, as such you need to supply the name of the remote service and remote method. In addition you need to transport the tag in your remote call to the server side if you want to trace it end to end.
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 to server
} catch (Throwable e) {
outgoingRemoteCall.error(e);
} finally {
outgoingRemoteCall.end();
}
On the server side you need to wrap the handling and processing of your remote call as well. This will not only trace the server side call and everything that happens, it will also connect it to the calling side.
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
IncomingRemoteCallTracer incomingRemoteCall = oneAgentSdk.traceIncomingRemoteCall("remoteMethodToCall", "RemoteServiceName", "rmi://Endpoint/service");
incomingRemoteCall.setDynatraceStringTag(tag);
incomingRemoteCall.start();
try {
incomingRemoteCall.setProtocolName("RMI/custom");
doSomeWork(); // process the remoteCall
} catch (Exception e) {
incomingRemoteCall.error(e);
// rethrow or add your exception handling
} finally{
incomingRemoteCall.end();
}
You can use the SDK to link inside a single process. To link for eg. an asynchronous execution, you need the following code:
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
InProcessLink inProcessLink = sdk.createInProcessLink();
Provide the returned inProcessLink to the code, that does the asynchronous execution:
OneAgentSDK sdk = OneAgentSDKFactory.createInstance();
InProcessLinkTracer inProcessLinkTracer = sdk.traceInProcessLink(inProcessLink);
inProcessLinkTracer.start();
try {
// do the work ...
} catch (Exception e) {
inProcessLinkTracer.error(e);
// rethrow or add your exception handling
} finally {
inProcessLinkTracer.end();
}
You can use the SDK to add custom request attributes to the current traced service. Custom request attributes allow you to do advanced filtering of your requests in Dynatrace.
Adding custom request attributes to the currently traced service call is simple. Just call one of the addCustomRequestAttribute methods with your key and value:
oneAgentSDK.addCustomRequestAttribute("region", "EMEA");
oneAgentSDK.addCustomRequestAttribute("salesAmount", 2500);
When no service call is being traced, the custom request attributes are dropped.
You can use the SDK to trace incoming web requests. This might be useful if Dynatrace does not support the respective web server framework or language processing the incoming web requests.
To trace an incoming web request you first need to create a WebServerInfo object. The info object represents the endpoint of your web server (web server name, application name and context root). This object should be reused for all traced web requests within for the same application.
WebServerInfo wsInfo = OneAgentSDK.createWebServerInfo("WebShopProduction", "CheckoutService", "/api/service/checkout");
To trace a specific incoming web request you then need to create a Tracer object. Make sure you provide all http headers from the request to the SDK by calling addRequestHeader(...). This ensures that tagging with our built-in sensor is working.
IncomingWebRequestTracer tracer = OneAgentSDK.traceIncomingWebRequest(wsInfo,"https://www.oursupershop.com/api/service/checkout/save","POST")
for (Entry<String, String> headerField : httpRequest.getHeaders().entrySet()) {
incomingWebrequestTracer.addRequestHeader(headerField.getKey(), headerField.getValue());
}
for (Entry<String, List<String>> parameterEntry : httpRequest.getParameters().entrySet()) {
for (String value : parameterEntry.getValue()) {
incomingWebrequestTracer.addParameter(parameterEntry.getKey(), value);
}
}
incomingWebrequestTracer.setRemoteAddress(httpRequest.getRemoteHostName());
tracer.start();
try {
int statusCodeReturnedToClient = processWebRequest();
tracer.setStatusCode(statusCodeReturnedToClient);
} catch (Exception e) {
tracer.setStatusCode(500); // we expect, the container sends http 500 in case request processing throws an exception
tracer.error(e);
throw e;
} finally {
tracer.end();
}
You can use the SDK to trace outgoing web requests. This might be useful if Dynatrace does not support the respective http library or language.
To trace a outgoing web request you need to create a Tracer object. It is important to send the Dynatrace Header. This ensures that tagging with our built-in sensor is working.
OutgoingWebRequestTracer outgoingWebRequestTracer = oneAgentSdk.traceOutgoingWebRequest(url, "GET");
outgoingWebRequestTracer.start();
try {
yourHttpClient.setUrl(url);
// sending HTTP header OneAgentSDK.DYNATRACE_HTTP_HEADERNAME is necessary for tagging:
yourHttpClient.addRequestHeader(OneAgentSDK.DYNATRACE_HTTP_HEADERNAME, outgoingWebRequestTracer.getDynatraceStringTag());
// provide all request headers to outgoingWebRequestTracer (optional):
for (Entry<String, String> entry : yourHttpClient.getRequestHeaders().entrySet()) {
outgoingWebRequestTracer.addRequestHeader(entry.getKey(), entry.getValue());
}
yourHttpClient.processHttpRequest();
for (Entry<String, List<String>> entry : yourHttpClient.getHeaderFields().entrySet()) {
for (String value : entry.getValue()) {
outgoingWebRequestTracer.addResponseHeader(entry.getKey(), value);
}
}
outgoingWebRequestTracer.setStatusCode(yourHttpClient.getResponseCode());
} catch (Exception e) {
outgoingWebRequestTracer.error(e);
} finally {
outgoingWebRequestTracer.end();
}
- What is the OneAgent SDK? in the Dynatrace documentation
- Feedback & Roadmap thread in AnswerHub
- Blog: Dynatrace OneAgent SDK for Java: End-to-end monitoring for proprietary Java frameworks
The Dynatrace OneAgent SDK for Java is an open source project, currently in beta status. The features are fully supported by Dynatrace.
Get Help
- Ask a question in the product forums
- Read the product documentation
Open a GitHub issue to:
- Report minor defects, minor items or typos
- Ask for improvements or changes in the SDK API
- Ask any questions related to the community effort
SLAs don't apply for GitHub tickets
Customers can open a ticket on the Dynatrace support portal to:
- Get support from the Dynatrace technical support engineering team
- Manage and resolve product related technical issues
SLAs apply according to the customer's support level.
see also https://github.com/Dynatrace/OneAgent-SDK-for-Java/releases
Version | Description | Links |
---|---|---|
1.4.0 | Added support for outgoing webrequests | binary source javadoc |
1.3.0 | Added support for incoming webrequests | binary source javadoc |
1.2.0 | Added support for in-process-linking | binary source javadoc |
1.1.0 | Added support for in-process-linking | binary source javadoc |
1.0.3 | Initial release | binary source javadoc |