# Filtering or changing user metadata with Java agent

**URL:** <https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899>\
**Category:** APM\
**Tags:** java\
**Created:** [January 10, 2022, 2:43pm UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899 "2022-01-10T14:43:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob5](https://avatars.discourse-cdn.com/v4/letter/r/ee59a6/32.png) [@Rob5](https://discuss.elastic.co/u/Rob5)\
**Post date:** [January 10, 2022, 2:43pm UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/1 "2022-01-10T14:43:35Z")

</div>

Hi!

I am using the apm Java agent attached to a Spring application without any custom spans or transactions.  
Is it possible to change or filter out the user metadata? [Metadata | APM Overview [7.15] | Elastic](https://www.elastic.co/guide/en/apm/get-started/current/metadata.html#user-fields)  
The user.name field get's populated automatically, but I don't want to store that value. Santize configuration is not helpful here unfortunately.

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [January 10, 2022, 3:43pm UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/2 "2022-01-10T15:43:29Z")

</div>

Technically you could set -Duser.name=something but the user.name is used extensively within applications as well as the agent, for example to determine the home directory and which user is running the process, so I suspect it would break things. You could post-facto sanitize the value held in the elastic database, eg regularly running a batch "anonymizing" procedure?

---

<div class="post-metadata">

**Author:** ![Rob5](https://avatars.discourse-cdn.com/v4/letter/r/ee59a6/32.png) [@Rob5](https://discuss.elastic.co/u/Rob5)\
**Post date:** [January 11, 2022, 11:28am UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/3 "2022-01-11T11:28:05Z")

</div>

> [@Jack\_Shirazi](#):
>
> Technically you could set -Duser.name=something but the user.name is used extensively within applications as well as the agent, for example to determine the home directory and which user is running the process, so I suspect it would break things

Thanks for the response.

In my case the user.name field seems to be populated from Spring context (and is set to the name of user with active session), the -Duser.name flag doesn't seem to have any effect on that.

The transaction API has a setUser method, but I don't think I can use it together with attached agent, right?

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [January 11, 2022, 11:53am UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/4 "2022-01-11T11:53:29Z")

</div>

setUser() should work, it shouldn't matter how the agent is started

---

<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:** [January 17, 2022, 4:42pm UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/5 "2022-01-17T16:42:57Z")

</div>

I'd recommend removing the user name with an ingest node pipeline.

See [Data security | APM User Guide [7.16] | Elastic](https://www.elastic.co/guide/en/apm/guide/7.16/apm-data-security.html#filters-ingest-pipeline)

---

<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 7, 2022, 12:43pm UTC](https://discuss.elastic.co/t/filtering-or-changing-user-metadata-with-java-agent/293899/6 "2022-02-07T12:43:42Z")

</div>

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