Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Created April 8, 2016 21:12
Show Gist options
  • Save adam-hert/ef58432d20327689305391af0d798390 to your computer and use it in GitHub Desktop.
Save adam-hert/ef58432d20327689305391af0d798390 to your computer and use it in GitHub Desktop.
Instrument a non-servlet java application
/**
* 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.
//End the Trace
Trace.endTrace("Hello Trace POJO");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment