Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a55f143
fix
peachisai Oct 18, 2025
d79fb55
fix
peachisai Oct 22, 2025
711963c
fix
peachisai Oct 22, 2025
6207a80
Fix
peachisai Oct 23, 2025
eba26a2
Fix
peachisai Oct 23, 2025
0e30316
Fix
peachisai Oct 23, 2025
508f01b
Fix
peachisai Oct 23, 2025
c214ede
Fix
peachisai Oct 23, 2025
3a218aa
Fix
peachisai Oct 23, 2025
9d5205f
Fix
peachisai Oct 23, 2025
b7076cc
Fix
peachisai Oct 23, 2025
20eb38a
Fix
peachisai Oct 23, 2025
80e9003
Fix
peachisai Oct 24, 2025
626a629
Fix
peachisai Oct 24, 2025
f9411ff
Fix
peachisai Oct 24, 2025
9a8f830
Fix
peachisai Oct 24, 2025
45b14f2
Fix
peachisai Oct 24, 2025
1853b42
Fix
peachisai Oct 24, 2025
c091b25
Fix
peachisai Oct 24, 2025
4e415f4
Fix
peachisai Oct 24, 2025
2392140
Fix
peachisai Oct 24, 2025
bfd2f4c
Fix
peachisai Oct 24, 2025
4431e59
Fix
peachisai Oct 24, 2025
70ce00c
Fix
peachisai Oct 24, 2025
4aba780
Fix
peachisai Oct 24, 2025
91f3eec
Fix
peachisai Oct 25, 2025
f4ed10b
Fix
peachisai Oct 25, 2025
461e90c
Fix
peachisai Oct 25, 2025
d8b3072
Fix
peachisai Oct 26, 2025
87aeeab
Fix
peachisai Oct 26, 2025
e01f6ad
Merge pull request #15 from peachisai/uat
peachisai Oct 26, 2025
1b72de9
Fix
peachisai Oct 26, 2025
b394856
Fix
peachisai Oct 26, 2025
2a45fe2
Fix
peachisai Oct 26, 2025
8932f85
Merge pull request #16 from peachisai/uat
peachisai Oct 26, 2025
8387a6c
Fix
peachisai Nov 2, 2025
a976175
Fix
peachisai Nov 2, 2025
88e0982
Merge pull request #17 from peachisai/uat
peachisai Nov 2, 2025
e29f1d0
Fix
peachisai Nov 2, 2025
64377df
Fix
peachisai Nov 2, 2025
e62c17c
Fix
peachisai Nov 2, 2025
dcf1013
Fix
peachisai Nov 2, 2025
b58fa70
Merge pull request #18 from peachisai/uat
peachisai Nov 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/plugins-jdk11-test.3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
matrix:
case:
- jdk11-forkjoinpool-scenario
- jdk-httpclient-scenario
steps:
- uses: actions/checkout@v2
with:
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Release Notes.
* Fix ClassLoader cache OOM issue with WeakHashMap.
* Fix Jetty client cannot receive the HTTP response body.
* Eliminate repeated code with HttpServletRequestWrapper in mvc-annotation-commons.
* Add the jdk httpclient plugin.

All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/242?closed=1)

Expand Down
46 changes: 46 additions & 0 deletions apm-sniffer/bootstrap-plugins/jdk-httpclient-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bootstrap-plugins</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>9.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apm-jdk-httpclient-plugin</artifactId>
<packaging>jar</packaging>

<name>apm-jdk-httpclient-plugin</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.skywalking.apm.plugin;

import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;

