Search in sources :

Example 41 with Span

use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.

the class AbstractBraveModuleTest method testFindTargets.

@Test
public void testFindTargets() {
    RelationshipRepositoryV2<Project, Serializable, Task, Serializable> relRepo = client.getRepositoryForType(Project.class, Task.class);
    relRepo.findManyTargets(123L, "tasks", new QuerySpec(Task.class));
    // check client call and link span
    ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
    List<Span> clientSpans = clientSpanCaptor.getAllValues();
    Span callSpan = clientSpans.get(0);
    Assert.assertEquals("get", callSpan.name());
    Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
    // check server local span
    ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(serverReporter, Mockito.times(2)).report(serverSpanCaptor.capture());
    List<Span> serverSpans = serverSpanCaptor.getAllValues();
    Span repositorySpan0 = serverSpans.get(0);
    Assert.assertEquals("crnk:get:/tasks/", repositorySpan0.name());
    Assert.assertTrue(repositorySpan0.toString().contains("\"lc\""));
    assertTag(repositorySpan0, "lc", "crnk");
    assertTag(repositorySpan0, "crnk.results", "0");
    assertTag(repositorySpan0, "crnk.status", "OK");
    Span repositorySpan1 = serverSpans.get(1);
    Assert.assertEquals("crnk:get:/projects/123/tasks/", repositorySpan1.name());
    Assert.assertTrue(repositorySpan1.toString().contains("\"lc\""));
    assertTag(repositorySpan1, "lc", "crnk");
    assertTag(repositorySpan1, "crnk.query", "?");
    assertTag(repositorySpan1, "crnk.results", "0");
    assertTag(repositorySpan1, "crnk.status", "OK");
}
Also used : Project(io.crnk.monitor.brave.mock.models.Project) Serializable(java.io.Serializable) Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) Span(zipkin2.Span) Test(org.junit.Test)

Example 42 with Span

use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.

the class AbstractBraveModuleTest method testFindAll.

@Test
public void testFindAll() {
    Task task = new Task();
    task.setId(13L);
    task.setName("myTask");
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "doe"));
    taskRepo.findAll(querySpec);
    // check client call and link span
    ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(clientReporter, Mockito.times(isOkHttp ? 1 : 1)).report(clientSpanCaptor.capture());
    List<Span> clientSpans = clientSpanCaptor.getAllValues();
    Span callSpan = clientSpans.get(0);
    Assert.assertEquals("get", callSpan.name());
    Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
    // check server local span
    ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
    List<Span> serverSpans = serverSpanCaptor.getAllValues();
    Span repositorySpan = serverSpans.get(0);
    Assert.assertEquals("crnk:get:/tasks/", repositorySpan.name());
    Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
    assertTag(repositorySpan, "lc", "crnk");
    assertTag(repositorySpan, "crnk.query", "?filter[tasks][name][EQ]=doe");
    assertTag(repositorySpan, "crnk.results", "0");
    assertTag(repositorySpan, "crnk.status", "OK");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Span(zipkin2.Span) Test(org.junit.Test)

Example 43 with Span

use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.

the class AbstractBraveModuleTest method testCreate.

@Test
public void testCreate() {
    Task task = new Task();
    task.setId(13L);
    task.setName("myTask");
    taskRepo.create(task);
    // check client call and link span
    ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
    List<Span> clientSpans = clientSpanCaptor.getAllValues();
    Span callSpan = clientSpans.get(0);
    Assert.assertEquals("post", callSpan.name());
    Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
    // check server local span
    ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
    List<Span> serverSpans = serverSpanCaptor.getAllValues();
    Span repositorySpan = serverSpans.get(0);
    Assert.assertEquals("crnk:post:/tasks/13/", repositorySpan.name());
    Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
    assertTag(repositorySpan, "lc", "crnk");
    assertTag(repositorySpan, "crnk.query", "?");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) Span(zipkin2.Span) Test(org.junit.Test)

Example 44 with Span

use of io.opencensus.proto.trace.v1.Span in project crnk-framework by crnk-project.

the class AbstractBraveModuleTest method testError.

