Skip to content

Commit b3e38a9

Browse files
author
Adrian Cole
committed
Exposes DependencyLinkSpan.from for use in spark job
1 parent 9e31cc3 commit b3e38a9

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

zipkin/src/main/java/zipkin/internal/DependencyLinkSpan.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
*/
1414
package zipkin.internal;
1515

16-
import static java.lang.String.format;
16+
import zipkin.Annotation;
17+
import zipkin.BinaryAnnotation;
18+
import zipkin.Constants;
19+
import zipkin.Span;
20+
1721
import static zipkin.internal.Util.checkNotNull;
1822
import static zipkin.internal.Util.equal;
1923

@@ -66,6 +70,24 @@ public static Builder builder(Long parentId, long spanId){
6670
return new Builder(parentId, spanId);
6771
}
6872

73+
public static DependencyLinkSpan from(Span s) {
74+
DependencyLinkSpan.Builder linkSpan = DependencyLinkSpan.builder(s.parentId, s.id);
75+
for (BinaryAnnotation a : s.binaryAnnotations) {
76+
if (a.key.equals(Constants.CLIENT_ADDR) && a.endpoint != null) {
77+
linkSpan.caService(a.endpoint.serviceName);
78+
} else if (a.key.equals(Constants.SERVER_ADDR) && a.endpoint != null) {
79+
linkSpan.saService(a.endpoint.serviceName);
80+
}
81+
}
82+
for (Annotation a : s.annotations) {
83+
if (a.value.equals(Constants.SERVER_RECV) && a.endpoint != null) {
84+
linkSpan.srService(a.endpoint.serviceName);
85+
break;
86+
}
87+
}
88+
return linkSpan.build();
89+
}
90+
6991
public static final class Builder {
7092
private final Long parentId;
7193
private final long spanId;

zipkin/src/main/java/zipkin/storage/InMemorySpanStore.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.TreeSet;
2727
import zipkin.Annotation;
2828
import zipkin.BinaryAnnotation;
29-
import zipkin.Constants;
3029
import zipkin.DependencyLink;
3130
import zipkin.Span;
3231
import zipkin.internal.ApplyTimestampAndDuration;
@@ -168,21 +167,7 @@ public List<DependencyLink> getDependencies(long endTs, @Nullable Long lookback)
168167
timestamp > endTs) {
169168
continue;
170169
}
171-
DependencyLinkSpan.Builder linkSpan = DependencyLinkSpan.builder(s.parentId, s.id);
172-
for (BinaryAnnotation a : s.binaryAnnotations) {
173-
if (a.key.equals(Constants.CLIENT_ADDR) && a.endpoint != null) {
174-
linkSpan.caService(a.endpoint.serviceName);
175-
} else if (a.key.equals(Constants.SERVER_ADDR) && a.endpoint != null) {
176-
linkSpan.saService(a.endpoint.serviceName);
177-
}
178-
}
179-
for (Annotation a : s.annotations) {
180-
if (a.value.equals(Constants.SERVER_RECV) && a.endpoint != null) {
181-
linkSpan.srService(a.endpoint.serviceName);
182-
break;
183-
}
184-
}
185-
linkSpans.add(linkSpan.build());
170+
linkSpans.add(DependencyLinkSpan.from(s));
186171
}
187172

188173
linksBuilder.putTrace(linkSpans.iterator());

0 commit comments

Comments
 (0)