本文整理了Java中zipkin2.Span.kind()
方法的一些代码示例,展示了Span.kind()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.kind()
方法的具体详情如下:
包路径:zipkin2.Span
类名称:Span
方法名:kind
[英]When present, used to interpret #remoteEndpoint
[中]出现时,用于解释#remoteEndpoint
代码示例来源:origin: openzipkin/brave
@Test
public void reportsServerKindToZipkin() throws Exception {
get("/foo");
Span span = takeSpan();
assertThat(span.kind())
.isEqualTo(Span.Kind.SERVER);
}
代码示例来源:origin: openzipkin/brave
@Test public void reportsClientKindToZipkin() throws Exception {
server.enqueue(new MockResponse());
get(client, "/foo");
Span span = takeSpan();
assertThat(span.kind())
.isEqualTo(Span.Kind.CLIENT);
}
代码示例来源:origin: line/armeria
@Test(timeout = 20000)
public void shouldSubmitSpanWhenRequestIsSampled() throws Exception {
final SpanCollectingReporter reporter = testServiceInvocation(1.0f);
// check span name
final Span span = reporter.spans().take();
assertThat(span.name()).isEqualTo(TEST_METHOD);
// check kind
assertThat(span.kind()).isSameAs(Kind.SERVER);
// only one span should be submitted
assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
// check # of annotations (we add wire annotations)
assertThat(span.annotations()).hasSize(2);
// check tags
assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
"http.host", "foo.com",
"http.method", "POST",
"http.path", "/hello/trustin",
"http.status_code", "200",
"http.url", "none+h2c://foo.com/hello/trustin"));
// check service name
assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
}
代码示例来源:origin: openzipkin/brave
@Test public void redirect() throws Exception {
Tracer tracer = httpTracing.tracing().tracer();
server.enqueue(new MockResponse().setResponseCode(302)
.addHeader("Location: " + url("/bar")));
server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location!
ScopedSpan parent = tracer.startScopedSpan("test");
try {
get(client, "/foo");
} catch (RuntimeException e) {
// some think 404 is an exception
} finally {
parent.finish();
}
Span client1 = takeSpan();
Span client2 = takeSpan();
assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path")))
.contains("/foo", "/bar");
assertThat(takeSpan().kind()).isNull(); // local
}
代码示例来源:origin: line/armeria
@Test(timeout = 20000)
public void shouldSubmitSpanWhenSampled() throws Exception {
final SpanCollectingReporter reporter = new SpanCollectingReporter();
final Tracing tracing = Tracing.newBuilder()
.localServiceName(TEST_SERVICE)
.spanReporter(reporter)
.sampler(Sampler.create(1.0f))
.build();
testRemoteInvocation(tracing, null);
// check span name
final Span span = reporter.spans().take();
assertThat(span.name()).isEqualTo(TEST_SPAN);
// check kind
assertThat(span.kind()).isSameAs(Kind.CLIENT);
// only one span should be submitted
assertThat(reporter.spans().poll(1, TimeUnit.SECONDS)).isNull();
// check # of annotations (we add wire annotations)
assertThat(span.annotations()).hasSize(2);
// check tags
assertThat(span.tags()).containsAllEntriesOf(ImmutableMap.of(
"http.host", "foo.com",
"http.method", "POST",
"http.path", "/hello/armeria",
"http.status_code", "200",
"http.url", "none+h2c://foo.com/hello/armeria"));
// check service name
assertThat(span.localServiceName()).isEqualTo(TEST_SERVICE);
// check remote service name
assertThat(span.remoteServiceName()).isEqualTo("foo.com");
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin
Span firstRemoteAncestor(SpanNode current) {
SpanNode ancestor = current.parent();
while (ancestor != null) {
Span maybeRemote = ancestor.span();
if (maybeRemote != null && maybeRemote.kind() != null) {
if (logger.isLoggable(FINE)) logger.fine("found remote ancestor " + maybeRemote);
return maybeRemote;
}
ancestor = ancestor.parent();
}
return null;
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin
static int compareShared(Span left, Span right) {
// If either are shared put it last
boolean leftShared = Boolean.TRUE.equals(left.shared());
boolean rightShared = Boolean.TRUE.equals(right.shared());
if (leftShared && rightShared) return 0; // both are shared, so skip out
if (leftShared) return 1;
if (rightShared) return -1;
// neither are shared, put the client spans first
boolean leftClient = Span.Kind.CLIENT.equals(left.kind());
boolean rightClient = Span.Kind.CLIENT.equals(right.kind());
if (leftClient && rightClient) return 0;
if (leftClient) return -1;
if (rightClient) return 1;
return 0; // neither are client spans
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests
@Test
public void reportsServerKindToZipkin() throws Exception {
get("/foo");
Span span = takeSpan();
assertThat(span.kind())
.isEqualTo(Span.Kind.SERVER);
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests
@Test public void reportsClientKindToZipkin() throws Exception {
server.enqueue(new MockResponse());
get(client, "/foo");
Span span = takeSpan();
assertThat(span.kind())
.isEqualTo(Span.Kind.CLIENT);
}
代码示例来源:origin: Nike-Inc/wingtips
private void verifySpanPurposeRelatedStuff(zipkin2.Span zipkinSpan, Span wingtipsSpan) {
SpanPurpose spanPurpose = wingtipsSpan.getSpanPurpose();
switch(spanPurpose) {
case SERVER:
assertThat(zipkinSpan.kind()).isEqualTo(zipkin2.Span.Kind.SERVER);
break;
case CLIENT:
assertThat(zipkinSpan.kind()).isEqualTo(zipkin2.Span.Kind.CLIENT);
break;
case LOCAL_ONLY:
case UNKNOWN:
// intentional fall-through: local and unknown span purpose are treated the same way
break;
default:
throw new IllegalStateException("Unhandled spanPurpose: " + spanPurpose.name());
}
}
代码示例来源:origin: openzipkin/zipkin-finagle
@Test public void reportsSpanOn_ServerSend() throws Exception {
advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
advanceAndRecord(1, root, Annotation.ServerSend$.MODULE$);
Span span = spansSent.take();
assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
assertThat(span.annotations()).isEmpty();
assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
assertThat(span.duration()).isEqualTo(1000);
}
代码示例来源:origin: openzipkin/zipkin-finagle
@Test public void reportsSpanOn_ClientRecv() throws Exception {
advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
advanceAndRecord(1, root, Annotation.ClientRecv$.MODULE$);
Span span = spansSent.take();
assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
assertThat(span.annotations()).isEmpty();
assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
assertThat(span.duration()).isEqualTo(1000);
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra
Input newInput(zipkin2.Span span, UUID ts_uuid) {
boolean traceIdHigh = !strictTraceId && span.traceId().length() == 32;
List<AnnotationUDT> annotations;
if (!span.annotations().isEmpty()) {
annotations =
span.annotations().stream().map(AnnotationUDT::new).collect(Collectors.toList());
} else {
annotations = Collections.emptyList();
}
String annotation_query = searchEnabled ? CassandraUtil.annotationQuery(span) : null;
return new AutoValue_InsertSpan_Input(
ts_uuid,
traceIdHigh ? span.traceId().substring(0, 16) : null,
traceIdHigh ? span.traceId().substring(16) : span.traceId(),
span.parentId(),
span.id(),
span.kind() != null ? span.kind().name() : null,
span.name(),
span.timestampAsLong(),
span.durationAsLong(),
span.localEndpoint() != null ? new EndpointUDT(span.localEndpoint()) : null,
span.remoteEndpoint() != null ? new EndpointUDT(span.remoteEndpoint()) : null,
annotations,
span.tags(),
annotation_query,
Boolean.TRUE.equals(span.debug()),
Boolean.TRUE.equals(span.shared()));
}
代码示例来源:origin: openzipkin/zipkin-finagle
@Test public void reportsSpanOn_Timeout() throws Exception {
advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
advanceAndRecord(1, root, new Annotation.Message(TimeoutFilter.TimeoutAnnotation()));
Span span = spansSent.take();
assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
"finagle.timeout"
);
assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
assertThat(span.duration()).isEqualTo(1000);
}
代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests
@Test public void redirect() throws Exception {
Tracer tracer = httpTracing.tracing().tracer();
server.enqueue(new MockResponse().setResponseCode(302)
.addHeader("Location: " + url("/bar")));
server.enqueue(new MockResponse().setResponseCode(404)); // hehe to a bad location!
ScopedSpan parent = tracer.startScopedSpan("test");
try {
get(client, "/foo");
} catch (RuntimeException e) {
// some think 404 is an exception
} finally {
parent.finish();
}
Span client1 = takeSpan();
Span client2 = takeSpan();
assertThat(Arrays.asList(client1.tags().get("http.path"), client2.tags().get("http.path")))
.contains("/foo", "/bar");
assertThat(takeSpan().kind()).isNull(); // local
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin
@Override void writeValue(Buffer b, Span value) {
TRACE_ID.write(b, value.traceId());
PARENT_ID.write(b, value.parentId());
ID.write(b, value.id());
KIND.write(b, toByte(value.kind()));
NAME.write(b, value.name());
TIMESTAMP.write(b, value.timestampAsLong());
DURATION.write(b, value.durationAsLong());
LOCAL_ENDPOINT.write(b, value.localEndpoint());
REMOTE_ENDPOINT.write(b, value.remoteEndpoint());
List<Annotation> annotations = value.annotations();
int annotationLength = annotations.size();
for (int i = 0; i < annotationLength; i++) {
ANNOTATION.write(b, annotations.get(i));
}
Map<String, String> tags = value.tags();
if (!tags.isEmpty()) { // avoid allocating an iterator when empty
for (Map.Entry<String, String> entry : tags.entrySet()) {
TAG.write(b, entry);
}
}
SpanField.DEBUG.write(b, Boolean.TRUE.equals(value.debug()));
SpanField.SHARED.write(b, Boolean.TRUE.equals(value.shared()));
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin
@Override int sizeOfValue(Span span) {
int sizeOfSpan = TRACE_ID.sizeInBytes(span.traceId());
sizeOfSpan += PARENT_ID.sizeInBytes(span.parentId());
sizeOfSpan += ID.sizeInBytes(span.id());
sizeOfSpan += KIND.sizeInBytes(span.kind() != null ? 1 : 0);
sizeOfSpan += NAME.sizeInBytes(span.name());
sizeOfSpan += TIMESTAMP.sizeInBytes(span.timestampAsLong());
sizeOfSpan += DURATION.sizeInBytes(span.durationAsLong());
sizeOfSpan += LOCAL_ENDPOINT.sizeInBytes(span.localEndpoint());
sizeOfSpan += REMOTE_ENDPOINT.sizeInBytes(span.remoteEndpoint());
List<Annotation> annotations = span.annotations();
int annotationCount = annotations.size();
for (int i = 0; i < annotationCount; i++) {
sizeOfSpan += ANNOTATION.sizeInBytes(annotations.get(i));
}
Map<String, String> tags = span.tags();
int tagCount = tags.size();
if (tagCount > 0) { // avoid allocating an iterator when empty
for (Map.Entry<String, String> entry : tags.entrySet()) {
sizeOfSpan += TAG.sizeInBytes(entry);
}
}
sizeOfSpan += DEBUG.sizeInBytes(Boolean.TRUE.equals(span.debug()));
sizeOfSpan += SHARED.sizeInBytes(Boolean.TRUE.equals(span.shared()));
return sizeOfSpan;
}
代码示例来源:origin: openzipkin/zipkin-finagle
@Test public void flushesIncompleteSpans() throws Exception {
advanceAndRecord(0, root, new Annotation.Rpc("GET"));
advanceAndRecord(15, root, new Annotation.ServiceName("frontend"));
advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
// Note: there's no ServerSend() which would complete the span.
time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer
timer.tick(); // invokes a flush
Span span = spansSent.take();
assertThat(span.id()).isEqualTo(root.spanId().toString());
assertThat(span.name()).isEqualTo("get");
assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
"finagle.flush"
);
assertThat(span.duration()).isNull();
}
代码示例来源:origin: com.google.cloud.trace.adapters.zipkin/translation
TraceSpan.Builder translate(TraceSpan.Builder spanBuilder, Span zipkinSpan) {
spanBuilder.setName(zipkinSpan.name());
SpanKind kind = getSpanKind(zipkinSpan.kind());
spanBuilder.setKind(kind);
rewriteIds(zipkinSpan, spanBuilder, kind);
if (zipkinSpan.timestamp() != null) {
spanBuilder.setStartTime(createTimestamp(zipkinSpan.timestamp()));
if (zipkinSpan.duration() != null) {
Timestamp endTime = createTimestamp(zipkinSpan.timestamp() + zipkinSpan.duration());
spanBuilder.setEndTime(endTime);
}
}
spanBuilder.putAllLabels(labelExtractor.extract(zipkinSpan));
return spanBuilder;
}
代码示例来源:origin: io.netifi.proteus/proteus-tracing-openzipkin
private zipkin2.proto3.Span mapSpan(Span span) {
zipkin2.proto3.Span.Builder builder =
zipkin2.proto3.Span.newBuilder().setName(span.name()).setTraceId(span.traceId());
if (span.parentId() != null) {
builder.setParentId(span.parentId());
}
builder.setId(span.id());
if (span.kind() != null) {
builder.setKind(zipkin2.proto3.Span.Kind.valueOf(span.kind().name()));
}
builder.setTimestamp(span.timestampAsLong()).setDuration(span.durationAsLong());
if (span.localEndpoint() != null) {
builder.setLocalEndpoint(mapEndpoint(span.localEndpoint()));
}
if (span.remoteEndpoint() != null) {
builder.setRemoteEndpoint(mapEndpoint(span.remoteEndpoint()));
}
for (Annotation annotation : span.annotations()) {
builder.addAnnotations(mapAnnotation(annotation));
}
builder
.putAllTags(span.tags())
.setDebug(span.debug() == null ? false : span.debug())
.setShared(span.shared() == null ? false : span.shared())
.putTags("group", group)
.putTags("destination", destination);
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!