# Set service environment from apm-server.yml

**URL:** <https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582>\
**Category:** APM\
**Tags:** server\
**Created:** [June 1, 2021, 6:14am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582 "2021-06-01T06:14:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryce\_Fernandes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bryce_fernandes/32/71166_2.png) [@Bryce\_Fernandes](https://discuss.elastic.co/u/Bryce_Fernandes)\
**Post date:** [June 1, 2021, 6:14am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/1 "2021-06-01T06:14:46Z")

</div>

Hi,

I have elk stack 7.11.1 setup with apm as central server.  
Have configured apm for java microservice and getting data in elasticsearch properly.  
Have 2 questions

1. I haven't set service environment variable in agent config and want to do it on central server. I have tried following.

2. I will be having multiple microservices for multiple applications so will like to create a field application : value when service.name contains some string.

Thanks and Regards,  
Bryce Fernandes.

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [June 1, 2021, 8:30am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/2 "2021-06-01T08:30:25Z")

</div>

Hi @Bryce_Fernandes  
what do you mean by " create a field application : value" ?

---

<div class="post-metadata">

**Author:** ![Bryce\_Fernandes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bryce_fernandes/32/71166_2.png) [@Bryce\_Fernandes](https://discuss.elastic.co/u/Bryce_Fernandes)\
**Post date:** [June 1, 2021, 8:37am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/3 "2021-06-01T08:37:31Z")

</div>

Hi @nugusbayevkk ,

So I have an application with 40 microservices. Application name is Instaclaim.  
Now in apm tab I can get 40 microservices by 40 names. What I want to do is create a field "Application\_name": "Instaclaim" , "Application\_name": "ESB".

This should be created after matching part of string present in service.name.

Regards,  
Bryce Fernandes.

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [June 2, 2021, 3:35am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/4 "2021-06-02T03:35:10Z")

</div>

> 1. I haven't set service environment variable in agent config and want to do it on central server. I have tried following. `apm-server.default_service_environment: "Production"`

That is the way to do it. The `apm-server.default_service_environment` config was introduced in 7.13.0, which was just released last week, so you would need to upgrade.

> 1. I will be having multiple microservices for multiple applications so will like to create a field application : value when service.name contains some string.

At the moment we don't have any configuration to do this centrally, though it sounds like a good feature request -- associating services with business applications.

You have at least two options that I can think of:

- Modify the "apm" ingest pipeline to set another field: [Ingest pipelines | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html)
- Set it through "global labels" in each service: [Core configuration options | APM Java Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-global-labels)

---

<div class="post-metadata">

**Author:** ![Bryce\_Fernandes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bryce_fernandes/32/71166_2.png) [@Bryce\_Fernandes](https://discuss.elastic.co/u/Bryce_Fernandes)\
**Post date:** [June 2, 2021, 5:26am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/5 "2021-06-02T05:26:14Z")

</div>

Hi @axw ,

Thanks for replying to my topic once again. Hope you are doing good.

I have tried the 2nd approach and has worked as of now will try first as well.

Thanks,  
Bryce Fernandes.

---

<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:** [June 23, 2021, 1:27am UTC](https://discuss.elastic.co/t/set-service-environment-from-apm-server-yml/274582/6 "2021-06-23T01:27:07Z")

</div>

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