Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync it up #489

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
174 changes: 87 additions & 87 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</modules>

<properties>
<opentracing.version>0.22.0</opentracing.version>
<opentracing.version>0.33.0</opentracing.version>
<java.compiler.target.version>1.8</java.compiler.target.version>
<java.compiler.source.version>1.8</java.compiler.source.version>
<jmh.version>1.9.3</jmh.version>
Expand Down Expand Up @@ -440,91 +440,91 @@

</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${maven.staging.plugin}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.pluign}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
<!-- <profiles>-->
<!-- <profile>-->
<!-- <id>release</id>-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.sonatype.plugins</groupId>-->
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
<!--&lt;!&ndash; <version>${maven.staging.plugin}</version>&ndash;&gt;-->
<!-- <extensions>true</extensions>-->
<!-- <configuration>-->
<!-- <serverId>ossrh</serverId>-->
<!-- <nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
<!-- <autoReleaseAfterClose>false</autoReleaseAfterClose>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!--&lt;!&ndash; <version>${maven.gpg.pluign}</version>&ndash;&gt;-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- <distributionManagement>-->
<!-- <snapshotRepository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/content/repositories/snapshots</url>-->
<!-- </snapshotRepository>-->
<!-- <repository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>-->
<!-- </repository>-->
<!-- </distributionManagement>-->
<!-- </profile>-->

<profile>
<id>snapshot</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${maven.staging.plugin}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven.gpg.pluign}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
<!-- <profile>-->
<!-- <id>snapshot</id>-->
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.sonatype.plugins</groupId>-->
<!-- <artifactId>nexus-staging-maven-plugin</artifactId>-->
<!-- <version>${maven.staging.plugin}</version>-->
<!-- <extensions>true</extensions>-->
<!-- <configuration>-->
<!-- <serverId>ossrh</serverId>-->
<!-- <nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
<!-- <autoReleaseAfterClose>false</autoReleaseAfterClose>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>${maven.gpg.pluign}</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- <distributionManagement>-->
<!-- <snapshotRepository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/content/repositories/snapshots</url>-->
<!-- </snapshotRepository>-->
<!-- <repository>-->
<!-- <id>ossrh</id>-->
<!-- <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>-->
<!-- </repository>-->
<!-- </distributionManagement>-->
<!-- </profile>-->
<!-- </profiles>-->
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ private Result doClientFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat
//restore parent
sofaTraceContext.push(clientSpan.getParentSofaTracerSpan());
}







}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
//reserve
this.addStat(statKey, values);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alipay.common.tracer.core.holder.SofaTraceContextHolder;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.common.tracer.core.tracer.AbstractTracer;
import io.opentracing.Scope;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
Expand Down Expand Up @@ -58,17 +59,20 @@ public void process(HttpRequest httpRequest, HttpContext httpContext) throws Htt
super.appendHttpClientRequestSpanTags(httpRequest, httpClientSpan);
//async handle
httpContext.setAttribute(CURRENT_ASYNC_HTTP_SPAN_KEY, httpClientSpan);
SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
//client span
if (httpClientSpan.getParentSofaTracerSpan() != null) {
//restore parent
sofaTraceContext.push(httpClientSpan.getParentSofaTracerSpan());
} else {
//pop async span
sofaTraceContext.pop();
}
// SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
// //client span
// if (httpClientSpan.getParentSofaTracerSpan() != null) {
// //restore parent
// sofaTraceContext.push(httpClientSpan.getParentSofaTracerSpan());
// } else {
// //pop async span
// sofaTraceContext.pop();
// }
}




