# Alternative to capture\_body

**URL:** <https://discuss.elastic.co/t/alternative-to-capture-body/291607>\
**Category:** APM\
**Tags:** java\
**Created:** [December 13, 2021, 8:56am UTC](https://discuss.elastic.co/t/alternative-to-capture-body/291607 "2021-12-13T08:56:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhavani\_Ananth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavani_ananth/32/45740_2.png) [@Bhavani\_Ananth](https://discuss.elastic.co/u/Bhavani_Ananth)\
**Post date:** [December 13, 2021, 8:56am UTC](https://discuss.elastic.co/t/alternative-to-capture-body/291607/1 "2021-12-13T08:56:08Z")

</div>

Hello Team,

There is a new requirement wherein we need to parse a certain tracking number that is part of the http url or part of the request body.

The one in the url can be easily retrieved.(http.url and using logstash parsing)  
Is there a way to retrieve the same from the request body without enabling capture\_body option as the latter has performance implications.

Please do let me know if any other options are available.  
Thanks in advance for your help!

The following are some details related to the elastic stack,  
**Kibana version** : 7.8.1

**Elasticsearch version** : 7.8.1.

**APM Server version** : 7.8.1

**APM Agent language and version** : Java, 1.18

**Browser version** :

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

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

**Is there anything special in your setup?** No

Regards,  
Bhavani

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [December 13, 2021, 9:26am UTC](https://discuss.elastic.co/t/alternative-to-capture-body/291607/2 "2021-12-13T09:26:04Z")

</div>

Hi @Bhavani_Ananth ,

It is not possible to capture something from the request body without capturing the whole body.  
For the performance implications, if you haven´t already doing an experiment is the best way to know if that's actually an issue in your use-case as it all depends on the actual application load, the request body size, ...

But, by reading your use-case description:

- you are already using Elastic APM Agent (version 1.18 is very old, you should update it)
- you need to capture a tracking ID that might be provided through the request body or URL

Here it sounds to be a perfect use-case to use the [Agent public API](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html), in particular it could allow to capture the tracking ID by using the [transaction custom context](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-transaction-add-custom-context):

```java
String trackingId = ""; // get tracking ID from your application code
ElasticApm.currentTransaction().addCustomContext("tracking_id", trackingId); 

```

---

<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:** [January 3, 2022, 5:26am UTC](https://discuss.elastic.co/t/alternative-to-capture-body/291607/3 "2022-01-03T05:26:10Z")

</div>

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