parent
5c51f5af2c
commit
cf93d1eee1
|
|
@ -10,7 +10,7 @@
|
|||
<artifactId>skywalking-dubbo-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-plugin</name>
|
||||
<name>dubbo-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
<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>skywalking-sdk-plugin</artifactId>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-httpclient-4.3.x-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>httpclient-4.3.x-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.ai.cloud.skywalking.plugin.httpclient.v43x;
|
||||
|
||||
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointSender;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
import com.ai.cloud.skywalking.model.Identification;
|
||||
import org.apache.http.HttpRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HttpClientTracing {
|
||||
|
||||
private static RPCBuriedPointSender sender = new RPCBuriedPointSender();
|
||||
|
||||
public static <R> R execute(String url, String traceHearName, HttpRequest httpRequest, Executor<R> executor) throws IOException {
|
||||
if (!AuthDesc.isAuth()) {
|
||||
return executor.execute();
|
||||
}
|
||||
|
||||
try {
|
||||
httpRequest.setHeader(traceHearName,
|
||||
"ContextData=" + sender.beforeSend(Identification.newBuilder()
|
||||
.viewPoint(url)
|
||||
.spanType("W")
|
||||
.build())
|
||||
.toString());
|
||||
return executor.execute();
|
||||
} catch (IOException e) {
|
||||
sender.handleException(e);
|
||||
throw e;
|
||||
} finally {
|
||||
sender.afterSend();
|
||||
}
|
||||
}
|
||||
|
||||
public interface Executor<R> {
|
||||
R execute() throws IOException;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
package com.ai.cloud.skywalking.plugin.httpclient.v43x;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SWTracingCloseableHttpClient extends CloseableHttpClient {
|
||||
private static final String DEFAULT_TRACE_NAME = "SkyWalking-TRACING-NAME";
|
||||
|
||||
private CloseableHttpClient client;
|
||||
private String traceHeaderName;
|
||||
|
||||
public SWTracingCloseableHttpClient(CloseableHttpClient client, String traceHeaderName) {
|
||||
this.client = client;
|
||||
if (traceHeaderName == null || traceHeaderName.length() <= 0) {
|
||||
throw new IllegalArgumentException("Trace header name can not be null");
|
||||
}
|
||||
this.traceHeaderName = traceHeaderName;
|
||||
}
|
||||
|
||||
public SWTracingCloseableHttpClient(CloseableHttpClient client) {
|
||||
this.client = client;
|
||||
this.traceHeaderName = DEFAULT_TRACE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpParams getParams() {
|
||||
return client.getParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientConnectionManager getConnectionManager() {
|
||||
return client.getConnectionManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<CloseableHttpResponse>() {
|
||||
@Override
|
||||
public CloseableHttpResponse execute() throws IOException {
|
||||
return client.execute(request);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpResponse execute(final HttpUriRequest request, final HttpContext context) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<CloseableHttpResponse>() {
|
||||
@Override
|
||||
public CloseableHttpResponse execute() throws IOException {
|
||||
return client.execute(request, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<CloseableHttpResponse>() {
|
||||
@Override
|
||||
public CloseableHttpResponse execute() throws IOException {
|
||||
return client.execute(target, request);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CloseableHttpResponse doExecute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<CloseableHttpResponse>() {
|
||||
@Override
|
||||
public CloseableHttpResponse execute() throws IOException {
|
||||
return client.execute(target, request, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloseableHttpResponse execute(final HttpHost target, final HttpRequest request, final HttpContext context) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<CloseableHttpResponse>() {
|
||||
@Override
|
||||
public CloseableHttpResponse execute() throws IOException {
|
||||
return client.execute(target, request, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(final HttpUriRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
|
||||
@Override
|
||||
public T execute() throws IOException {
|
||||
return client.execute(request, responseHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(final HttpUriRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(request.getURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
|
||||
@Override
|
||||
public T execute() throws IOException {
|
||||
return client.execute(request, responseHandler, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
|
||||
@Override
|
||||
public T execute() throws IOException {
|
||||
return client.execute(target, request, responseHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T execute(final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException {
|
||||
return HttpClientTracing.execute(target.toURI().toString(), traceHeaderName, request, new HttpClientTracing.Executor<T>() {
|
||||
@Override
|
||||
public T execute() throws IOException {
|
||||
return client.execute(target, request, responseHandler, context);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<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>skywalking-sdk-plugin</artifactId>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-httpClient-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>httpClient-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<artifactId>skywalking-jdbc-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-plugin</name>
|
||||
<name>jdbc-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
<module>spring-plugin</module>
|
||||
<module>jdbc-plugin</module>
|
||||
<module>web-plugin</module>
|
||||
<module>httpclient-plugin</module>
|
||||
<module>httpclient-4.2.x-plugin</module>
|
||||
<module>httpclient-4.3.x-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
@ -50,4 +51,13 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<!--发布-->
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>company-private-nexus-library-snapshots</id>
|
||||
<name>company-private-nexus-library-snapshots</name>
|
||||
<url>http://10.1.228.199:18081/nexus/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<artifactId>skywalking-web-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-plugin</name>
|
||||
<name>web-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
Loading…
Reference in New Issue