use of zipkin.storage.cassandra.NamedBoundStatement in project zipkin by openzipkin.
the class TracedSession method update.
@Override
public void update(Host host, Statement statement, Exception e, long nanos) {
if (!(statement instanceof NamedBoundStatement))
return;
Span span = cache.remove(statement);
if (span == null) {
if (statement.isTracing()) {
LOG.warn("{} not in the cache eventhough tracing is on", statement);
}
return;
}
Span previous = brave.clientSpanThreadBinder().getCurrentClientSpan();
brave.clientSpanThreadBinder().setCurrentSpan(span);
try {
if (e != null) {
brave.clientTracer().submitBinaryAnnotation(Constants.ERROR, e.getMessage());
}
} finally {
// TODO: on brave 4, set host to remote address
brave.clientTracer().setClientReceived();
brave.clientSpanThreadBinder().setCurrentSpan(previous);
}
}
use of zipkin.storage.cassandra.NamedBoundStatement 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;
}
}
Aggregations