# All spans grouped into "ServletWrappingController"

**URL:** <https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765>\
**Category:** APM\
**Tags:** java, server\
**Created:** [October 30, 2020, 1:47am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765 "2020-10-30T01:47:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuleow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fuleow/32/86591_2.png) [@fuleow](https://discuss.elastic.co/u/fuleow)\
**Post date:** [October 30, 2020, 1:47am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/1 "2020-10-30T01:47:36Z")

</div>

We are instrumenting our Spring Boot services using the latest Elastic APM Agent and in Kibana the traces are all grouped by their parent spans. Unfortunately this makes almost all spans grouped under "ServletWrappingController" which is not very helpful. Is there a way to rename the parent span so this is more meaningful?

Some of our service are being instrumented using the OpenTelemetry agent and it allows the parent span to be renamed. This helps us group traces more logically based on the api and method being called.

The OpenTelemetry docs acknowledge and address this:

> The state described above has one significant problem. Observability backends usually aggregate traces based on their root spans. This means that ALL traces from any application deployed to Servlet container will be grouped together. Because their root spans will all have the same named based on common entry point. In order to alleviate this problem, instrumentations for specific frameworks, such as Spring MVC here, _update_ name of the span corresponding to the entry point. Each framework instrumentation can decide what is the best span name based on framework implementation details. Of course, still adhering to OpenTelemetry [semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md).

> <https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/servlet>
>
> //github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/servlet

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 30, 2020, 7:28am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/2 "2020-10-30T07:28:00Z")

</div>

We pretty much do the same. For Spring MVC we also set the transaction name based on the MVC controller that handles the request. If it's an custom or unsupported framework, you can use the API to [set the name of the transaction](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-set-name).  
Which framework are you using? Possibly it's not much effort to add auto-instrumentation for it.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 30, 2020, 7:39am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/3 "2020-10-30T07:39:21Z")

</div>

I think the issue is that we give precedence to Spring controllers/`HandlerMethod`s as they are usually more descriptive than the `DispatcherServlet` that invokes them. But in this case, `ServletWrappingController` is invoking another servlet whose name is even more appropriate.

We could either have a special case for `ServletWrappingController` or, if you don't want any transactions named after Spring MVC controllers, you can also [`disable`](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-disable-instrumentations) the `spring-mvc` instrumentation.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 30, 2020, 11:24am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/4 "2020-10-30T11:24:00Z")

</div>

I've added support for `ServletWrappingCrontroller`: [https://github.com/elastic/apm-agent-java/pull/1461](https://github.com/elastic/apm-agent-java/pull/1461)

Could you try if the approach works for you? Here are the build artifacts of that PR:

> **[Jenkins](https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-java/apm-agent-java-mbp/detail/PR-1461/2/artifacts/)**

---

<div class="post-metadata">

**Author:** ![fuleow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fuleow/32/86591_2.png) [@fuleow](https://discuss.elastic.co/u/fuleow)\
**Post date:** [October 30, 2020, 6:31pm UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/5 "2020-10-30T18:31:54Z")

</div>

Thanks for the quick reply and PR @felixbarny. These are jsonRPC calls being handled by our custom library so the meaningful values will be in the request body. However I think your change is still useful for other services.

We are actually using the opentracing-api instead of apm-agent-api directly since there are shims available from both Elastic APM and OpenTelemetry for the OpenTracing Tracer.

We are forced to use a mixed setup because we had scaling issues using the Elastic APM Java Agent on our very high rps services (40,000+ rps). Even with a low sample rate the high level transactions are still reported to the APM server and that slowed things down significantly (see [https://github.com/elastic/apm/issues/104](https://github.com/elastic/apm/issues/104) and [https://github.com/elastic/apm/issues/151](https://github.com/elastic/apm/issues/151)).

Switching to using the OTEL or Jaeger agent and exporting to APM server's Jaeger endpoint works, but it is a hacky solution. I'm not sure if things have changed recently, but if it would be possible for the Java agent to only send sampled transaction information instead of all transactions that would make thing scale much easier.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [October 30, 2020, 9:43pm UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/6 "2020-10-30T21:43:34Z")

</div>

We'll add some experimental options to calculate metrics based on transactions in the upcoming 7.11 release. Be sure to try that out and give us feedback.

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 1, 2020, 7:03am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/7 "2020-11-01T07:03:35Z")

</div>

> [@fuleow](#):
>
> Even with a low sample rate the high level transactions are still reported to the APM server and that slowed things down significantly

Can you elaborate on that a bit? What has slowed down? Did you experience higher latencies in your application endpoints, or did you observe the effect only on the ingestion pipeline (agent -\> APM Server - ES)? Did you try to see what happens with VERY slow sample rate (e.g. 0.0 - 0.001) to validate that the overhead is indeed related to ingestion and not related to the instrumentation/tracing overhead?

---

<div class="post-metadata">

**Author:** ![fuleow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fuleow/32/86591_2.png) [@fuleow](https://discuss.elastic.co/u/fuleow)\
**Post date:** [November 2, 2020, 5:41pm UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/8 "2020-11-02T17:41:26Z")

</div>

We had the service's sample rate set at 0.01% and there were no issues there. The slowdown was in the ingestion pipeline because billions of events were being created every day for the top level transaction information. Issue 151 and the subsequent discussions provide a lot of details [https://github.com/elastic/apm/issues/151](https://github.com/elastic/apm/issues/151). It deals with the node agent but we saw the same behavior with Java.

The APM Server's UI shows the number of transactions in each latency bucket including ones which weren't sampled and it also gives overall latency numbers. We don't really need this information since we have other tools like Prometheus to capture histogram buckets of request latencies. A random sample will also approximate the correct distribution in APM without needing to record data from all transactions.

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 3, 2020, 6:12am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/9 "2020-11-03T06:12:14Z")

</div>

Thanks for the details. It validates our efforts towards not sending unsampled transactions (relying on Elasticsearch's new histogram data type instead) and smarter, tail-based, sampling.  
One thing I am still missing is whether or not you observed overhead in your application's endpoints latencies with the higher sampling rate, or any other noticeable overhead on CPU or memory (in the agent side).

---

<div class="post-metadata">

**Author:** ![fuleow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fuleow/32/86591_2.png) [@fuleow](https://discuss.elastic.co/u/fuleow)\
**Post date:** [November 3, 2020, 7:05pm UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/10 "2020-11-03T19:05:15Z")

</div>

I don't think there was any noticeable overhead on the application with sampling at under 1%. We did not attempt sampling at a higher rate because it would cause issues with ingestion.

> [@Eyal\_Koren](#):
>
> It validates our efforts towards not sending unsampled transactions

Is this something that can be enabled on the agent right now?

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [November 4, 2020, 3:53am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/11 "2020-11-04T03:53:26Z")

</div>

> [@fuleow](#):
>
> Is this something that can be enabled on the agent right now?

Not yet. It has multiple dependencies, but it is WIP.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [November 4, 2020, 7:30am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/12 "2020-11-04T07:30:58Z")

</div>

Have you tried dropping non-sampled transactions with an [APM Server processor](https://www.elastic.co/guide/en/beats/filebeat/current/defining-processors.html) in with an [ingest node processor](https://www.elastic.co/guide/en/elasticsearch/reference/master/ingest.html)?

The RPM graph will be off but it might be a decent short-term solution for you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 25, 2020, 3:31am UTC](https://discuss.elastic.co/t/all-spans-grouped-into-servletwrappingcontroller/253765/13 "2020-11-25T03:31:09Z")

</div>

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