# Service\_name auto-discovery issue

**URL:** <https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604>\
**Category:** APM\
**Tags:** java\
**Created:** [November 18, 2021, 2:08pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604 "2021-11-18T14:08:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![coynef](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@coynef](https://discuss.elastic.co/u/coynef)\
**Post date:** [November 18, 2021, 2:08pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/1 "2021-11-18T14:08:33Z")

</div>

**Kibana version** : 7.10.1

**Elasticsearch version** :7.10.1

**APM Server version** :7.10.1

**APM Agent language and version** : 1.26.0

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:  
Service name is being auto discovered as '-project-artifactId-' which is incorrect

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/6/46a59b8caca6d46117ec71aebfbf9d2664dbf6dd.png)

**Steps to reproduce** :

1. Run my java application with the -javaagent parameter set
2. Metrics reach APM as expected and viewable in Kibana
3. Service name is incorrectly discovered as '-project-artifactId-'

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

Full command that runs the application is...  
/usr/bin/java -javaagent:/usr/local/apm/elastic-apm-agent-1.26.0.jar -Xms82m -Xmx2048m -DdockerNetworkNames=SA\_Service\_Overlay -DdockerServiceNames=capability-access-manager\_rest -DhazelcastPeerPort=5701 -DdockerServiceLabels=container\_name=capability-access-manager-rest -DskipVerifySsl=False -DlogAllServiceNamesOnFailedDiscovery=false -DstrictDockerServiceNameComparison=true -cp capability-access-manager-rest.jar -Dhttps.proxyHost= -Dhttps.proxyPort= -Djdk.tls.ephemeralDHKeySize=2048 org.springframework.boot.loader.JarLauncher

Docker log when container spins up...

```auto
2021-11-18 15:25:33,014 [main] INFO co.elastic.apm.agent.util.JmxUtils - Found JVM-specific OperatingSystemMXBean interface: com.sun.management.OperatingSystemMXBean
2021-11-18 15:25:34,704 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.26.0 as JarLauncher on Java 1.8.0_212 Runtime version: 1.8.0_212-b04 VM version: 25.212-b04 (IcedTea) Linux 3.10.0-1127.19.1.el7.x86_64
2021-11-18 15:25:34,706 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - environment: 'PRO-1' (source: Environment Variables)
2021-11-18 15:25:34,707 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - server_url: 'https://gt6h12345.icts.abc.net:8200' (source: Environment Variables)
2021-11-18 15:25:34,708 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - verify_server_cert: 'false' (source: Environment Variables)
2021-11-18 15:25:34,709 [main] WARN co.elastic.apm.agent.configuration.StartupInfo - To enable all features and decrease startup time, please configure application_packages
2021-11-18 15:25:57,471 [main] INFO co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state
2021-11-18 15:25:58,550 [elastic-apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build_date": "2021-01-12T21:51:32Z", "build_sha": "42a349a4ec9d2dd16e08b8af125647294e7a7e4b", "version": "7.10.2"}
{"@timestamp":"2021-11-18T15:26:06.778+00:00","@version":1,"message":"Client environment:java.class.path=capability-access-manager-rest.jar:/usr/local/apm/elastic-apm-agent-1.26.0.jar","logger_name":"org.apache.zookeeper.ZooKeeper","thread_name":"main","level":"INFO","level_value":20000}
2021-11-18 15:26:19,591 [main] WARN co.elastic.apm.agent.bci.bytebuddy.ErrorLoggingListener - io.micrometer.core.instrument.MeterRegistry$$EnhancerBySpringCGLIB$$983437b8 uses an unsupported class file version (pre Java 4}) and can't be instrumented. Consider updating to a newer version of that library.
2021-11-18 15:26:22,032 [main] INFO co.elastic.apm.agent.micrometer.MicrometerMetricsReporter - Registering Micrometer MeterRegistry: io.micrometer.prometheus.PrometheusMeterRegistry@42dd7d82
2021-11-18 15:27:44,213 [main] INFO co.elastic.apm.agent.servlet.ServletVersionInstrumentation - Servlet container info = Apache Tomcat/9.0.16

```

---

<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:** [November 21, 2021, 12:55pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/2 "2021-11-21T12:55:59Z")

</div>

Hi and welcome to our community!

Did you try to set `${project.artifactId}` or something similar somewhere in your application (e.g. as the `<display-name>` in your `web.xml` or `spring.application.name` in `application.properties`), expecting it to be replaced on build time?

If so, note that it doesn't get rendered as you expect, and since it contains some illegal characters, as [documented](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-service-name), they are being escaped.

In order to fix that, either make sure that your application artifacts contain the proper service/application name, or set the `service_name` configuration manually.

---

<div class="post-metadata">

**Author:** ![coynef](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@coynef](https://discuss.elastic.co/u/coynef)\
**Post date:** [November 22, 2021, 11:41am UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/3 "2021-11-22T11:41:42Z")

</div>

Thanks for feedback here. I looked at what you suggested and I see the following is set in the /capability-access-manager-rest/src/main/resources/application.properties file....

"application.name=@project.artifactId@"

Is this what is being used?

We have a number of other applications and this property is also set as above but the autodiscovery is working as expected

---

<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:** [November 22, 2021, 1:02pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/4 "2021-11-22T13:02:25Z")

</div>

> [@coynef](#):
>
> Is this what is being used?

It seems to be the case

> [@coynef](#):
>
> We have a number of other applications and this property is also set as above but the autodiscovery is working as expected

I guess in those other applications this value is properly being set with a proper value at build time

---

<div class="post-metadata">

**Author:** ![coynef](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@coynef](https://discuss.elastic.co/u/coynef)\
**Post date:** [November 22, 2021, 1:51pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/5 "2021-11-22T13:51:28Z")

</div>

I can see in the associated pom.xml that the project artifactId is set as capability-access-manager-rest

Is there any way, logs or otherwise, where I see what value the auto discovery is picking up? We plan to on-board a significant number of applications so I want to avoid this issue in future.

---

<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:** [November 22, 2021, 2:18pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/6 "2021-11-22T14:18:28Z")

</div>

> [@coynef](#):
>
> Is there any way, logs or otherwise, where I see what value the auto discovery is picking up? We plan to on-board a significant number of applications so I want to avoid this issue in future.

Currently only if you set `log_level` to `DEBUG` (or lower). Can you use this logging level only for the onboarding process?

---

<div class="post-metadata">

**Author:** ![coynef](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@coynef](https://discuss.elastic.co/u/coynef)\
**Post date:** [November 22, 2021, 2:55pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/7 "2021-11-22T14:55:49Z")

</div>

I'll see can I deploy a Github code branch to our test environment. Will the service discovery module logging be detailed enough to give me the information I need if I set it to DEBUG?

---

<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:** [November 22, 2021, 3:14pm UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/8 "2021-11-22T15:14:03Z")

</div>

It should print something like: `Using <AUTO-DISCOVERED-NAME> as the service name for class loader <CLASS-LOADER>`.  
Try it with the one you already have.

---

<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:** [December 13, 2021, 11:14am UTC](https://discuss.elastic.co/t/service-name-auto-discovery-issue/289604/9 "2021-12-13T11:14:32Z")

</div>

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