# Setting environment from agent

**URL:** <https://discuss.elastic.co/t/setting-environment-from-agent/194911>\
**Category:** APM\
**Tags:** java\
**Created:** [August 12, 2019, 7:44pm UTC](https://discuss.elastic.co/t/setting-environment-from-agent/194911 "2019-08-12T19:44:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [August 12, 2019, 7:44pm UTC](https://discuss.elastic.co/t/setting-environment-from-agent/194911/1 "2019-08-12T19:44:18Z")

</div>

Hello I am wondering if it would be possible to set the `service.environment` field from the java agent side using -D options. The main idea is that we would like to use one APM server for multiple environments and we would like to have the possibility to filter the data from the environment.

**Kibana version** : 7.3.0

**Elasticsearch version** : 7.3.0

**APM Server version** : 7.3.0

**APM Agent language and version** : java 1.8.0

**Browser version** : Safari 13.0

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

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

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

\*\* I am wondering if it would be possible to set the `service.environment` field from the java agent side using -D options. The main idea is that we would like to use one APM server for multiple environments and we would like to have the possibility to filter the data from the environment.\*\*:

**Steps to reproduce** :  
1.  
2.  
3.

**Errors in browser console (if relevant)**:

**Provide logs and/or server output (if relevant)**:

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 12, 2019, 9:43pm UTC](https://discuss.elastic.co/t/setting-environment-from-agent/194911/2 "2019-08-12T21:43:33Z")

</div>

Hi @zozo6015

Is [this](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-environment) what you are looking for?

If so you should be able to set it with `-Delastic.apm.environment="production"`

Then you can filter on it and there is even a built in filter in the APM UI for versions \>= 7.2

 ![50%20PM](https://us1.discourse-cdn.com/elastic/original/3X/3/d/3df7fe2df79ee3f2cc203bd14ffc7bcbe6c0c24b.png)

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [August 13, 2019, 12:25pm UTC](https://discuss.elastic.co/t/setting-environment-from-agent/194911/3 "2019-08-13T12:25:16Z")

</div>

Great, that is exactly what I need.

---

<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:** [September 3, 2019, 8:37am UTC](https://discuss.elastic.co/t/setting-environment-from-agent/194911/4 "2019-09-03T08:37:49Z")

</div>

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