Question

The Events : Errors tab in New Relic displays exceptions (date, time, message and stack trace) reported by my application using NewRelic.noticeError(exception). For those reported from web transactions it shows the URL of the transaction which is perfect. But for background tasks reported using @Trace annotations it displays the name of the thread. This is meaningless because the threads have names like pool-23-thread-9927.

Can I assign a display name to each background task or pass one when reporting the error so that it shows in the URL column instead of the thread's name?

Note: I would prefer not to change the name of the thread if I can avoid it.

Update

Here's the overview of code. The transaction is contained in PingJob which catches and reports the exception.

public class PingJob implements Callable<PingStatus>
{
    @Trace(metricName = "ping", dispatcher = true)
    @Override
    public PingStatus call() {
        try {
            // calls that may throw exceptions
        }
        catch (RuntimeException e) {
            // pass to utility method to log and/or report to New Relic
            ExceptionLogger.log(e, LOG);
        }
    }
}

I see the exceptions reported by ExceptionLogger on the New Relic site, but the URL column lists the name of the thread instead of the transaction, in this case ping.

Was it helpful?

Solution

Depending on what parameters you set in the @Trace annotation, you will see different values for the error URL recorded in the New Relic UI for an error in a background task.

Specifying the metricName and setting dispatcher to true, as in

@Trace(metricName = "YourErrorNameHere", dispatcher = true)

will set the displayed URL to YourErrorNameHere

Specifying no metricName but still setting dispatcher to true, as in

@Trace(dispatcher = true)

will set the displayed URL to your class name/method name, such as com.example.task.BackgroundTask/run

If you just use @Trace by itself without setting dispatcher to true, the thread name will be displayed.

We will be updating our documentation in the future to make this clearer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top