From 05bdf4f5152df400a704b654123c3f490f23b2e4 Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Fri, 16 Jul 2021 08:08:23 +0200 Subject: [PATCH 1/5] Use Implementation-Title as default service name if it is available --- .../apm/agent/configuration/ServiceNameUtil.java | 11 ++++++++++- docs/configuration.asciidoc | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceNameUtil.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceNameUtil.java index 97326f6cfb..a744ca91ac 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceNameUtil.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServiceNameUtil.java @@ -20,6 +20,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.jar.Attributes; +import java.util.jar.JarFile; public class ServiceNameUtil { private static final String JAR_VERSION_SUFFIX = "-(\\d+\\.)+(\\d+)(.*)?$"; @@ -86,7 +88,14 @@ private static String parseJarCommand(String command) { String result = null; for (String commandPart : commandParts) { if (commandPart.endsWith(".jar")) { - result = removeVersionFromJar(removePath(removeJarExtension(commandPart))); + try (JarFile jarFile = new JarFile(commandPart)) { + result = jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_TITLE); + } catch (Exception ignored) { + } + + if (result == null || result.isEmpty()) { + result = removeVersionFromJar(removePath(removeJarExtension(commandPart))); + } break; } } diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index d90d68d19c..237ea2e51e 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -492,6 +492,7 @@ NOTE: Service name auto discovery mechanisms require APM Server 7.0+. | For Spring-based application, uses the `spring.application.name` property, if set. For Servlet-based applications, uses the `display-name` of the `web.xml`, if available. Falls back to the servlet context path the application is mapped to (unless mapped to the root context). +Falls back to `Implementation-Title` in the `META-INF/MANIFEST.MF` of the main jar file. Falls back to the name of the main class or jar file. If the service name is set explicitly, it overrides all of the above. | String | false From b05df14138e5260aa55adbf7f439d493de5ae566 Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Fri, 16 Jul 2021 09:03:17 +0200 Subject: [PATCH 2/5] Added #1921 to the changelog --- CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c6bd54e726..9fdd72f520 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -59,6 +59,7 @@ service map and downstream service in the dependencies table - {pull}1898[#1898] * Basic support for com.sun.net.httpserver.HttpServer - {pull}1854[#1854] * Update to async-profiler 1.8.6 {pull}1907[#1907] * Added support for setting the framework using the public api (#1908) - {pull}1909[#1909] +* When the MANIFEST.MF of the main jar contains the Implementation-Title attribute, it is used as the default service name - {pull}1921[#1921] [float] ===== Bug fixes From 4e0d07ac13211e68f29a29e4247277963cf4be00 Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Thu, 2 Dec 2021 15:46:48 +0100 Subject: [PATCH 3/5] Updated configuration.asciidoc --- docs/configuration.asciidoc | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index b41847d92c..1094882f2b 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -496,7 +496,6 @@ NOTE: Service name auto discovery mechanisms require APM Server 7.0+. | For Spring-based application, uses the `spring.application.name` property, if set. For Servlet-based applications, uses the `display-name` of the `web.xml`, if available. Falls back to the servlet context path the application is mapped to (unless mapped to the root context). -Falls back to `Implementation-Title` in the `META-INF/MANIFEST.MF` of the main jar file. Falls back to the name of the main class or jar file. If the service name is set explicitly, it overrides all of the above. | String | false From 30986088e2ecf26d286d34da7b6f1037fb3ee024 Mon Sep 17 00:00:00 2001 From: Felix Barnsteiner Date: Wed, 26 Jan 2022 08:30:24 +0100 Subject: [PATCH 4/5] Document implementation-title fallback --- apm-agent/src/test/resources/configuration.asciidoc.ftl | 1 + docs/configuration.asciidoc | 2 ++ 2 files changed, 3 insertions(+) diff --git a/apm-agent/src/test/resources/configuration.asciidoc.ftl b/apm-agent/src/test/resources/configuration.asciidoc.ftl index 2a1428716a..6de0111723 100644 --- a/apm-agent/src/test/resources/configuration.asciidoc.ftl +++ b/apm-agent/src/test/resources/configuration.asciidoc.ftl @@ -83,6 +83,7 @@ ELASTIC_APM_SERVER_URL=http://localhost:8200 For Spring-based application, uses the `spring.application.name` property, if set. For Servlet-based applications, uses the `display-name` of the `web.xml`, if available. Falls back to the servlet context path the application is mapped to (unless mapped to the root context). +Falls back to the `Implementation-Title` in the `MANIFEST.MF` file. Falls back to the name of the main class or jar file. If the service name is set explicitly, it overrides all of the above. diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index 6db66d6ef9..b21e9232b0 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -497,6 +497,7 @@ NOTE: Service name auto discovery mechanisms require APM Server 7.0+. | For Spring-based application, uses the `spring.application.name` property, if set. For Servlet-based applications, uses the `display-name` of the `web.xml`, if available. Falls back to the servlet context path the application is mapped to (unless mapped to the root context). +Falls back to the `Implementation-Title` in the `MANIFEST.MF` file. Falls back to the name of the main class or jar file. If the service name is set explicitly, it overrides all of the above. | String | false @@ -2891,6 +2892,7 @@ The default unit for this option is `ms`. # Default value: For Spring-based application, uses the `spring.application.name` property, if set. # For Servlet-based applications, uses the `display-name` of the `web.xml`, if available. # Falls back to the servlet context path the application is mapped to (unless mapped to the root context). +# Falls back to the `Implementation-Title` in the `MANIFEST.MF` file. # Falls back to the name of the main class or jar file. # If the service name is set explicitly, it overrides all of the above. # From ec1688c2c887993a43eaaee737b3eeab5a37daba Mon Sep 17 00:00:00 2001 From: Tobias Stadler Date: Wed, 26 Jan 2022 08:40:15 +0100 Subject: [PATCH 5/5] Update CHANGELOG.asciidoc Co-authored-by: Felix Barnsteiner --- CHANGELOG.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index e7f6eeb36a..3057b7ffa1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -29,7 +29,8 @@ endif::[] * Replaced `authorization` in the default value of `sanitize_field_names` with `*auth*` - {pull}2326[#2326] * Unsampled transactions are dropped and not sent to the APM-Server if the APM-Server version is 8.0+ - {pull}2329[#2329] * Adding agent logging capabilities to our SDK, making it available for external plugins - {pull}2390[#2390] -* When the MANIFEST.MF of the main jar contains the Implementation-Title attribute, it is used as the default service name - {pull}1921[#1921] +* When the `MANIFEST.MF` of the main jar contains the `Implementation-Title` attribute, it is used as the default service name - {pull}1921[#1921] + Note: this may change your service names if you relied on the auto-discovery that uses the name of the jar file. If that jar file also contains an `Implementation-Title` attribute in the `MANIFEST.MF` file, the latter will take precedence. [float] ===== Bug fixes