Instrument Java code your way: TraceView Java API at your service!
by May 8, 2013

Filed under: Performance Monitoring

AppNeta no longer blogs on DevOps topics like this one.

Feel free to enjoy it, and check out what we can do for monitoring end user experience of the apps you use to drive your business at

When it comes to analyzing your web application’s performance, TraceView has already instruments a wide spectrum of Java components, such as application servers, frameworks and JDBC connections, all with the convenience of simply including TraceView Java agent jar in your JVM. However, have you come across situations that make you think, “It would have been nice if this was traced too”? You can do this with the TraceView Java API!

Don’t feel like coding? Just annotate it!

TraceView API

Have you seen a slowdown in your code, and have some methods you’d like to check? The simplest way is to add the @LogMethod or @ProfileMethod annotation to those methods. Invocations to those methods will then be traced by the Java agent and reflected on your TraceView panels. Since you can assign different layer/profile names for those methods, you can easily group them and gather useful statistics from your TraceView pages! (Heat map, layer/profile summary etc). You might even turn on back trace tracking or store the method return values by tweaking various optional parameters.

Need more power? Add a few lines of code!

TraceView Java Agent was built for web applications, so traces are normally triggered by web requests. However, this does not mean you are limited to tracing web applications. In fact, you can even trace stand-alone applications with TraceView Java Agent with just a couple lines of code!

For example, you may have a day-end process that perform several scheduled tasks which each run in its own separate thread, some tasks may involve database operations. Adding the 2 steps below not only measures the timing of the job, but also any of the database calls that were invoked during the task itself.

import com.tracelytics.api.ext;
// Your task class that implements Callable
public static class SampleTask implements Callable<Boolean> {
    public Boolean call() throws Exception {
        // Add this to start a trace for the task
        TraceEvent startEvent = Trace.startTrace(id);;
        // Your actual operations here...
        // Add this to end a trace
        return true;

But wait… where is the code that traces the database operations? You do not need to worry about it! In fact, once you start a Trace using the API, anything comes down the calling stack with layer recognized by TraceView Java Agent (JDBC, Apache Http Client, etc.) will be instrumented.

TraceView API 2

Try it out!

That’s it! Kick start the Java process with the TraceView Java Agent and you will start seeing traces of your custom layer on the jobs. By assigning different layer names, you can easily customize the groupings, and even handle different concurrency models by digging into the full API.

  • Krish V

    How do you handle scenarios where the code is deeply nested in for-loops? Would that cause tracing overhead? Some of the use cases have billions of iterations (example plotting a graph over voluminous data points).