java-dynamic-sqs-listener icon indicating copy to clipboard operation
java-dynamic-sqs-listener copied to clipboard

New Relic's @Trace annotation above @QueueListener is not working

Open harshitshah4 opened this issue 3 years ago • 2 comments
trafficstars

I have added @Trace annotation to Spring boot's Kafka Listener , it seems to be working over there. But its not working above @QueueListener.

What's the correct way to integrate New Relic with @QueueListener.

My current implementation looks something like this

    @Trace(metricName = "metricName", dispatcher = true)
    @QueueListener(value = "${queue.name}", sqsClient = "sqsClient")
    public void processMessage(@Payload Request request) throws Exception {
        ...
    }

harshitshah4 avatar Nov 30 '21 05:11 harshitshah4

Interesting, what you are doing is correct and there must be a bug.

I have seen similar problems before with other annotations and I was able to get around it by making sure it worked with cglib and other proxying libraries with this utility: AnnotationUtils.

Let me do some digging and see what I can find.

JaidenAshmore avatar Dec 04 '21 15:12 JaidenAshmore

Okay it looks like we wouldn't get automatic integration for this, e.g. you can see that newrelic has custom integration code for each integration that they want to support: https://github.com/newrelic/newrelic-java-agent/tree/main/instrumentation.

As I don't have a lot of knowledge in NewRelic and don't actively use it myself, I probably won't work on this. I am open for anyone who has a lot more new relic knowledge to submit a PR for fixing this!

For reference, we have similar tracing implementations that wrap each message being processed in a tracing span:

  • AWS Xray: https://github.com/JaidenAshmore/java-dynamic-sqs-listener/tree/5.x/extensions/aws-xray-extension
  • Brave: https://github.com/JaidenAshmore/java-dynamic-sqs-listener/tree/5.x/extensions/brave-extension

It looks like new relic does it a little bit different using Weave* annotations: https://github.com/newrelic/newrelic-java-agent/blob/main/instrumentation/spring-4.3.0/src/main/java/com/nr/agent/instrumentation/SpringController_Instrumentation.java#L33. Maybe we would just need to weave the core annotations like @SqsListener and that would be it? The negative of this approach is that this doesn't work if people add their own annotations for a custom message listener. Implementing a custom MessageProcessingDecorator in that sense would be more extensible but not sure how to do it with the new relic without really digging into their code.

Sorry I couldn't be more help :(

JaidenAshmore avatar Dec 04 '21 17:12 JaidenAshmore