# Capture method arguments and return value in Java

**URL:** <https://discuss.elastic.co/t/capture-method-arguments-and-return-value-in-java/296308>\
**Category:** APM\
**Tags:** java\
**Created:** [February 4, 2022, 2:06pm UTC](https://discuss.elastic.co/t/capture-method-arguments-and-return-value-in-java/296308 "2022-02-04T14:06:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkensy](https://avatars.discourse-cdn.com/v4/letter/k/edb3f5/32.png) [@kkensy](https://discuss.elastic.co/u/kkensy)\
**Post date:** [February 4, 2022, 2:06pm UTC](https://discuss.elastic.co/t/capture-method-arguments-and-return-value-in-java/296308/1 "2022-02-04T14:06:05Z")

</div>

Hello all,

we are trying to evaluate the elastic apm solution. I want to understand whether i can capture any method arguments or return value (of selected methods) without touching the source code?

A similar question was asked over 2 years ago - I wonder if anything has changed? I can't find any references in the documentation.

> [@Capture method arguments and return value](https://discuss.elastic.co/t/capture-method-arguments-and-return-value/204360):
>
> Hi All, Am totally new to elastic apm as well as elastic search and am trying to evaluate elastic apm and hence subscribed to trail version of elastic cloud. I want to understand whether i can capture any method arguments or return value and if possible then how to do the same. Regards, Gopikrishnan

Regards  
Krystian

---

<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:** [February 4, 2022, 3:18pm UTC](https://discuss.elastic.co/t/capture-method-arguments-and-return-value-in-java/296308/2 "2022-02-04T15:18:40Z")

</div>

Hi @kkensy , nothing have changed here and we don't have plans to implement that.

If you could modify the application code the simplest way to do that would be to use the [Public API](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html).  
Here you state that you can't, so simply using the public API is not an option.

The biggest advantage here is that the code modifications are really simple and straightforward (also easy to revert if needed).

On the other end, the Java agent supports external plugins, which allow you to write a custom plugin for your application that will enable you to modify/add values to the existing spans and transactions that are created by the agent. There is no limitation on what the agent can capture: arguments, return values, even private class attributes could be read and modified.

The major downside here is that the complexity is way higher than a trivial code modification in the application, and will require you to be able to maintain this external plugin over time.

---

<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:** [February 25, 2022, 11:19am UTC](https://discuss.elastic.co/t/capture-method-arguments-and-return-value-in-java/296308/3 "2022-02-25T11:19:23Z")

</div>

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