@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException,
IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alipay.common.tracer.core.holder.SofaTraceContextHolder;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.common.tracer.core.tracer.AbstractTracer;
import io.opentracing.Scope;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
Expand Down Expand Up @@ -61,12 +62,16 @@ public void process(HttpRequest httpRequest, HttpContext httpContext) throws Htt
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext) throws HttpException,
IOException {
SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
SofaTracerSpan httpClientSpan = sofaTraceContext.getCurrentSpan();
// SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
// SofaTracerSpan httpClientSpan = sofaTraceContext.getCurrentSpan();
SofaTracerSpan httpClientSpan = (SofaTracerSpan) httpClientTracer.getSofaTracer().activeSpan();
//tag append
super.appendHttpClientResponseSpanTags(httpResponse, httpClientSpan);
//finish
int statusCode = httpResponse.getStatusLine().getStatusCode();
httpClientTracer.clientReceive(String.valueOf(statusCode));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.alipay.sofa.tracer.plugins.httpclient.base.AbstractTestBase;
import com.alipay.sofa.tracer.plugins.httpclient.base.client.HttpAsyncClientInstance;
import com.alipay.sofa.tracer.plugins.httpclient.base.controller.PostBody;
import io.opentracing.Scope;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -98,26 +99,45 @@ private void testAsyncHttpClientPost(int expectedLength) throws Exception {
"HttpClientTracer Baggage").start();
sofaTracerParentSpan.setBaggageItem("key1", "baggage1");
sofaTracerParentSpan.setBaggageItem("key2", "baggage2");
sofaTraceContext.push(sofaTracerParentSpan);

String responseStr = new HttpAsyncClientInstance().executePost(httpUrl,
try(Scope scope = sofaTracer.scopeManager().activate(sofaTracerParentSpan)){
String responseStr = new HttpAsyncClientInstance().executePost(httpUrl,
JSON.toJSONString(postBody));

PostBody resultPostBody = JSON.parseObject(responseStr, PostBody.class);
assertEquals(postBody, resultPostBody);
PostBody resultPostBody = JSON.parseObject(responseStr, PostBody.class);
assertEquals(postBody, resultPostBody);

assertEquals(sofaTraceContext.getCurrentSpan(), sofaTracerParentSpan);
//wait for async output
List<String> contents = FileUtils
assertEquals(sofaTracer.activeSpan(), sofaTracerParentSpan);
List<String> contents = FileUtils
.readLines(customFileLog(HttpClientLogEnum.HTTP_CLIENT_DIGEST.getDefaultLogName()));
assertTrue(contents.size() == expectedLength);

// stat log print cycle: 1s
Thread.sleep(1000);

//stat log
List<String> statContents = FileUtils
.readLines(customFileLog(HttpClientLogEnum.HTTP_CLIENT_STAT.getDefaultLogName()));
assertTrue(statContents.size() == expectedLength);
assertTrue(contents.size() == expectedLength);
// stat log print cycle: 1s
Thread.sleep(1000);

//stat log
List<String> statContents = FileUtils
.readLines(customFileLog(HttpClientLogEnum.HTTP_CLIENT_STAT.getDefaultLogName()));
assertTrue(statContents.size() == expectedLength);
}
// sofaTraceContext.push(sofaTracerParentSpan);
//
// String responseStr = new HttpAsyncClientInstance().executePost(httpUrl,
// JSON.toJSONString(postBody));
//
// PostBody resultPostBody = JSON.parseObject(responseStr, PostBody.class);
// assertEquals(postBody, resultPostBody);
//
// assertEquals(sofaTraceContext.getCurrentSpan(), sofaTracerParentSpan);
// //wait for async output
// List<String> contents = FileUtils
// .readLines(customFileLog(HttpClientLogEnum.HTTP_CLIENT_DIGEST.getDefaultLogName()));
// assertTrue(contents.size() == expectedLength);
//
// // stat log print cycle: 1s
// Thread.sleep(1000);
//
// //stat log
// List<String> statContents = FileUtils
// .readLines(customFileLog(HttpClientLogEnum.HTTP_CLIENT_STAT.getDefaultLogName()));
// assertTrue(statContents.size() == expectedLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.alipay.common.tracer.core.tracer.AbstractTracer;
import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.sofa.tracer.plugins.okhttp.OkHttpRequestCarrier;
import io.opentracing.Scope;
import okhttp3.Headers;
import okhttp3.Request;
import okhttp3.Response;
Expand Down Expand Up @@ -53,9 +54,16 @@ public SofaTracerOkHttpInterceptor(AbstractTracer okHttpTracer, String appName,
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = null;
SofaTracer sofaTracer = okHttpTracer.getSofaTracer();
SofaTracerSpan sofaTracerSpan = okHttpTracer.clientSend(request.method());
Response response = chain.proceed(appendOkHttpRequestSpanTags(request, sofaTracerSpan));
okHttpTracer.clientReceive(String.valueOf(response.code()));
try(Scope scope = sofaTracer.scopeManager().activate(sofaTracerSpan)){
response = chain.proceed(appendOkHttpRequestSpanTags(request, sofaTracerSpan));
okHttpTracer.clientReceive(String.valueOf(response.code()));
} finally {
sofaTracerSpan.finish();
}

return response;
}

Expand Down
Loading