Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Last active November 28, 2016 23:40
Show Gist options
  • Save adam-hert/fa3ce29981e3b9dca7617046bd24c08b to your computer and use it in GitHub Desktop.
Save adam-hert/fa3ce29981e3b9dca7617046bd24c08b to your computer and use it in GitHub Desktop.
/**
* The HelloTrace class is an example of how to instrument a non-servlet java application
* simply traces "Hello World!" to standard output.
*/
//import the tracelytics-api.jar (/usr/local/tracelytics/tracelytics-api.jar)
import com.tracelytics.api.ext.*;
class HelloTrace {
public static void main(String[] args) {
//Start a trace (In a servlet, we do this automatically at the start of the request)
TraceEvent event = Trace.startTrace("Hello Trace POJO");
// Because TraceView's UI like web applications, we'll use HTTP server KV pairs to leverage the UI fully
// source: https://docs.appneta.com/extending-traceview-customizing
event.addInfo("HTTP-Host", "Localhost");
event.addInfo("URL", "Hello_Trace/POJO"); // example for if there is a specific task type you'd like to segment on
event.report();
//Do some normal java stuff
System.out.println("Hello Trace!"); // Display the string.
try {
sleep(200);
} catch(InterruptedException ex){
Thread.currentThread().interrupt();
}
//End the Trace
Trace.endTrace("Hello Trace POJO");
}
@ProfileMethod(profileName="sleep", backTrace=true, storeReturn=true)
public static void sleep(long ms) throws InterruptedException {
Thread.sleep(ms);
System.out.println("Slept");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment