# Apm-agent service\_name as macro/variable

**URL:** <https://discuss.elastic.co/t/apm-agent-service-name-as-macro-variable/265632>\
**Category:** APM\
**Tags:** java\
**Created:** [February 26, 2021, 4:08pm UTC](https://discuss.elastic.co/t/apm-agent-service-name-as-macro-variable/265632 "2021-02-26T16:08:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rufik](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rufik](https://discuss.elastic.co/u/rufik)\
**Post date:** [February 26, 2021, 4:08pm UTC](https://discuss.elastic.co/t/apm-agent-service-name-as-macro-variable/265632/1 "2021-02-26T16:08:22Z")

</div>

Is it possible to use some kind of variable/macro for `elastic.apm.service_name` option?  
I have java app running on many machines, one app per one machine. Leaving this option empty causes to show the same "Service Name" in Kibana APM - I'd like to have `service_name` as hostname. So something like that could be very helpful:

```auto
-Delastic.apm.service_name=$hostname

```

I could use single configuration for all apps then 🙂

---

<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:** [February 27, 2021, 6:50pm UTC](https://discuss.elastic.co/t/apm-agent-service-name-as-macro-variable/265632/2 "2021-02-27T18:50:33Z")

</div>

Hi,  
as a workaround you can export ENV variable before starting your application:

```auto
export ELATIC_APM_SERVICE_NAME=`hostname`
echo $ELATIC_APM_SERVICE_NAME

```

---

<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:** [March 20, 2021, 2:51pm UTC](https://discuss.elastic.co/t/apm-agent-service-name-as-macro-variable/265632/3 "2021-03-20T14:51:24Z")

</div>

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