Search in sources :

Example 11 with AttributeValue

use of io.opencensus.trace.AttributeValue in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandlerTest method convertErrorSpanDataToJaegerThriftSpan.

@Test
public void convertErrorSpanDataToJaegerThriftSpan() throws SenderException {
    long startTime = 1519629870001L;
    long endTime = 1519630148002L;
    String statusMessage = "timeout";
    SpanData spanData = SpanData.create(sampleSpanContext(), SpanId.fromBytes(new byte[] { (byte) 0x7F, FF, FF, FF, FF, FF, FF, FF }), true, "test", Kind.SERVER, Timestamp.fromMillis(startTime), SpanData.Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<Annotation>>emptyList(), 0), SpanData.TimedEvents.create(Collections.<TimedEvent<MessageEvent>>emptyList(), 0), SpanData.Links.create(Collections.<Link>emptyList(), 0), 0, Status.DEADLINE_EXCEEDED.withDescription(statusMessage), Timestamp.fromMillis(endTime));
    handler.export(singletonList(spanData));
    verify(mockSender).send(eq(process), captor.capture());
    List<Span> spans = captor.getValue();
    assertThat(spans.size()).isEqualTo(1);
    Span span = spans.get(0);
    assertThat(span.tags.size()).isEqualTo(3);
    assertThat(span.tags).containsExactly(new Tag(JaegerExporterHandler.SPAN_KIND, TagType.STRING).setVStr("server"), new Tag(JaegerExporterHandler.STATUS_CODE, TagType.LONG).setVLong(4), new Tag(JaegerExporterHandler.STATUS_MESSAGE, TagType.STRING).setVStr(statusMessage));
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) TimedEvent(io.opencensus.trace.export.SpanData.TimedEvent) Tag(io.jaegertracing.thriftjava.Tag) Span(io.jaegertracing.thriftjava.Span) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 12 with AttributeValue

use of io.opencensus.trace.AttributeValue in project instrumentation-java by census-instrumentation.

the class InstanaExporterHandler method convertToJson.

static String convertToJson(Collection<SpanData> spanDataList) {
    StringBuilder sb = new StringBuilder();
    sb.append('[');
    for (final SpanData span : spanDataList) {
        final SpanContext spanContext = span.getContext();
        final SpanId parentSpanId = span.getParentSpanId();
        final Timestamp startTimestamp = span.getStartTimestamp();
        final Timestamp endTimestamp = span.getEndTimestamp();
        final Status status = span.getStatus();
        if (status == null || endTimestamp == null) {
            continue;
        }
        if (sb.length() > 1) {
            sb.append(',');
        }
        sb.append('{');
        sb.append("\"spanId\":\"").append(encodeSpanId(spanContext.getSpanId())).append("\",");
        sb.append("\"traceId\":\"").append(encodeTraceId(spanContext.getTraceId())).append("\",");
        if (parentSpanId != null) {
            sb.append("\"parentId\":\"").append(encodeSpanId(parentSpanId)).append("\",");
        }
        sb.append("\"timestamp\":").append(toMillis(startTimestamp)).append(',');
        sb.append("\"duration\":").append(toMillis(startTimestamp, endTimestamp)).append(',');
        sb.append("\"name\":\"").append(toSpanName(span)).append("\",");
        sb.append("\"type\":\"").append(toSpanType(span)).append('"');
        if (!status.isOk()) {
            sb.append(",\"error\":").append("true");
        }
        Map<String, AttributeValue> attributeMap = span.getAttributes().getAttributeMap();
        if (attributeMap.size() > 0) {
            StringBuilder dataSb = new StringBuilder();
            dataSb.append('{');
            for (Entry<String, AttributeValue> entry : attributeMap.entrySet()) {
                if (dataSb.length() > 1) {
                    dataSb.append(',');
                }
                dataSb.append("\"").append(entry.getKey()).append("\":\"").append(attributeValueToString(entry.getValue())).append("\"");
            }
            dataSb.append('}');
            sb.append(",\"data\":").append(dataSb);
        }
        sb.append('}');
    }
    sb.append(']');
    return sb.toString();
}
Also used : Status(io.opencensus.trace.Status) AttributeValue(io.opencensus.trace.AttributeValue) SpanContext(io.opencensus.trace.SpanContext) SpanData(io.opencensus.trace.export.SpanData) Timestamp(io.opencensus.common.Timestamp) SpanId(io.opencensus.trace.SpanId)

Example 13 with AttributeValue

use of io.opencensus.trace.AttributeValue 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 14 with AttributeValue

use of io.opencensus.trace.AttributeValue in project instrumentation-java by census-instrumentation.

