# Spring Boot instrumentation only discovers @Controller classes

**URL:** <https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934>\
**Category:** APM\
**Tags:** java\
**Created:** [April 29, 2019, 1:05pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934 "2019-04-29T13:05:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiagoveigalazaro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagoveigalazaro/32/45237_2.png) [@tiagoveigalazaro](https://discuss.elastic.co/u/tiagoveigalazaro)\
**Post date:** [April 29, 2019, 1:05pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/1 "2019-04-29T13:05:39Z")

</div>

Hi all,

We are evaluating Elastic APM as the APM solution for a newly built project at a customer. The experience so far has been great, with a small nuance.

We are using Spring Boot with a three-tier approach: @Controller, @Service and @Repository annotated classes. To my surprise, only the rest endpoints (@Controller) get discovered. To add additional spans, we need to add them manually via the API (tested, works great). We've tried to configure the flag `elastic.apm.trace_methods` to monitor all methods of all classes of the base package but does not seem to work.

Are we doing something wrong or is this the expected behaviour?

**Kibana version** : 7.0.0

**Elasticsearch version** : 7.0.0

**APM Server version** : 7.0.0

**APM Agent language and version** : Java 1.6.0

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: Docker running on Kubernetes

**Fresh install or upgraded from other version?** : Fresh install

---

<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:** [April 29, 2019, 1:33pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/2 "2019-04-29T13:33:10Z")

</div>

Hi and thanks for evaluating Elastic APM 🙂

> [@tiagoveigalazaro](#):
>
> Are we doing something wrong or is this the expected behaviour?

Yes, this is expected. There are no spans created for `@Service` or `@Repository` methods by default. So `trace_methods` should be the way to go for you.

Could you send me the [debug logs](https://www.elastic.co/guide/en/apm/agent/java/current/trouble-shooting.html#trouble-shooting-logging) of the startup up until the first request is completed?

Thanks,  
Felix

---

<div class="post-metadata">

**Author:** ![tiagoveigalazaro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagoveigalazaro/32/45237_2.png) [@tiagoveigalazaro](https://discuss.elastic.co/u/tiagoveigalazaro)\
**Post date:** [April 29, 2019, 2:28pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/3 "2019-04-29T14:28:36Z")

</div>

Hi Felix,

Thank you so much for such a speedy reply. When I enabled it it shows some more data that I will have to anonymise. Will prepare a sandboxed application that will be easier to debug this on and share the logs with you as soon as I can. Thanks again!

---

<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:** [April 29, 2019, 2:41pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/4 "2019-04-29T14:41:07Z")

</div>

Sounds like a plan. In the meantime, could you send me your configuration for `trace_methods`? Maybe I can spot something obvious there.

---

<div class="post-metadata">

**Author:** ![aerstelle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aerstelle/32/43121_2.png) [@aerstelle](https://discuss.elastic.co/u/aerstelle)\
**Post date:** [April 30, 2019, 6:44pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/5 "2019-04-30T18:44:15Z")

</div>

We've temporarily worked around this by setting the following trace\_methods, but we would also prefer a way to specify all @Service's public methods similar to how @Controller methods are automatically captured.

`-Delastic.apm.trace_methods="public com.myorg.*ServiceImpl#*"`

I thought of building an solution with AOP to target the methods, but couldn't wrap my head around the approach.

---

<div class="post-metadata">

**Author:** ![tiagoveigalazaro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagoveigalazaro/32/45237_2.png) [@tiagoveigalazaro](https://discuss.elastic.co/u/tiagoveigalazaro)\
**Post date:** [May 2, 2019, 2:57pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/6 "2019-05-02T14:57:48Z")

</div>

Hi,

Sorry for the delay to your such quick note Felix.

We are using something like this:

```auto
-Delastic.apm.trace_methods=com.example.*

```

Question: does the wildcard match sub packages? We are using our base package here, but then we have .service, .repository, etc. This could potentially be the issue if we're trying to use something that does not work the way we are assuming.

---

<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:** [May 2, 2019, 3:25pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/7 "2019-05-02T15:25:41Z")

</div>

Yes, sub-packages are matched with a wildcard as well. See also [https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-trace-methods](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-trace-methods)

---

<div class="post-metadata">

**Author:** ![tiagoveigalazaro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiagoveigalazaro/32/45237_2.png) [@tiagoveigalazaro](https://discuss.elastic.co/u/tiagoveigalazaro)\
**Post date:** [May 8, 2019, 1:12pm UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/8 "2019-05-08T13:12:34Z")

</div>

Hi all,

Sorry for the late reply once again, but many other topics came in. I think we might have done something wrong in our initial service, because on this second that I built for debugging purposes the trace\_methods work!

Thanks for your help! (We're happy 🙂)

---

<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:** [May 29, 2019, 9:12am UTC](https://discuss.elastic.co/t/spring-boot-instrumentation-only-discovers-controller-classes/178934/9 "2019-05-29T09:12:34Z")

</div>

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