Search in sources :

Example 51 with Kind

use of zipkin2.Span.Kind in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceReporterTests method testSingleServerSpan.

@Test
public void testSingleServerSpan() {
    Span parent = Span.newBuilder().traceId("123").id("9999").name("http:parent").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.SERVER).build();
    this.reporter.report(parent);
    Assert.assertEquals(1, this.test.traceSpans.size());
    TraceSpan traceSpan = this.test.traceSpans.get(0);
    Assert.assertEquals("http:parent", traceSpan.getName());
    // Server Spans should use Span begin and end time, not SR or SS
    Assert.assertEquals(this.spanTranslator.createTimestamp(beginTime), traceSpan.getStartTime());
    Assert.assertEquals(this.spanTranslator.createTimestamp(endTime), traceSpan.getEndTime());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_SERVER, traceSpan.getKind());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 52 with Kind

use of zipkin2.Span.Kind in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceReporterTests method testClientServerSpans.

@Test
public void testClientServerSpans() {
    Span clientSpan = Span.newBuilder().traceId("123").id("9999").name("http:call").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.CLIENT).build();
    Span serverSpan = Span.newBuilder().traceId("123").parentId(clientSpan.id()).id(clientSpan.id()).name("http:service").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.SERVER).build();
    this.reporter.report(serverSpan);
    this.reporter.report(clientSpan);
    Assert.assertEquals(2, this.test.traceSpans.size());
    TraceSpan serverTraceSpan = this.test.traceSpans.get(0);
    Assert.assertEquals("http:service", serverTraceSpan.getName());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_SERVER, serverTraceSpan.getKind());
    TraceSpan clientTraceSpan = this.test.traceSpans.get(1);
    Assert.assertEquals("http:call", clientTraceSpan.getName());
    // Client span chould use CS and CR time, not Span begin or end time.
    Assert.assertEquals(this.spanTranslator.createTimestamp(beginTime), clientTraceSpan.getStartTime());
    Assert.assertEquals(this.spanTranslator.createTimestamp(endTime), clientTraceSpan.getEndTime());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_CLIENT, clientTraceSpan.getKind());
    Assert.assertEquals(0, clientTraceSpan.getParentSpanId());
    Assert.assertNotEquals(Long.valueOf(serverSpan.parentId()).longValue(), serverTraceSpan.getParentSpanId());
    // Even though the client and server spans shared the same Span ID. In Stackdriver Trace,
    // the IDs should be different. This is accomplished through
    // StackdriverTraceSpanListener.rewriteIds().
    Assert.assertNotEquals(clientTraceSpan.getSpanId(), serverTraceSpan.getSpanId());
    // Although the Span IDs were re-written, the server Span's parent ID should still refer
    // to client Span ID.
    Assert.assertEquals(serverTraceSpan.getParentSpanId(), clientTraceSpan.getSpanId());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with Kind

use of zipkin2.Span.Kind in project instrumentation-java by census-instrumentation.

the class ZipkinExporterHandler method generateSpan.

@SuppressWarnings("deprecation")
static Span generateSpan(SpanData spanData, Endpoint localEndpoint) {
    SpanContext context = spanData.getContext();
    long startTimestamp = toEpochMicros(spanData.getStartTimestamp());
    // TODO(sebright): Fix the Checker Framework warning.
    @SuppressWarnings("nullness") long endTimestamp = toEpochMicros(spanData.getEndTimestamp());
    // TODO(bdrutu): Fix the Checker Framework warning.
    @SuppressWarnings("nullness") Span.Builder spanBuilder = Span.newBuilder().traceId(context.getTraceId().toLowerBase16()).id(context.getSpanId().toLowerBase16()).kind(toSpanKind(spanData)).name(spanData.getName()).timestamp(toEpochMicros(spanData.getStartTimestamp())).duration(endTimestamp - startTimestamp).localEndpoint(localEndpoint);
    if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
        spanBuilder.parentId(spanData.getParentSpanId().toLowerBase16());
    }
    for (Map.Entry<String, AttributeValue> label : spanData.getAttributes().getAttributeMap().entrySet()) {
        spanBuilder.putTag(label.getKey(), attributeValueToString(label.getValue()));
    }
    Status status = spanData.getStatus();
    if (status != null) {
        spanBuilder.putTag(STATUS_CODE, status.getCanonicalCode().toString());
        if (status.getDescription() != null) {
            spanBuilder.putTag(STATUS_DESCRIPTION, status.getDescription());
        }
        if (!status.isOk()) {
            spanBuilder.putTag(STATUS_ERROR, status.getCanonicalCode().toString());
        }
    }
    for (TimedEvent<Annotation> annotation : spanData.getAnnotations().getEvents()) {
        spanBuilder.addAnnotation(toEpochMicros(annotation.getTimestamp()), annotation.getEvent().getDescription());
    }
    for (TimedEvent<io.opencensus.trace.MessageEvent> messageEvent : spanData.getMessageEvents().getEvents()) {
        spanBuilder.addAnnotation(toEpochMicros(messageEvent.getTimestamp()), messageEvent.getEvent().getType().name());
    }
    return spanBuilder.build();
}
Also used : Status(io.opencensus.trace.Status) AttributeValue(io.opencensus.trace.AttributeValue) SpanContext(io.opencensus.trace.SpanContext) Span(zipkin2.Span) Annotation(io.opencensus.trace.Annotation) Map(java.util.Map)

Example 54 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class ITTraces method getTrace_differentiatesDebugFromShared.

/**
 * Prevents subtle bugs which can result in mixed-length traces from linking.
 */
@Test
protected void getTrace_differentiatesDebugFromShared(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Span clientSpan = newClientSpan(testSuffix).toBuilder().debug(true).build();
    Span serverSpan = clientSpan.toBuilder().kind(SERVER).debug(null).shared(true).build();
    accept(clientSpan, serverSpan);
    // assertGetTraceReturns does recursive comparison
    assertGetTraceReturns(clientSpan.traceId(), asList(clientSpan, serverSpan));
}
Also used : TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 55 with Kind

use of zipkin2.Span.Kind in project zipkin by openzipkin.

the class ITTraces method getTraces_differentiatesDebugFromShared.

/**
 * Prevents subtle bugs which can result in mixed-length traces from linking.
 */
@Test
protected void getTraces_differentiatesDebugFromShared(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    Span clientSpan = newClientSpan(testSuffix).toBuilder().debug(true).build();
    Span serverSpan = clientSpan.toBuilder().kind(SERVER).debug(null).shared(true).build();
    accept(clientSpan, serverSpan);
    // assertGetTracesReturns does recursive comparison
    assertGetTracesReturns(asList(clientSpan.traceId()), asList(clientSpan, serverSpan));
}
Also used : TestObjects.newClientSpan(zipkin2.TestObjects.newClientSpan) Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Aggregations

Span (zipkin2.Span)77 Test (org.junit.Test)54 Endpoint (zipkin2.Endpoint)28 Test (org.junit.jupiter.api.Test)17 V1Span (zipkin2.v1.V1Span)10 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)8 SpanSampler (com.wavefront.agent.sampler.SpanSampler)6 ByteBuf (io.netty.buffer.ByteBuf)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)6 IOException (java.io.IOException)6 Map (java.util.Map)6 Span (wavefront.report.Span)6 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)5 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)5 Trace (com.google.devtools.cloudtrace.v1.Trace)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Annotation (wavefront.report.Annotation)4 Annotation (zipkin2.Annotation)3