the class InstanaExporterHandlerTest method generateSpan_MultipleAttributes.

@Test
public void generateSpan_MultipleAttributes() {
    Map<String, AttributeValue> multipleAttributes = ImmutableMap.of("http.url", AttributeValue.stringAttributeValue("http://localhost/foo"), "http.method", AttributeValue.stringAttributeValue("GET"));
    SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
    "SpanName", /* name */
    Kind.CLIENT, /* kind */
    Timestamp.create(1505855794, 194009601), /* startTimestamp */
    Attributes.create(multipleAttributes, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
    Status.OK, Timestamp.create(1505855799, 465726528));
    assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data))).isEqualTo("[" + "{" + "\"spanId\":\"9cc1e3049173be09\"," + "\"traceId\":\"d239036e7d5cec11\"," + "\"parentId\":\"8b03ab423da481c5\"," + "\"timestamp\":1505855794194," + "\"duration\":5271," + "\"name\":\"SpanName\"," + "\"type\":\"EXIT\"," + "\"data\":" + "{" + "\"http.url\":\"http://localhost/foo\"," + "\"http.method\":\"GET\"" + "}" + "}" + "]");
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Example 15 with AttributeValue

use of io.opencensus.trace.AttributeValue in project instrumentation-java by census-instrumentation.

the class ZipkinExporterHandlerTest method generateSpan_WithAttributes.

@Test
public void generateSpan_WithAttributes() {
    Map<String, AttributeValue> attributeMap = new HashMap<String, AttributeValue>();
    attributeMap.put("string", AttributeValue.stringAttributeValue("string value"));
    attributeMap.put("boolean", AttributeValue.booleanAttributeValue(false));
    attributeMap.put("long", AttributeValue.longAttributeValue(9999L));
    SpanData data = SpanData.create(SpanContext.create(TraceId.fromLowerBase16(TRACE_ID), SpanId.fromLowerBase16(SPAN_ID), TraceOptions.builder().setIsSampled(true).build()), // TODO SpanId.fromLowerBase16
    SpanId.fromLowerBase16(PARENT_SPAN_ID), true, /* hasRemoteParent */
    "Sent.helloworld.Greeter.SayHello", /* name */
    Kind.CLIENT, /* kind */
    Timestamp.create(1505855794, 194009601), /* startTimestamp */
    Attributes.create(attributeMap, 0), TimedEvents.create(annotations, 0), TimedEvents.create(messageEvents, 0), Links.create(Collections.<Link>emptyList(), 0), null, /* childSpanCount */
    Status.OK, Timestamp.create(1505855799, 465726528));
    assertThat(ZipkinExporterHandler.generateSpan(data, localEndpoint)).isEqualTo(Span.newBuilder().traceId(TRACE_ID).parentId(PARENT_SPAN_ID).id(SPAN_ID).kind(Span.Kind.CLIENT).name(data.getName()).timestamp(1505855794000000L + 194009601L / 1000).duration((1505855799000000L + 465726528L / 1000) - (1505855794000000L + 194009601L / 1000)).localEndpoint(localEndpoint).addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED").addAnnotation(1505855799000000L + 459486280L / 1000, "SENT").putTag(ZipkinExporterHandler.STATUS_CODE, "OK").putTag("string", "string value").putTag("boolean", "false").putTag("long", "9999").build());
}
Also used : AttributeValue(io.opencensus.trace.AttributeValue) SpanData(io.opencensus.trace.export.SpanData) HashMap(java.util.HashMap) Link(io.opencensus.trace.Link) Test(org.junit.Test)

Aggregations

AttributeValue (io.opencensus.trace.AttributeValue)15 SpanData (io.opencensus.trace.export.SpanData)11 Test (org.junit.Test)8 Status (io.opencensus.trace.Status)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Link (io.opencensus.trace.Link)4 SpanContext (io.opencensus.trace.SpanContext)4 List (java.util.List)4 Timestamp (io.opencensus.common.Timestamp)3 AttributeValue.stringAttributeValue (io.opencensus.trace.AttributeValue.stringAttributeValue)3 SpanId (io.opencensus.trace.SpanId)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Scope (org.apache.ignite.spi.tracing.Scope)3 TracingConfigurationCoordinates (org.apache.ignite.spi.tracing.TracingConfigurationCoordinates)3 TracingConfigurationParameters (org.apache.ignite.spi.tracing.TracingConfigurationParameters)3 Tag (io.jaegertracing.thriftjava.Tag)2 Span (io.opencensus.trace.Span)2 TraceParams (io.opencensus.trace.config.TraceParams)2