APM agent is not starting

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.

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.

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.

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?

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.

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!

1 Like

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