Search in sources :

Example 1 with SpanId

use of com.github.kristofa.brave.SpanId in project zipkin by openzipkin.

the class TracedSession method handleInvocation.

@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
    // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
    if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null && // Only trace named statements for now, since that's what we use
    method.getName().equals("executeAsync") && args[0] instanceof NamedBoundStatement) {
        NamedBoundStatement statement = (NamedBoundStatement) args[0];
        SpanId spanId = brave.clientTracer().startNewSpan(statement.name);
        // o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
        if (version.compareTo(ProtocolVersion.V4) >= 0) {
            statement.enableTracing();
            statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
        }
        // start the span and store it
        brave.clientTracer().setClientSent();
        brave.clientTracer().submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
        cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
        // let go of the client span as it is only used for the RPC (will have no local children)
        brave.clientSpanThreadBinder().setCurrentSpan(null);
        return new BraveResultSetFuture(target.executeAsync(statement), brave);
    }
    try {
        return method.invoke(target, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException)
            throw e.getCause();
        throw e;
    }
}
Also used : NamedBoundStatement(zipkin.storage.cassandra.NamedBoundStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) SpanId(com.github.kristofa.brave.SpanId)

Example 2 with SpanId

use of com.github.kristofa.brave.SpanId in project zipkin by openzipkin.

the class TracedSession method handleInvocation.

@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
    // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
    if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null && method.getName().equals("executeAsync") && args[0] instanceof BoundStatement) {
        BoundStatement statement = (BoundStatement) args[0];
        // via an internal class z.s.cassandra3.NamedBoundStatement, toString() is a nice name
        SpanId spanId = brave.clientTracer().startNewSpan(statement.toString());
        // o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
        if (version.compareTo(ProtocolVersion.V4) >= 0) {
            statement.enableTracing();
            statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
        }
        // start the span and store it
        brave.clientTracer().setClientSent();
        brave.clientTracer().submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
        cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
        // let go of the client span as it is only used for the RPC (will have no local children)
        brave.clientSpanThreadBinder().setCurrentSpan(null);
        return new BraveResultSetFuture(target.executeAsync(statement), brave);
    }
    try {
        return method.invoke(target, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException)
            throw e.getCause();
        throw e;
    }
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) SpanId(com.github.kristofa.brave.SpanId)

Example 3 with SpanId

use of com.github.kristofa.brave.SpanId in project camel by apache.

the class ZipkinServerRequestAdapter method getTraceData.

@Override
public TraceData getTraceData() {
    String sampled = exchange.getIn().getHeader(ZipkinConstants.SAMPLED, "0", String.class);
    if (sampled.equals("0") || sampled.toLowerCase().equals("false")) {
        return TraceData.builder().sample(false).build();
    } else {
        String traceId = exchange.getIn().getHeader(ZipkinConstants.TRACE_ID, String.class);
        String spanId = exchange.getIn().getHeader(ZipkinConstants.SPAN_ID, String.class);
        String parentSpanId = exchange.getIn().getHeader(ZipkinConstants.PARENT_SPAN_ID, String.class);
        if (traceId != null && spanId != null) {
            SpanId span = createSpanId(traceId, spanId, parentSpanId);
            return TraceData.builder().sample(true).spanId(span).build();
        }
    }
    return TraceData.builder().build();
}
Also used : ZipkinHelper.createSpanId(org.apache.camel.zipkin.ZipkinHelper.createSpanId) SpanId(com.github.kristofa.brave.SpanId)

Example 4 with SpanId

use of com.github.kristofa.brave.SpanId in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testExtract_childSpan.

@Test
public void testExtract_childSpan() throws Exception {
    SpanId spanId = SpanId.builder().spanId(2L).traceId(1L).parentId(1L).build();
    TextMap textMap = makeRequestWithSpanId(spanId);
    SpanContext context = b3Codec.extract(textMap);
    assertEquals(1, context.getTraceId());
    assertEquals(1, context.getParentId());
    assertEquals(2, context.getSpanId());
    // sampled
    assertEquals(1, context.getFlags());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) SpanId(com.github.kristofa.brave.SpanId) Test(org.junit.Test)

Example 5 with SpanId

use of com.github.kristofa.brave.SpanId in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testExtract_rootSpan.

@Test
public void testExtract_rootSpan() throws Exception {
    SpanId spanId = SpanId.builder().spanId(1L).traceId(1L).parentId(null).build();
    TextMap textMap = makeRequestWithSpanId(spanId);
    SpanContext context = b3Codec.extract(textMap);
    assertEquals(1, context.getTraceId());
    // parentID==0 means root span
    assertEquals(0, context.getParentId());
    assertEquals(1, context.getSpanId());
    // sampled
    assertEquals(1, context.getFlags());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) SpanId(com.github.kristofa.brave.SpanId) Test(org.junit.Test)

Aggregations

SpanId (com.github.kristofa.brave.SpanId)5 SpanContext (com.uber.jaeger.SpanContext)2 TextMap (io.opentracing.propagation.TextMap)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Test (org.junit.Test)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 ZipkinHelper.createSpanId (org.apache.camel.zipkin.ZipkinHelper.createSpanId)1 NamedBoundStatement (zipkin.storage.cassandra.NamedBoundStatement)1