# Referencing to an environment variable for usage inside apm properties file

**URL:** <https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410>\
**Category:** APM\
**Tags:** java\
**Created:** [October 5, 2019, 3:05am UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410 "2019-10-05T03:05:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nie/32/55307_2.png) [@Nie](https://discuss.elastic.co/u/Nie)\
**Post date:** [October 5, 2019, 3:05am UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/1 "2019-10-05T03:05:34Z")

</div>

How do we reference to an environment variable inside elasticapm.properties file? I can't find an example here - [https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html](https://www.elastic.co/guide/en/apm/agent/java/current/configuration.html)

Is this valid for elasticapm.properties file assuming ENV\_APPLICATION\_US\_SANTACLARA exists in the environment?

```
service_name=${ENV_APPLICATION_US_SANTACLARA}
application_packages=com.example
server_urls=http://localhost:8200
```

---

<div class="post-metadata">

**Author:** ![Nie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nie/32/55307_2.png) [@Nie](https://discuss.elastic.co/u/Nie)\
**Post date:** [October 5, 2019, 11:36pm UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/2 "2019-10-05T23:36:05Z")

</div>

I decided to try my example above. It's invalid. Here's the error

`[Attach Listener] WARN co.elastic.apm.agent.shaded.stagemonitor.configuration.ConfigurationOption - Error in /tmp/elasticapm.properties: Your service name "${ENV_APPLICATION_US_SANTACLARA}" must only contain characters from the ASCII alphabet, numbers, dashes, underscores and spaces`

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [October 6, 2019, 5:57am UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/3 "2019-10-06T05:57:14Z")

</div>

Since the properties file is parsed as key-value literals, this is impossible.  
What you could do is set the `ELASTIC_APM_SERVICE_NAME` environment variable in your startup script. See [related documentation](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-service-name).

---

<div class="post-metadata">

**Author:** ![Nie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nie/32/55307_2.png) [@Nie](https://discuss.elastic.co/u/Nie)\
**Post date:** [October 6, 2019, 2:20pm UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/4 "2019-10-06T14:20:59Z")

</div>

So add ELASTIC\_APM\_SERVICE\_NAME to the environment variable in the startup and remove it from the properties file. Correct?  
Thank you.

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [October 6, 2019, 2:47pm UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/5 "2019-10-06T14:47:32Z")

</div>

Correct. Set it with the value of `ENV_APPLICATION_US_SANTACLARA`, which means you must make sure you do that only after `ENV_APPLICATION_US_SANTACLARA` is set.

---

<div class="post-metadata">

**Author:** ![Nie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nie/32/55307_2.png) [@Nie](https://discuss.elastic.co/u/Nie)\
**Post date:** [October 6, 2019, 3:15pm UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/6 "2019-10-06T15:15:15Z")

</div>

It worked! Thank you so much!

---

<div class="post-metadata">

**Author:** ![Nie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nie/32/55307_2.png) [@Nie](https://discuss.elastic.co/u/Nie)\
**Post date:** [October 11, 2019, 2:53pm UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/7 "2019-10-11T14:53:28Z")

</div>

Follow up question. What's the proper way of shipping catalina.out?

---

<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:** [November 1, 2019, 10:53am UTC](https://discuss.elastic.co/t/referencing-to-an-environment-variable-for-usage-inside-apm-properties-file/202410/8 "2019-11-01T10:53:29Z")

</div>

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