You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2020/12/06 13:14:31 UTC
[skywalking] branch master updated: Fix jdk-http and okhttp-3.x
plugin did not overwrite the old trace header. (#5958)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new c24dbd6 Fix jdk-http and okhttp-3.x plugin did not overwrite the old trace header. (#5958)
c24dbd6 is described below
commit c24dbd6ec14e809d2960cc8e3303261984dfd87a
Author: zifeihan <re...@gmail.com>
AuthorDate: Sun Dec 6 21:14:12 2020 +0800
Fix jdk-http and okhttp-3.x plugin did not overwrite the old trace header. (#5958)
* Fix jdk-http and okhttp-3.x did not overwrite the old trace header.
* Update CHANGES.md.
---
CHANGES.md | 2 +-
.../apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java | 2 +-
.../apm/plugin/jdk/http/HttpClientWriteRequestInterceptor.java | 2 +-
.../skywalking/apm/testcase/jdkhttp/controller/CaseController.java | 2 ++
.../apache/skywalking/testcase/okhttp/controller/CaseController.java | 5 ++++-
5 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index a0933d8..ec78051 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -8,7 +8,7 @@ Release Notes.
* Chore: adapt `create_source_release.sh` to make it runnable on Linux.
#### Java Agent
-
+* Fix jdk-http and okhttp-3.x plugin did not overwrite the old trace header.
#### OAP-Backend
* Make meter receiver support MAL.
diff --git a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
index 8b1a12b..b88f846 100644
--- a/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
+++ b/apm-sniffer/apm-sdk-plugin/okhttp-3.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/okhttp/v3/RealCallInterceptor.java
@@ -74,7 +74,7 @@ public class RealCallInterceptor implements InstanceMethodsAroundInterceptor, In
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
- headerBuilder.add(next.getHeadKey(), next.getHeadValue());
+ headerBuilder.set(next.getHeadKey(), next.getHeadValue());
}
headersField.set(request, headerBuilder.build());
}
diff --git a/apm-sniffer/bootstrap-plugins/jdk-http-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/http/HttpClientWriteRequestInterceptor.java b/apm-sniffer/bootstrap-plugins/jdk-http-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/http/HttpClientWriteRequestInterceptor.java
index 37d6677..58298b3 100644
--- a/apm-sniffer/bootstrap-plugins/jdk-http-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/http/HttpClientWriteRequestInterceptor.java
+++ b/apm-sniffer/bootstrap-plugins/jdk-http-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdk/http/HttpClientWriteRequestInterceptor.java
@@ -52,7 +52,7 @@ public class HttpClientWriteRequestInterceptor implements InstanceMethodsAroundI
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
- headers.add(next.getHeadKey(), next.getHeadValue());
+ headers.set(next.getHeadKey(), next.getHeadValue());
}
}
diff --git a/test/plugin/scenarios/jdk-http-scenario/src/main/java/org/apache/skywalking/apm/testcase/jdkhttp/controller/CaseController.java b/test/plugin/scenarios/jdk-http-scenario/src/main/java/org/apache/skywalking/apm/testcase/jdkhttp/controller/CaseController.java
index 8310a16..4ff7fca 100644
--- a/test/plugin/scenarios/jdk-http-scenario/src/main/java/org/apache/skywalking/apm/testcase/jdkhttp/controller/CaseController.java
+++ b/test/plugin/scenarios/jdk-http-scenario/src/main/java/org/apache/skywalking/apm/testcase/jdkhttp/controller/CaseController.java
@@ -38,9 +38,11 @@ public class CaseController {
@RequestMapping("/jdk-http-scenario")
@ResponseBody
public String testcase() throws IOException {
+ // Like gateway forward trace header.
URL url = new URL("http://localhost:8080/jdk-http-scenario/case/receiveContext-0");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty("key", "value");
+ connection.addRequestProperty("sw8", "123456");
int responseCode = connection.getResponseCode();
return "Success:" + responseCode;
}
diff --git a/test/plugin/scenarios/okhttp-scenario/src/main/java/test/apache/skywalking/testcase/okhttp/controller/CaseController.java b/test/plugin/scenarios/okhttp-scenario/src/main/java/test/apache/skywalking/testcase/okhttp/controller/CaseController.java
index ace50a9..efbe4b7 100644
--- a/test/plugin/scenarios/okhttp-scenario/src/main/java/test/apache/skywalking/testcase/okhttp/controller/CaseController.java
+++ b/test/plugin/scenarios/okhttp-scenario/src/main/java/test/apache/skywalking/testcase/okhttp/controller/CaseController.java
@@ -47,7 +47,9 @@ public class CaseController {
@RequestMapping("/okhttp-case")
@ResponseBody
public String okHttpScenario() {
- Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-0").build();
+ // Like gateway forward trace header.
+ Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-0")
+ .header("sw8", "123456").build();
new OkHttpClient().newCall(request).enqueue(new Callback() {
@Override
@@ -58,6 +60,7 @@ public class CaseController {
@Override
public void onResponse(Call call, Response response) throws IOException {
Request request = new Request.Builder().url("http://127.0.0.1:8080/okhttp-case/case/receiveContext-1")
+ .header("sw8", "123456")
.build();
new OkHttpClient().newCall(request).execute();
}