Search in sources :

Example 6 with Annotation

use of org.exquery.xquery3.Annotation in project zipkin by openzipkin.

the class V2SpanConverter method convert.

public V1Span convert(Span value) {
    md.parse(value);
    result.clear().traceId(value.traceId()).parentId(value.parentId()).id(value.id()).name(value.name()).debug(value.debug());
    // Don't report timestamp and duration on shared spans (should be server, but not necessarily)
    if (!Boolean.TRUE.equals(value.shared())) {
        result.timestamp(value.timestampAsLong());
        result.duration(value.durationAsLong());
    }
    boolean beginAnnotation = md.startTs != 0L && md.begin != null;
    boolean endAnnotation = md.endTs != 0L && md.end != null;
    Endpoint ep = value.localEndpoint();
    int annotationCount = value.annotations().size();
    if (beginAnnotation) {
        annotationCount++;
        result.addAnnotation(md.startTs, md.begin, ep);
    }
    for (int i = 0, length = value.annotations().size(); i < length; i++) {
        Annotation a = value.annotations().get(i);
        if (beginAnnotation && a.value().equals(md.begin))
            continue;
        if (endAnnotation && a.value().equals(md.end))
            continue;
        result.addAnnotation(a.timestamp(), a.value(), ep);
    }
    if (endAnnotation) {
        annotationCount++;
        result.addAnnotation(md.endTs, md.end, ep);
    }
    for (Map.Entry<String, String> b : value.tags().entrySet()) {
        result.addBinaryAnnotation(b.getKey(), b.getValue(), ep);
    }
    boolean writeLocalComponent = annotationCount == 0 && ep != null && value.tags().isEmpty();
    boolean hasRemoteEndpoint = md.addr != null && value.remoteEndpoint() != null;
    // write an empty "lc" annotation to avoid missing the localEndpoint in an in-process span
    if (writeLocalComponent)
        result.addBinaryAnnotation("lc", "", ep);
    if (hasRemoteEndpoint)
        result.addBinaryAnnotation(md.addr, value.remoteEndpoint());
    return result.build();
}
Also used : Endpoint(zipkin2.Endpoint) Map(java.util.Map) Endpoint(zipkin2.Endpoint) Annotation(zipkin2.Annotation)

Example 7 with Annotation

use of org.exquery.xquery3.Annotation in project zipkin-gcp by openzipkin.

the class SpanTranslator method translate.

/**
 * Converts a Zipkin Span into a Stackdriver Trace Span.
 *
 * <p>Ex.
 *
 * <pre>{@code
 * traceSpan = SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build();
 * }</pre>
 *
 * <p>Note: the result does not set {@link com.google.devtools.cloudtrace.v2.Span.Builder#setName(String)}
 * and it is up to callers to make sure to fill it using the project ID and trace ID.
 *
 * @param spanBuilder the builder (to facilitate re-use)
 * @param zipkinSpan The Zipkin Span.
 * @return A Stackdriver Trace Span.
 */
public static com.google.devtools.cloudtrace.v2.Span.Builder translate(com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder, Span zipkinSpan) {
    boolean logTranslation = LOG.isLoggable(FINE);
    if (logTranslation)
        LOG.log(FINE, ">> translating zipkin span: {0}", zipkinSpan);
    spanBuilder.setSpanId(zipkinSpan.id());
    if (zipkinSpan.parentId() != null) {
        spanBuilder.setParentSpanId(zipkinSpan.parentId());
    }
    // NOTE: opencensus prefixes Send. and Recv. based on Kind. For now we reproduce our V1 behavior
    // of using the span name as the display name as is.
    spanBuilder.setDisplayName(toTruncatableString((zipkinSpan.name() != null && !zipkinSpan.name().isEmpty()) ? zipkinSpan.name() : "unknown"));
    if (zipkinSpan.timestampAsLong() != 0L) {
        spanBuilder.setStartTime(createTimestamp(zipkinSpan.timestampAsLong()));
        if (zipkinSpan.durationAsLong() != 0L) {
            Timestamp endTime = createTimestamp(zipkinSpan.timestampAsLong() + zipkinSpan.durationAsLong());
            spanBuilder.setEndTime(endTime);
        }
    }
    spanBuilder.setAttributes(ATTRIBUTES_EXTRACTOR.extract(zipkinSpan));
    if (!zipkinSpan.annotations().isEmpty()) {
        TimeEvents.Builder events = TimeEvents.newBuilder();
        for (Annotation annotation : zipkinSpan.annotations()) {
            events.addTimeEvent(TimeEvent.newBuilder().setTime(createTimestamp(annotation.timestamp())).setAnnotation(TimeEvent.Annotation.newBuilder().setDescription(toTruncatableString(annotation.value()))));
        }
        spanBuilder.setTimeEvents(events);
    }
    if (logTranslation)
        LOG.log(FINE, "<< translated to stackdriver span: {0}", spanBuilder);
    return spanBuilder;
}
Also used : TimeEvents(com.google.devtools.cloudtrace.v2.Span.TimeEvents) Timestamp(com.google.protobuf.Timestamp) Annotation(zipkin2.Annotation)

Example 8 with Annotation

use of org.exquery.xquery3.Annotation in project libSBOLj by SynBioDex.

the class AnnotationTest method test_pubConstructors.