@Test
public void testError() {
    Task task = new Task();
    task.setId(13L);
    try {
        taskRepo.create(task);
    } catch (Exception e) {
    // ok
    }
    // check client call and link span
    ArgumentCaptor<Span> clientSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(clientReporter, Mockito.times(1)).report(clientSpanCaptor.capture());
    List<Span> clientSpans = clientSpanCaptor.getAllValues();
    Span callSpan = clientSpans.get(0);
    Assert.assertEquals("post", callSpan.name());
    Assert.assertEquals(Span.Kind.CLIENT, callSpan.kind());
    assertTag(callSpan, "http.status_code", "500");
    // check server local span
    ArgumentCaptor<Span> serverSpanCaptor = ArgumentCaptor.forClass(Span.class);
    Mockito.verify(serverReporter, Mockito.times(1)).report(serverSpanCaptor.capture());
    List<Span> serverSpans = serverSpanCaptor.getAllValues();
    Span repositorySpan = serverSpans.get(0);
    Assert.assertEquals("crnk:post:/tasks/13/", repositorySpan.name());
    Assert.assertTrue(repositorySpan.toString().contains("\"lc\""));
    assertTag(repositorySpan, "lc", "crnk");
    assertTag(repositorySpan, "crnk.query", "?");
    assertTag(repositorySpan, "crnk.status", "EXCEPTION");
}
Also used : Task(io.crnk.monitor.brave.mock.models.Task) Span(zipkin2.Span) Test(org.junit.Test)

Example 45 with Span

use of io.opencensus.proto.trace.v1.Span in project instrumentation-java by census-instrumentation.

the class StackdriverV2ExporterHandler method generateSpan.

@VisibleForTesting
Span generateSpan(SpanData spanData, Map<String, AttributeValue> resourceLabels, Map<String, AttributeValue> fixedAttributes) {
    SpanContext context = spanData.getContext();
    final String spanIdHex = context.getSpanId().toLowerBase16();
    SpanName spanName = SpanName.newBuilder().setProject(projectId).setTrace(context.getTraceId().toLowerBase16()).setSpan(spanIdHex).build();
    Span.Builder spanBuilder = Span.newBuilder().setName(spanName.toString()).setSpanId(spanIdHex).setDisplayName(toTruncatableStringProto(toDisplayName(spanData.getName(), spanData.getKind()))).setStartTime(toTimestampProto(spanData.getStartTimestamp())).setAttributes(toAttributesProto(spanData.getAttributes(), resourceLabels, fixedAttributes)).setTimeEvents(toTimeEventsProto(spanData.getAnnotations(), spanData.getMessageEvents()));
    io.opencensus.trace.Status status = spanData.getStatus();
    if (status != null) {
        spanBuilder.setStatus(toStatusProto(status));
    }
    Timestamp end = spanData.getEndTimestamp();
    if (end != null) {
        spanBuilder.setEndTime(toTimestampProto(end));
    }
    spanBuilder.setLinks(toLinksProto(spanData.getLinks()));
    Integer childSpanCount = spanData.getChildSpanCount();
    if (childSpanCount != null) {
        spanBuilder.setChildSpanCount(Int32Value.newBuilder().setValue(childSpanCount).build());
    }
    if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
        spanBuilder.setParentSpanId(spanData.getParentSpanId().toLowerBase16());
    }
    /*@Nullable*/
    Boolean hasRemoteParent = spanData.getHasRemoteParent();
    if (hasRemoteParent != null) {
        spanBuilder.setSameProcessAsParentSpan(BoolValue.of(!hasRemoteParent));
    }
    return spanBuilder.build();
}
Also used : SpanName(com.google.devtools.cloudtrace.v2.SpanName) SpanContext(io.opencensus.trace.SpanContext) TruncatableString(com.google.devtools.cloudtrace.v2.TruncatableString) Span(com.google.devtools.cloudtrace.v2.Span) Timestamp(io.opencensus.common.Timestamp) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Span (zipkin2.Span)290 Test (org.junit.Test)192 Test (org.junit.jupiter.api.Test)67 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 Endpoint (zipkin2.Endpoint)37 ArrayList (java.util.ArrayList)24 V1Span (zipkin2.v1.V1Span)17 List (java.util.List)14 AggregateCall (zipkin2.internal.AggregateCall)13 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)12 Arrays.asList (java.util.Arrays.asList)9 Map (java.util.Map)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Span (com.google.devtools.cloudtrace.v2.Span)8 LinkedHashMap (java.util.LinkedHashMap)8 Trace (com.google.devtools.cloudtrace.v1.Trace)7 Span (zipkin2.proto3.Span)7 SpanData (io.opencensus.trace.export.SpanData)6 SpanCustomizer (brave.SpanCustomizer)5 IOException (java.io.IOException)5