cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Capturing Distributed tracing ID with OneAgentSDK for Java

PraveenYendluri
Frequent Guest

How to capture distributed tracing ID in our java programatically with OneAgentSDK. Is there any way?

3 REPLIES 3

michalOM
Helper

Hello @PraveenYendluri ,

sure you can. Check documentation oneAgentSDK for JAVA.

Dynatrace/OneAgent-SDK-for-Java: Enables custom tracing of Java applications in Dynatrace (github.co...

OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
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);
// rethrow or add your exception handling
} finally {
outgoingRemoteCall.end();
}

Best Regards

 

Thank you Michal!!

I am not sure, I got your you message. My requirement is as I pasted below can I get two values highlighted in yellow. I have seen these values in Distributed Traces. I am trying with 

TraceContextInfo t = oneAgentSdk.getTraceContextInfo();

log.info("ACTIVE Dynatrace Trace ID: " + t.getTraceId() + " & SpanId:: " + t.getSpanId());

But I am getting 000000000000 values for both trace id and span id.

 

Bottom Line is I need to get W3C trace ID. Ex: 522dede9e76d809281cd7cdb969934a7

 

PraveenYendluri_0-1729038447803.png

Coming to your code, method oneAgentSdk.traceOutgoingRemoteCall is taking 5 parameters 

String serviceMethod, String serviceName, String serviceEndpoint, ChannelType channelType, String channelEndpoint
 
How do I get these values ? Please advise me.
 
Thank you Praveen
 

 

Dear @PraveenYendluri,

 

I hard to say why you have 00000000 instead of actual values. Probably you make systematical error somewhere. Make sure that you are using OneAgentSDK in right place(function which is actually monitored by DT) and OneAgent is up and running. 

oneAgentSdk.traceOutgoingRemoteCall is a method to extend normal visibility of Dynatrace. If your method is not monitored by Dynatrace you can use it  and have extra node in PurePath.

Parameters of this function is basically how wish to see trace in Dynatrace. That mean you can choose whatever value you wish(there are limitation, but in principle):

michalOM_1-1729065092537.png

Best Regards

Michał

 

Featured Posts