Is it possible to monitor background transactions using the Java Agent?

thairu's Avatar

thairu

10 Mar, 2010 05:32 AM via web

This FAQ covers monitoring background processes using the Ruby agent - http://support.newrelic.com/faqs/general/how-do-i-monitor-backgroun...

Is it possible to do the same with the Java Agent?

  1. Support Staff 2 Posted by Saxon D'Aubin on 10 Mar, 2010 04:33 PM

    Saxon D'Aubin's Avatar

    Hi,
    Yes, you can monitor background transactions with the Java agent using annotations. Just mark the entry method of the background task with our com.newrelic.agent.Trace annotation:

    @Trace(dispatcher=true)
    public void run() {
      // background task
    }
    

    Add this to the common section of newrelic.yml:

    enable_custom_tracing: true
    

    You'll need to include the agent jar in your compilation classpath.

    If you're using the latest agent (1.2.004.1), you can define your own trace annotation class:

    package com.test;
    
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Trace {
    public static final String NULL = "";
    String metricName() default NULL;
    boolean dispatcher() default false;
    String tracerFactoryName() default NULL;
    

    }

    Then configure the agent to use this annotation in newrelic.yml:

    class_transformer:
      trace_annotation_class_name: com.testTrace
    

    Please let me know if you need any help.

  2. 3 Posted by thairu on 12 Mar, 2010 02:39 AM

    thairu's Avatar

    Thanks. This got it working for me. Curious though - What does @Trace(dispatcher=false) do? Is that a no-op?

  3. Support Staff 4 Posted by Saxon D'Aubin on 12 Mar, 2010 05:18 PM

    Saxon D'Aubin's Avatar

    RPM displays transactions, and an individual transaction contains all of the tracer points that were touched during that transaction. We display transactions as either web transactions or background transactions. The first tracer point in a transaction must be a dispatcher. In the case of web transactions, we've built in instrumentation for the http dispatchers of common servlet containers. We've also built in some background dispatcher tracers, but anything we haven't covered can be instrumented with the @Trace(dispatcher=true) annotation.

    So, no, @Trace(dispatcher=false) is not a no-op. It's the default value for the dispatcher flag, so it's equivalent to @Trace, and it simply adds a tracer to a method to provide further breakdown of web and background transactions.

  4. 5 Posted by thairu on 12 Mar, 2010 07:44 PM

    thairu's Avatar

    Thanks!

Comments are currently closed for this discussion. You can start a new one.