# APM Java agent: How to customize transaction sample rates based on different controllers

**URL:** <https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360>\
**Category:** Elastic Observability\
**Created:** [September 10, 2024, 8:26pm UTC](https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360 "2024-09-10T20:26:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guoqing\_Yu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guoqing_yu/32/137494_2.png) [@Guoqing\_Yu](https://discuss.elastic.co/u/Guoqing_Yu)\
**Post date:** [September 10, 2024, 8:26pm UTC](https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360/1 "2024-09-10T20:26:35Z")

</div>

I have a Java application that has multiple RESTful controllers and APM agent deployed. However, I only want certain actions/transactions to be traced instead of all of them (e.g., XXXController#update -\> sample\_rate 0.9). Is there an easy way to approach this?

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [September 11, 2024, 5:03am UTC](https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360/2 "2024-09-11T05:03:27Z")

</div>

Hi,

If you have a platinum or enterprise license, [tail-based sampling](https://www.elastic.co/guide/en/observability/current/apm-configure-tail-based-sampling.html) is exactly what you are looking for:

```yaml
- sample_rate: .9
  trace.name: "XXXController#update"
- sample_rate: .0

```

This will cause the agent to still send all traces to the APM-Server and the server will only keep the matching traces. This is useful because you can also use the outcome of the REST request to discard all successfull traces and only keep traces for errors.

If you do not have such a license, your best bet would be to disable the auto instrumentation of controllers and use `@CaptureTransaction` to only instrument the methods you want: [Public API | APM .NET Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#convenient-capture-transaction)

Best regards  
Wolfram

---

<div class="post-metadata">

**Author:** ![Guoqing\_Yu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guoqing_yu/32/137494_2.png) [@Guoqing\_Yu](https://discuss.elastic.co/u/Guoqing_Yu)\
**Post date:** [September 11, 2024, 3:12pm UTC](https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360/3 "2024-09-11T15:12:04Z")

</div>

Thanks for your prompt reply! I have tried adding tail-based sampling to apm-server.yml but while I was running the server setup I got something like “apm integration installed failed…index template matching [traces-apm] not found”. Our elastic and kibana are 7.10 while apm server is 7.17, so I doubt if it's a version incompatibility issue?

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [September 12, 2024, 4:24am UTC](https://discuss.elastic.co/t/apm-java-agent-how-to-customize-transaction-sample-rates-based-on-different-controllers/366360/4 "2024-09-12T04:24:04Z")

</div>

> [@Guoqing\_Yu](#):
>
> I doubt if it's a version incompatibility issue

Tailbased sampling is available in 7.x, but it was made generally available in 8.1: [APM version 8.1 | Elastic Observability [8.15] | Elastic](https://www.elastic.co/guide/en/observability/current/apm-release-notes-8.1.html#_added_18)

Maybe you should consider upgrading your stack some time.

> [@Guoqing\_Yu](#):
>
> index template matching [traces-apm] not found

I think you need to install the assets for the Elastic APM integration from Fleet - even if you use the standalone APM server: [Install and uninstall Elastic Agent integration assets | Fleet and Elastic Agent Guide [7.17] | Elastic](https://www.elastic.co/guide/en/fleet/7.17/install-uninstall-integration-assets.html)

Here is someone, that had a similar issue: [APM Server index template matching [traces-apm.sampled] not found - #2 by simitt](https://discuss.elastic.co/t/apm-server-index-template-matching-traces-apm-sampled-not-found/319677/2)
