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 2020/02/02 08:49:35 UTC

[GitHub] [skywalking] wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8

wu-sheng commented on a change in pull request #4307: Clean up legacy v1 header logic, use built-in Base64 since JDK8
URL: https://github.com/apache/skywalking/pull/4307#discussion_r373829673
 
 

 ##########
 File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextCarrier.java
 ##########
 @@ -108,53 +103,36 @@ String serialize(HeaderVersion version) {
      * @param text carries {@link #traceSegmentId} and {@link #spanId}, with '|' split.
      */
     ContextCarrier deserialize(String text, HeaderVersion version) {
-        if (text != null) {
-            // if this carrier is initialized by v1 or v2, don't do deserialize again for performance.
-            if (this.isValid(HeaderVersion.v1) || this.isValid(HeaderVersion.v2)) {
-                return this;
-            }
-            if (HeaderVersion.v1.equals(version)) {
-                String[] parts = text.split("\\|", 8);
-                if (parts.length == 8) {
-                    try {
-                        this.traceSegmentId = new ID(parts[0]);
-                        this.spanId = Integer.parseInt(parts[1]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[2]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[3]);
-                        this.peerHost = parts[4];
-                        this.entryEndpointName = parts[5];
-                        this.parentEndpointName = parts[6];
-                        this.primaryDistributedTraceId = new PropagatedTraceId(parts[7]);
-                    } catch (NumberFormatException e) {
-
-                    }
-                }
-            } else if (HeaderVersion.v2.equals(version)) {
-                String[] parts = text.split("\\-", 9);
-                if (parts.length == 9) {
-                    try {
-                        // parts[0] is sample flag, always trace if header exists.
-                        this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
-                        this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
-                        this.spanId = Integer.parseInt(parts[3]);
-                        this.parentServiceInstanceId = Integer.parseInt(parts[4]);
-                        this.entryServiceInstanceId = Integer.parseInt(parts[5]);
-                        this.peerHost = Base64.decode2UTFString(parts[6]);
-                        this.entryEndpointName = Base64.decode2UTFString(parts[7]);
-                        this.parentEndpointName = Base64.decode2UTFString(parts[8]);
-                    } catch (NumberFormatException e) {
-
-                    }
+        if (text == null) {
+            return this;
+        }
+        // if this carrier is initialized by v2, don't do deserialize again for performance.
+        if (this.isValid(HeaderVersion.v2)) {
+            return this;
+        }
+        if (HeaderVersion.v2 == version) {
+            String[] parts = text.split("-", 9);
+            if (parts.length == 9) {
+                try {
+                    // parts[0] is sample flag, always trace if header exists.
+                    this.primaryDistributedTraceId = new PropagatedTraceId(Base64.decode2UTFString(parts[1]));
+                    this.traceSegmentId = new ID(Base64.decode2UTFString(parts[2]));
+                    this.spanId = Integer.parseInt(parts[3]);
+                    this.parentServiceInstanceId = Integer.parseInt(parts[4]);
+                    this.entryServiceInstanceId = Integer.parseInt(parts[5]);
+                    this.peerHost = Base64.decode2UTFString(parts[6]);
+                    this.entryEndpointName = Base64.decode2UTFString(parts[7]);
+                    this.parentEndpointName = Base64.decode2UTFString(parts[8]);
+                } catch (NumberFormatException ignored) {
+
                 }
-            } else {
-                throw new IllegalArgumentException("Unimplemented header version." + version);
             }
         }
-        return this;
+        throw new IllegalArgumentException("Unimplemented header version." + version);
 
 Review comment:
   Don't throw an exception in agent core API. Output a warning log.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services