Skip to content
Merged
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
16 changes: 16 additions & 0 deletions demo/docker-build-config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Huawei Technologies Co., Ltd
~
~ Licensed 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">
Expand Down
20 changes: 18 additions & 2 deletions demo/docker-run-config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Huawei Technologies Co., Ltd
~
~ Licensed 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">
Expand All @@ -25,12 +40,13 @@
<alias>service-center</alias>
<run>
<wait>
<log>listen on server</log>
<tcp>
<ports>
<port>30100</port>
</ports>
</tcp>
<time>60000</time>
<time>60000</time>
</wait>
<ports>
<port>service.center.port:30100</port>
Expand All @@ -40,7 +56,7 @@
<image>
<name>${demo.service.name}:${project.version}</name>
<alias>${demo.service.name}</alias>
<run>
<run>
<env>
<JAVA_OPTS>
${demo.vm.options} -Dcse.service.registry.address=http://sc.servicecomb.io:30100 -Dcse.service.publishAddress=${docker.hostname}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Span {
String spanName() default "";
String callPath() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ class ZipkinSpanAspect {

@Around("execution(@io.servicecomb.tracing.Span * *(..)) && @annotation(spanAnnotation)")
public Object advise(ProceedingJoinPoint joinPoint, Span spanAnnotation) throws Throwable {
String spanName = spanAnnotation.spanName();
String callPath = spanAnnotation.callPath();
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
LOG.debug("Generating zipkin span for method {}", method.toString());
return adviser.invoke(method.getName(), method.toString(), joinPoint::proceed);
if ("".equals(spanName)) {
spanName = method.getName();
}
if ("".equals(callPath)) {
callPath = method.toString();
}

return adviser.invoke(spanName, callPath, joinPoint::proceed);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import brave.internal.StrictCurrentTraceContext;
import io.servicecomb.tracing.zipkin.ZipkinSpanAspectTest.TracingConfig;
import io.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication;
import io.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication.CustomSpanTask;
import io.servicecomb.tracing.zipkin.app.ZipkinSpanTestApplication.SomeSlowTask;
import zipkin.Span;

Expand All @@ -53,6 +54,9 @@ public class ZipkinSpanAspectTest {

@Autowired
private SomeSlowTask someSlowTask;

@Autowired
private CustomSpanTask customSpanTask;

@Autowired
private Tracing tracing;
Expand All @@ -72,6 +76,17 @@ public void reportedSpanContainsAnnotatedMethodInfo() throws Exception {
assertThat(span.name, is("crawl"));
assertThat(tracedValues(span), contains(SomeSlowTask.class.getMethod("crawl").toString()));
}

@Test
public void reportCustomSpanInfomation() throws Exception {
customSpanTask.invoke();
await().atMost(2, SECONDS).until(() -> !spans.isEmpty());

zipkin.Span span = spans.poll();
assertThat(span.name, is("transaction1"));
assertThat(tracedValues(span), contains("startA"));

}

private List<String> tracedValues(zipkin.Span spans) {
return spans.binaryAnnotations.stream()
Expand All @@ -97,4 +112,4 @@ Tracing tracing(Queue<Span> spans) {
.build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,23 @@ public static void main(String[] args) {
SomeSlowTask someSlowTask() {
return new SomeSlowTask();
}

@Bean
CustomSpanTask customSpanTask() {
return new CustomSpanTask();
}

public static class SomeSlowTask {
@Span
public String crawl() {
return "crawling...";
}
}

public static class CustomSpanTask {
@Span(spanName = "transaction1", callPath = "startA")
public String invoke() {
return "invoke the method";
}
}
}