@Test
public void test_pubConstructors() throws SBOLValidationException, URISyntaxException {
    Annotation CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), true);
    assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getBooleanValue());
    assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
    assertTrue(CD_annot.isBooleanValue());
    CD_annot.setBooleanValue(false);
    assertFalse(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getBooleanValue());
    gRNA_b_gene.removeAnnotation(CD_annot);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
    // test constructor with double
    CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), 1.0);
    assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getDoubleValue() == 1.0);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
    assertTrue(CD_annot.isDoubleValue());
    CD_annot.setDoubleValue(5.0);
    assertTrue(CD_annot.getDoubleValue() == 5.0);
    gRNA_b_gene.removeAnnotation(CD_annot);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
    // test constructor with int
    CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), 2);
    assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getIntegerValue() == 2);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
    assertTrue(CD_annot.isIntegerValue());
    CD_annot.setIntegerValue(7);
    assertTrue(CD_annot.getIntegerValue() == 7);
    gRNA_b_gene.removeAnnotation(CD_annot);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
    // test constructor with string
    CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), "protein");
    assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getStringValue().equals("protein"));
    assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
    assertTrue(CD_annot.isStringValue());
    CD_annot.setStringValue("notAProtein");
    assertTrue(CD_annot.getStringValue().equals("notAProtein"));
    gRNA_b_gene.removeAnnotation(CD_annot);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
    // test constructor with URI
    CD_annot = gRNA_b_gene.createAnnotation(new QName(prURI, "protein", "pr"), new URI("http://www.sbolstandard.org/protein"));
    assertTrue(gRNA_b_gene.getAnnotation(CD_annot.getQName()).getURIValue().equals(new URI("http://www.sbolstandard.org/protein")));
    assertTrue(gRNA_b_gene.getAnnotations().size() == 1);
    assertTrue(CD_annot.isURIValue());
    CD_annot.setURIValue(new URI("http://www.sbolstandard.org/gene"));
    assertTrue(CD_annot.getURIValue().equals(new URI("http://www.sbolstandard.org/gene")));
    gRNA_b_gene.removeAnnotation(CD_annot);
    assertTrue(gRNA_b_gene.getAnnotations().size() == 0);
}
Also used : QName(javax.xml.namespace.QName) URI(java.net.URI) Annotation(org.sbolstandard.core2.Annotation) Test(org.junit.Test)

Example 9 with Annotation

use of org.exquery.xquery3.Annotation in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testAppendSpanWithLogs.

@Test
public void testAppendSpanWithLogs() throws Exception {
    JaegerSpan jaegerSpan = tracer.buildSpan("jaegerSpan-with-logs").start();
    jaegerSpan.log("event");
    // use sorted map for consistent ordering in test
    Map<String, Object> fields = new TreeMap<String, Object>();
    fields.put("event", "structured data");
    fields.put("string", "something");
    fields.put("number", 42);
    fields.put("boolean", true);
    jaegerSpan.log(fields);
    sender.append(jaegerSpan);
    sender.flush();
    List<List<zipkin2.Span>> traces = zipkinRule.getTraces();
    assertEquals(1, traces.size());
    assertEquals(1, traces.get(0).size());
    zipkin2.Span zipkinSpan = traces.get(0).get(0);
    assertEquals(2, zipkinSpan.annotations().size());
    // ignore order by using set
    Set<String> annotationValues = new HashSet<String>();
    for (Annotation annotation : zipkinSpan.annotations()) {
        annotationValues.add(annotation.value());
    }
    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add("event");
    expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
    assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Annotation(zipkin2.Annotation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Annotation

use of org.exquery.xquery3.Annotation in project jaeger-client-java by jaegertracing.

the class V2SpanConverterTest method testSpanLogsCreateAnnotations.

@Test
public void testSpanLogsCreateAnnotations() {
    JaegerSpan span = tracer.buildSpan("span-with-logs").start();
    span.log("event");
    // use sorted map for consistent ordering in test
    Map<String, Object> fields = new TreeMap<String, Object>();
    fields.put("event", "structured data");
    fields.put("string", "something");
    fields.put("number", 42);
    fields.put("boolean", true);
    span.log(fields);
    zipkin2.Span zipkinSpan = V2SpanConverter.convertSpan(span);
    List<String> annotationValues = new ArrayList<String>();
    for (Annotation annotation : zipkinSpan.annotations()) {
        annotationValues.add(annotation.value());
    }
    List<String> expectedValues = new ArrayList<String>();
    expectedValues.add("event");
    expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
    assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Annotation(zipkin2.Annotation) Test(org.junit.Test)

Aggregations

Annotation (zipkin2.Annotation)14 Map (java.util.Map)8 Test (org.junit.Test)5 Endpoint (zipkin2.Endpoint)5 ArrayList (java.util.ArrayList)4 Span (zipkin2.Span)4 LinkedHashMap (java.util.LinkedHashMap)3 TreeMap (java.util.TreeMap)3 QName (javax.xml.namespace.QName)3 Annotation (org.sbolstandard.core2.Annotation)3 JsonToken (com.fasterxml.jackson.core.JsonToken)2 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 IOException (java.io.IOException)2 URI (java.net.URI)2 List (java.util.List)2 Tracing (brave.Tracing)1 Platform (brave.internal.Platform)1 TraceContext (brave.propagation.TraceContext)1 TimeEvents (com.google.devtools.cloudtrace.v2.Span.TimeEvents)1 Timestamp (com.google.protobuf.Timestamp)1