Search in sources :

Example 36 with Endpoint

use of org.jboss.remoting3.Endpoint in project zipkin by openzipkin.

the class V2SpanWriter method annotationSizeInBytes.

static int annotationSizeInBytes(long timestamp, String value, int endpointSizeInBytes) {
    // {"timestamp":,"value":""}
    int sizeInBytes = 25;
    sizeInBytes += asciiSizeInBytes(timestamp);
    sizeInBytes += jsonEscapedSizeInBytes(value);
    if (endpointSizeInBytes != 0) {
        // ,"endpoint":
        sizeInBytes += 12;
        sizeInBytes += endpointSizeInBytes;
    }
    return sizeInBytes;
}
Also used : Endpoint(zipkin2.Endpoint)

Example 37 with Endpoint

use of org.jboss.remoting3.Endpoint in project zipkin by openzipkin.

the class V1SpanConverter method processBinaryAnnotations.

void processBinaryAnnotations(V1Span source) {
    zipkin2.Endpoint ca = null, sa = null, ma = null;
    for (int i = 0, length = source.binaryAnnotations.size(); i < length; i++) {
        V1BinaryAnnotation b = source.binaryAnnotations.get(i);
        // endpoint. Hence, we leniently parse.
        if ("ca".equals(b.key)) {
            ca = b.endpoint;
            continue;
        } else if ("sa".equals(b.key)) {
            sa = b.endpoint;
            continue;
        } else if ("ma".equals(b.key)) {
            ma = b.endpoint;
            continue;
        }
        Span.Builder currentSpan = forEndpoint(source, b.endpoint);
        // don't add marker "lc" tags
        if ("lc".equals(b.key) && b.stringValue.isEmpty())
            continue;
        currentSpan.putTag(b.key, b.stringValue);
    }
    boolean noCoreAnnotations = cs == null && cr == null && ss == null && sr == null;
    // special-case when we are missing core annotations, but we have both address annotations
    if (noCoreAnnotations && (ca != null || sa != null)) {
        if (ca != null && sa != null) {
            forEndpoint(source, ca).remoteEndpoint(sa);
        } else if (sa != null) {
            // "sa" is a default for a remote address, don't make it a client span
            forEndpoint(source, null).remoteEndpoint(sa);
        } else {
            // ca != null: treat it like a server
            forEndpoint(source, null).kind(Kind.SERVER).remoteEndpoint(ca);
        }
        return;
    }
    V1Annotation server = sr != null ? sr : ss;
    if (ca != null && server != null && !ca.equals(server.endpoint)) {
        // the same service name as "sa". Removing the service name prevents creating loopback links.
        if (hasSameServiceName(ca, server.endpoint)) {
            ca = ca.toBuilder().serviceName(null).build();
        }
        forEndpoint(source, server.endpoint).remoteEndpoint(ca);
    }
    if (sa != null) {
        // client span
        if (cs != null) {
            forEndpoint(source, cs.endpoint).remoteEndpoint(sa);
        } else if (cr != null) {
            forEndpoint(source, cr.endpoint).remoteEndpoint(sa);
        }
    }
    if (ma != null) {
        // a messaging span. This will ensure both sides have the address of the broker.
        if (ms != null)
            forEndpoint(source, ms.endpoint).remoteEndpoint(ma);
        if (mr != null)
            forEndpoint(source, mr.endpoint).remoteEndpoint(ma);
    }
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) Endpoint(zipkin2.Endpoint)

Example 38 with Endpoint

use of org.jboss.remoting3.Endpoint in project zipkin by openzipkin.

the class V1SpanConverter method processAnnotations.

