# APM agent is not starting

**URL:** <https://discuss.elastic.co/t/apm-agent-is-not-starting/271228>\
**Category:** APM\
**Tags:** docker, java\
**Created:** [April 26, 2021, 8:02am UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228 "2021-04-26T08:02:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggio](https://avatars.discourse-cdn.com/v4/letter/g/51bf81/32.png) [@ggio](https://discuss.elastic.co/u/ggio)\
**Post date:** [April 26, 2021, 8:02am UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/1 "2021-04-26T08:02:59Z")

</div>

Hi,

I'm trying to integrate Elastic APM with some Java microservices running on Docker environment. These microservices are all defined inside a docker-compose YAML files

Since the application is based on Java, I downloaded the Java APM agent and I've added these java opts to each component:  
-javaagent:/path/to/elastic-apm-agent.jar -Delastic.apm.service\_name="name of microservice"

Some common properties between microservices such as Elastic url, secret token are defined in a elasticapm.properties which is located in the same path of the apm agent jar

The result is that the APM agent is not starting, on the logs I can see these relevant messages:  
**- Error: Could not find or load main class "name of the application here"**  
**- Error in Java System Properties: Your service name ""nameofservicehere" must only contain characters from the ASCII alphabet, numbers, dashes, underscores and spaces Default value 'app' for 'service\_name' will be applied.**

It is worth to say that I'm not using any special character inside the name of the service, just letters, spaces and dashes.

What's wrong with my setup?

**Kibana version** :  
7.10.2  
**Elasticsearch version** :  
7.10.2  
**APM Server version** :  
7.10.2  
**APM Agent language and version** :  
Java Elastic APM agent 1.23.0  
**Original install method (e.g. download page, yum, deb, from source, etc.) and version**:  
Official repository  
**Java version**  
openjdk version "1.8.0\_252"  
OpenJDK Runtime Environment (IcedTea 3.16.0) (Alpine 8.252.09-r0)  
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

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

- Error: Could not find or load main class "name of the application here"
- Error in Java System Properties: Your service name ""nameofservicehere" must only contain characters from the ASCII alphabet, numbers, dashes, underscores and spaces Default value 'app' for 'service\_name' will be applied.

---

<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:** [April 26, 2021, 9:36am UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/2 "2021-04-26T09:36:20Z")

</div>

Looks like there is something wrong with your command line.  
See why it's parsed as if `"name of the application here"` is the main class.

> [@ggio](#):
>
> It is worth to say that I'm not using any special character inside the name of the service, just letters, spaces and dashes.

It could be the usage of `"` when setting the `service_name` system property.

If you can't figure it out, please paste the entire command line here.

---

<div class="post-metadata">

**Author:** ![ggio](https://avatars.discourse-cdn.com/v4/letter/g/51bf81/32.png) [@ggio](https://discuss.elastic.co/u/ggio)\
**Post date:** [April 26, 2021, 10:22am UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/3 "2021-04-26T10:22:34Z")

</div>

I just tried to substitute the jvm parameter **-Delastic.apm.service\_name** with the environment variable **ELASTIC\_APM\_SERVICE\_NAME** and now I can see application transactions coming to the APM server.  
This solution is also acceptable for me

Now, I still don't understand why part of service name is truncated, just to make you understand the environment variable is set in this way:  
**ELASTIC\_APM\_SERVICE\_NAME="Nameofproject name-of-microservice"** (notice the space between two words)  
If I go on Elastic APM server, I can see only the last part of the name, name-of-microservice in this case.  
Any idea of why of this behaviour?

---

<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:** [April 26, 2021, 12:01pm UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/4 "2021-04-26T12:01:56Z")

</div>

I can't put my finger on why exactly that is, but it is probably has to do with how env variables names and/or values are escaped within your specific setup. Normally, you should be able to figure it out by some trial and error (e.g. test with single quotes or no quotes).  
Alternatively, just switch to using only single words (with underscores instead of spaces) and without any quoting. I assume this should avoid these issues.

---

<div class="post-metadata">

**Author:** ![ggio](https://avatars.discourse-cdn.com/v4/letter/g/51bf81/32.png) [@ggio](https://discuss.elastic.co/u/ggio)\
**Post date:** [April 26, 2021, 2:25pm UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/5 "2021-04-26T14:25:26Z")

</div>

You were right, I just tried to set the environment variable without using any double/single quote and now the value of the variable is matching with the service name inside Elastic APM.

Thanks a lot @Eyal_Koren!

---

<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:** [May 17, 2021, 10:26am UTC](https://discuss.elastic.co/t/apm-agent-is-not-starting/271228/6 "2021-05-17T10:26:09Z")

</div>

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