Referencing to an environment variable for usage inside apm properties file

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

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

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

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.

1 Like

So add ELASTIC_APM_SERVICE_NAME to the environment variable in the startup and remove it from the properties file. Correct?
Thank you.

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.

1 Like

It worked! Thank you so much!

1 Like

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

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