import java.lang.reflect.Method;
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class HttpClientSendAsyncInterceptor implements InstanceMethodsAroundInterceptor {

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
HttpRequest request = (HttpRequest) allArguments[0];
URI uri = request.uri();

ContextCarrier contextCarrier = new ContextCarrier();
AbstractSpan span = ContextManager.createExitSpan(buildOperationName(request.method(), uri), contextCarrier, getPeer(uri));

if (request instanceof EnhancedInstance) {
((EnhancedInstance) request).setSkyWalkingDynamicField(contextCarrier);
}

span.setComponent(ComponentsDefine.JDK_HTTP);
Tags.HTTP.METHOD.set(span, request.method());
Tags.URL.set(span, String.valueOf(uri));
SpanLayer.asHttp(span);
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {

if (ContextManager.isActive()) {
AbstractSpan span = ContextManager.activeSpan();
span.prepareForAsync();

if (ret != null) {
CompletableFuture<?> future = (CompletableFuture<?>) ret;
ret = future.whenComplete((response, throwable) -> {
try {
if (throwable != null) {
span.errorOccurred();
span.log(throwable);
return;
}
if (response instanceof HttpResponse) {
HttpResponse<?> httpResponse = (HttpResponse<?>) response;
int statusCode = httpResponse.statusCode();
Tags.HTTP_RESPONSE_STATUS_CODE.set(span, statusCode);
if (statusCode >= 400) {
span.errorOccurred();
}
}
} finally {
span.asyncFinish();
}
});
} else {
Map<String, String> eventMap = new HashMap<String, String>();
eventMap.put("error", "No response");
span.log(System.currentTimeMillis(), eventMap);
span.errorOccurred();
}
ContextManager.stopSpan();
}
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
ContextManager.activeSpan().log(t);
}
}

private String buildOperationName(String method, URI uri) {
String path = uri.getPath();
if (path == null || path.isEmpty()) {
path = "/";
}
return method + ":" + path;
}

private String getPeer(URI uri) {
String host = uri.getHost();
int port = uri.getPort();

if (port == -1) {
port = "https".equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
}

return host + ":" + port;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.skywalking.apm.plugin;

import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;

import java.lang.reflect.Method;
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;

public class HttpClientSendInterceptor implements InstanceMethodsAroundInterceptor {

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
HttpRequest request = (HttpRequest) allArguments[0];
URI uri = request.uri();

ContextCarrier contextCarrier = new ContextCarrier();
AbstractSpan span = ContextManager.createExitSpan(buildOperationName(request.method(), uri), contextCarrier, getPeer(uri));

if (request instanceof EnhancedInstance) {
((EnhancedInstance) request).setSkyWalkingDynamicField(contextCarrier);
}

span.setComponent(ComponentsDefine.JDK_HTTP);
Tags.HTTP.METHOD.set(span, request.method());
Tags.URL.set(span, String.valueOf(uri));
SpanLayer.asHttp(span);
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {

if (ContextManager.isActive()) {
AbstractSpan span = ContextManager.activeSpan();
if (ret != null) {
HttpResponse<?> response = (HttpResponse<?>) ret;
int statusCode = response.statusCode();

Tags.HTTP_RESPONSE_STATUS_CODE.set(span, response.statusCode());
if (statusCode >= 400) {
span.errorOccurred();
}
} else {
Map<String, String> eventMap = new HashMap<String, String>();
eventMap.put("error", "No response");
span.log(System.currentTimeMillis(), eventMap);
span.errorOccurred();
}

ContextManager.stopSpan();
}
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
ContextManager.activeSpan().log(t);
}
}

private String buildOperationName(String method, URI uri) {
String path = uri.getPath();
if (path == null || path.isEmpty()) {
path = "/";
}
return method + ":" + path;
}

private String getPeer(URI uri) {
String host = uri.getHost();
int port = uri.getPort();

if (port == -1) {
port = "https".equalsIgnoreCase(uri.getScheme()) ? 443 : 80;
}

return host + ":" + port;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.apache.skywalking.apm.plugin;

import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;

import java.lang.reflect.Method;
import java.net.http.HttpHeaders;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HttpRequestHeadersInterceptor implements InstanceMethodsAroundInterceptor {

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {

}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {

ContextCarrier contextCarrier = (ContextCarrier) objInst.getSkyWalkingDynamicField();
HttpHeaders originalHeaders = (HttpHeaders) ret;
final Map<String, List<String>> headerMap = new HashMap<>(originalHeaders.map());
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
headerMap.put(next.getHeadKey(), List.of(next.getHeadValue()));
}

return HttpHeaders.of(headerMap, (k, v) -> true);
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
ContextManager.activeSpan().log(t);
}
}
}
Loading
Loading