JaidenAshmore / java-dynamic-sqs-listener

Java SQS Listener library built to be customisable and dynamic during runtime
MIT License
50 stars 12 forks source link

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

Open harshitshah4 opened 2 years ago

harshitshah4 commented 2 years ago

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 {
        ...
    }
JaidenAshmore commented 2 years ago

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 commented 2 years ago

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:

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 :(