elastic / elastic/apm-agent-java

Improve Spring-messaging transaction names and failure recognition

Open
#2,812 1 comment 0 reactions 0 assignees View on GitHub
agent-java new-feature
Dominant language
Java
Stars
594
Forks
338
Avg merge
1d 13h
Merged PRs (30d)
25

Description

At the moment messaging transactions are fully handled by the instrumentation of the used underlying messaging technology.
This means that for example Transactions are simply named like `Receive message from Topic/Queue XY`.

Imo it would be more developer-friendly to do the naming similar to how we do it for `spring-web-mvc`: We should use the actual entry-method into the user-code as transaction name. Depending on the used messaging technology, these are bean methods annotated with `@KafkaListener`, `@JmsListener` or `@RabbitListener`.

In addition we currently are missing proper failure detection for spring message handlers. Spring catches exceptions thrown by the user-provided messagehandler, meaning that they never reach our messaging-technology instrumentation layer. It would be great to mark the transactions as failed and to record the exception when a handler throws one.

I didn't investiage further, but `org.springframework.messaging.handler.invocation.InvocableHandlerMethod#invoke` looks like it might be a good universal instrumentation point for recording the method names of handlers registered via the annotations listed above.
However, we need to take care that we do not mess up the naming when [listeners are registered programatically](https://stackoverflow.com/a/57629069).

For the failure/exception detection we should use an instrumentation point which is used for both types of handlers (annotation-based and programatically registered).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.