Support for getting API mapping in parameterized URLs

Elasticsearch version:
APM Server version:
APM Agent language and version:
Java - 1.16.0

Original install method (e.g. download page, yum, deb, from source, etc.) and version:
Download page

Fresh install or upgraded from other version?
Upgraded version

Is there anything special in your setup? For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
We have a path parameterized API implemented in our Springboot application:

	public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
		ModelAndView mav = new ModelAndView("owners/ownerDetails");
		Owner owner = this.owners.findById(ownerId);
		for (Pet pet : owner.getPets()) {
		return mav;

Example calls to this API are like:


We would like to group all these transactions based on the API mapping defined. For the above-mentioned example, we would like to group the APIs by /owners/{ownerId}

For example, an extra field in the 'url' section that specifies the API mapping:

'url': {
    'path': '/owners/3',
    'api_mapping': '/owners/{ownerId}',
    'full': ....

Is there any way we can implement this using the latest versions? If not, can we expect a feature like this soon?

We currently don't capture the value of these annotations, we only do that for the core JAX-RS annotations.
However, you should be able to achieve what you are looking for by setting use_path_as_transaction_name to true in combination with url_groups. Make sure you use the latter config for all those paths that contain path-parameters.
I hope this helps.

Thank you for your reply, Eyal!

This solution did not work well for us.
We tried the combination of use_path_as_transaction_name and url_groups, but we find that the transaction name follows a priority order as mentioned here:

As per my understanding, since we use a spring MVC framework, the transaction name comes from the servlet as this takes precedence over the use_path_as_transaction_name setting.

Is there a way we can override this priority order?

Ohh, right... Since use_path_as_transaction_name is an opt-in, we may need to reconsider this prioritization..
In the mean time, try setting disable_instrumentations to spring-mvc.

Spring sets a request attribute containing the Spring MVC pattern: org.springframework.web.servlet.HandlerMapping.bestMatchingPattern and org.springframework.web.servlet.HandlerMapping.pathWithinHandlerMapping. The former is not required to be supported by all HandlerMapping implementations.

You could either use a HandlerInterceptor in combination with the public API to set ElasticApm.currentTransaction().setName(handlerMappingName) or contribute out-of-the-box support for that in the agent. We already have a configuration option for JAX-RS to favor the path mapping over the class and method name (use_jaxrs_path_as_transaction_name).

This achieves what we needed, but seems like disabling the instrumentation has other consequences. The custom spans which we set did not show up in our spans list.
We are not clear on what else will be affected, so any help regarding this would be appreciated.

Setting the name with the help of Public APIs will definitely work, but we were just trying to see if this could be done with any present configuration options so there is as little disruption to the source code as possible.

Setting disable_instrumentations=spring-mvc should not influence other spans, only avoid the naming of transactions to be ControllerName#method.

Also note, that for path parameters, you'll have to set url_groups, as otherwise, you'll end up with different transaction names for each path parameter.

If you don't want to change the application code, the best way would be to contribute support for out-of-the-box support in the agent by modifying SpringTransactionNameInstrumentation.

Would you be interested in that?

Yes, we would indeed be interested.
I realize the tag for this topic says Java agent, but we would also like to get this feature for Django 2.2 and below with the help of DJANGO_TRANSACTION_NAME_FROM_ROUTE setting.
If you can point me to the right place for the python agent as well, it would be of great help!

Best to create another topic with the python tag, referencing this topic.

I'm afraid this is only possible for Django 2.2+, as Django didn't make the route available before that.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.