void processAnnotations(V1Span source) {
    for (int i = 0, length = source.annotations.size(); i < length; i++) {
        V1Annotation a = source.annotations.get(i);
        Span.Builder currentSpan = forEndpoint(source, a.endpoint);
        // core annotations require an endpoint. Don't give special treatment when that's missing
        if (a.value.length() == 2 && a.endpoint != null) {
            if (a.value.equals("cs")) {
                currentSpan.kind(Kind.CLIENT);
                cs = a;
            } else if (a.value.equals("sr")) {
                currentSpan.kind(Kind.SERVER);
                sr = a;
            } else if (a.value.equals("ss")) {
                currentSpan.kind(Kind.SERVER);
                ss = a;
            } else if (a.value.equals("cr")) {
                currentSpan.kind(Kind.CLIENT);
                cr = a;
            } else if (a.value.equals("ms")) {
                currentSpan.kind(Kind.PRODUCER);
                ms = a;
            } else if (a.value.equals("mr")) {
                currentSpan.kind(Kind.CONSUMER);
                mr = a;
            } else if (a.value.equals("ws")) {
                ws = a;
            } else if (a.value.equals("wr")) {
                wr = a;
            } else {
                currentSpan.addAnnotation(a.timestamp, a.value);
            }
        } else {
            currentSpan.addAnnotation(a.timestamp, a.value);
        }
    }
    // When bridging between event and span model, you can end up missing a start annotation
    if (cs == null && endTimestampReflectsSpanDuration(cr, source)) {
        cs = V1Annotation.create(source.timestamp, "cs", cr.endpoint);
    }
    if (sr == null && endTimestampReflectsSpanDuration(ss, source)) {
        sr = V1Annotation.create(source.timestamp, "sr", ss.endpoint);
    }
    if (cs != null && sr != null) {
        // in a shared span, the client side owns span duration by annotations or explicit timestamp
        maybeTimestampDuration(source, cs, cr);
        // special-case loopback: We need to make sure on loopback there are two span2s
        Span.Builder client = forEndpoint(source, cs.endpoint);
        Span.Builder server;
        if (hasSameServiceName(cs.endpoint, sr.endpoint)) {
            client.kind(Kind.CLIENT);
            // fork a new span for the server side
            server = newSpanBuilder(source, sr.endpoint).kind(Kind.SERVER);
        } else {
            server = forEndpoint(source, sr.endpoint);
        }
        // the server side is smaller than that, we have to read annotations to find out
        server.shared(true).timestamp(sr.timestamp);
        if (ss != null)
            server.duration(ss.timestamp - sr.timestamp);
        // one-way has no duration
        if (cr == null && source.duration == 0)
            client.duration(null);
    } else if (cs != null && cr != null) {
        maybeTimestampDuration(source, cs, cr);
    } else if (sr != null && ss != null) {
        maybeTimestampDuration(source, sr, ss);
    } else {
        // otherwise, the span is incomplete. revert special-casing
        handleIncompleteRpc(source);
    }
    // implied shared. When we only see the server-side, carry this signal over.
    if (cs == null && sr != null && // case could be due to the client-side of that RPC.
    (source.timestamp == 0 || (ss != null && source.duration == 0))) {
        forEndpoint(source, sr.endpoint).shared(true);
    }
    // ms and mr are not supposed to be in the same span, but in case they are..
    if (ms != null && mr != null) {
        // special-case loopback: We need to make sure on loopback there are two span2s
        Span.Builder producer = forEndpoint(source, ms.endpoint);
        Span.Builder consumer;
        if (hasSameServiceName(ms.endpoint, mr.endpoint)) {
            producer.kind(Kind.PRODUCER);
            // fork a new span for the consumer side
            consumer = newSpanBuilder(source, mr.endpoint).kind(Kind.CONSUMER);
        } else {
            consumer = forEndpoint(source, mr.endpoint);
        }
        consumer.shared(true);
        if (wr != null) {
            consumer.timestamp(wr.timestamp).duration(mr.timestamp - wr.timestamp);
        } else {
            consumer.timestamp(mr.timestamp);
        }
        producer.timestamp(ms.timestamp).duration(ws != null ? ws.timestamp - ms.timestamp : null);
    } else if (ms != null) {
        maybeTimestampDuration(source, ms, ws);
    } else if (mr != null) {
        if (wr != null) {
            maybeTimestampDuration(source, wr, mr);
        } else {
            maybeTimestampDuration(source, mr, null);
        }
    } else {
        if (ws != null)
            forEndpoint(source, ws.endpoint).addAnnotation(ws.timestamp, ws.value);
        if (wr != null)
            forEndpoint(source, wr.endpoint).addAnnotation(wr.timestamp, wr.value);
    }
}
Also used : Span(zipkin2.Span) Endpoint(zipkin2.Endpoint)

Example 39 with Endpoint

use of org.jboss.remoting3.Endpoint in project zipkin by openzipkin.

the class V1Annotation method hashCode.

@Override
public int hashCode() {
    int h = 1;
    h *= 1000003;
    h ^= (int) (h ^ ((timestamp >>> 32) ^ timestamp));
    h *= 1000003;
    h ^= value.hashCode();
    h *= 1000003;
    h ^= endpoint == null ? 0 : endpoint.hashCode();
    return h;
}
Also used : Endpoint(zipkin2.Endpoint)

Example 40 with Endpoint

use of org.jboss.remoting3.Endpoint 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)

Aggregations

Endpoint (zipkin2.Endpoint)60 Span (zipkin2.Span)27 Test (org.junit.jupiter.api.Test)18 V1Span (zipkin2.v1.V1Span)16 Test (org.junit.Test)15 NoopHealthCheckManager (com.wavefront.agent.channel.NoopHealthCheckManager)5 SpanSampler (com.wavefront.agent.sampler.SpanSampler)5 ByteBuf (io.netty.buffer.ByteBuf)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)5 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)5 ArrayList (java.util.ArrayList)5 Span (wavefront.report.Span)5 Endpoint (org.apache.woden.wsdl20.Endpoint)4 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)4 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Service (org.apache.woden.wsdl20.Service)3