You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/11/24 16:58:02 UTC

[GitHub] [skywalking-java] nisiyong commented on a diff in pull request #397: Report agent version to OAP

nisiyong commented on code in PR #397:
URL: https://github.com/apache/skywalking-java/pull/397#discussion_r1031710629


##########
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java:
##########
@@ -45,7 +55,32 @@ public static List<KeyStringValuePair> parseProperties() {
 
         properties.add(KeyStringValuePair.newBuilder().setKey("namespace").setValue(Config.Agent.NAMESPACE).build());
         properties.add(KeyStringValuePair.newBuilder().setKey("cluster").setValue(Config.Agent.CLUSTER).build());
+        properties.add(KeyStringValuePair.newBuilder().setKey("version").setValue(getAgentVersion()).build());
 
         return properties;
     }
+
+    public static String getAgentVersion() {
+        try {
+            InputStream inStream = InstanceJsonPropertiesUtil.class.getClassLoader()
+                    .getResourceAsStream(GIT_PROPERTIES);
+            if (inStream != null) {
+                Properties gitProperties = new Properties();
+                gitProperties.load(inStream);
+                String commitIdAbbrev = gitProperties.getProperty("git.commit.id.abbrev");
+                String buildTime = gitProperties.getProperty("git.build.time");
+                String buildVersion = gitProperties.getProperty("git.build.version");
+                String version =  buildVersion + "-" + commitIdAbbrev + "-" + buildTime;
+
+                LOGGER.info("SkyWalking agent version: {}", version);
+                return version;
+            } else {
+                LOGGER.warn("{} not found, SkyWalking agent version: unknown", GIT_PROPERTIES);

Review Comment:
   @kezhenxu94 If users build from the source tarball, here is the WARN level logging.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org