use of zipkin.storage.cassandra3.Schema.AnnotationUDT in project zipkin by openzipkin.
the class DefaultSessionFactory method initializeUDTs.
private static void initializeUDTs(Session session) {
Schema.ensureExists(DEFAULT_KEYSPACE + "_udts", session);
MappingManager mapping = new MappingManager(session);
// The UDTs are hardcoded against the zipkin keyspace.
// If a different keyspace is being used the codecs must be re-applied to this different keyspace
TypeCodec<TraceIdUDT> traceIdCodec = mapping.udtCodec(TraceIdUDT.class);
TypeCodec<EndpointUDT> endpointCodec = mapping.udtCodec(EndpointUDT.class);
TypeCodec<AnnotationUDT> annoCodec = mapping.udtCodec(AnnotationUDT.class);
TypeCodec<BinaryAnnotationUDT> bAnnoCodec = mapping.udtCodec(BinaryAnnotationUDT.class);
KeyspaceMetadata keyspace = session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
session.getCluster().getConfiguration().getCodecRegistry().register(new TypeCodecImpl(keyspace.getUserType("trace_id"), TraceIdUDT.class, traceIdCodec)).register(new TypeCodecImpl(keyspace.getUserType("endpoint"), EndpointUDT.class, endpointCodec)).register(new TypeCodecImpl(keyspace.getUserType("annotation"), AnnotationUDT.class, annoCodec)).register(new TypeCodecImpl(keyspace.getUserType("binary_annotation"), BinaryAnnotationUDT.class, bAnnoCodec));
}
use of zipkin.storage.cassandra3.Schema.AnnotationUDT in project zipkin by openzipkin.
the class CassandraSpanConsumer method storeSpan.
/**
* Store the span in the underlying storage for later retrieval.
*/
ListenableFuture<?> storeSpan(Span span, TraceIdUDT traceId, boolean isServerRecvSpan, Long timestamp) {
try {
if ((null == timestamp || 0 == timestamp) && !isServerRecvSpan && metadata.compactionClass.contains("TimeWindowCompactionStrategy")) {
LOG.warn("Span {} in trace {} had no timestamp. " + "If this happens a lot consider switching back to SizeTieredCompactionStrategy for " + "{}.traces", span.id, span.traceId, session.getLoggedKeyspace());
}
List<AnnotationUDT> annotations = new ArrayList<>(span.annotations.size());
for (Annotation annotation : span.annotations) {
annotations.add(new AnnotationUDT(annotation));
}
List<BinaryAnnotationUDT> binaryAnnotations = new ArrayList<>(span.binaryAnnotations.size());
for (BinaryAnnotation annotation : span.binaryAnnotations) {
binaryAnnotations.add(new BinaryAnnotationUDT(annotation));
}
Set<String> annotationKeys = CassandraUtil.annotationKeys(span);
if (!strictTraceId && traceId.getHigh() != 0L) {
storeSpan(span, new TraceIdUDT(0L, traceId.getLow()), isServerRecvSpan, timestamp);
}
BoundStatement bound = bindWithName(insertSpan, "insert-span").set("trace_id", traceId, TraceIdUDT.class).setUUID("ts_uuid", new UUID(UUIDs.startOf(null != timestamp ? (timestamp / 1000) : 0).getMostSignificantBits(), UUIDs.random().getLeastSignificantBits())).setLong("id", span.id).setString("span_name", span.name).setList("annotations", annotations).setList("binary_annotations", binaryAnnotations).setString("all_annotations", Joiner.on(',').join(annotationKeys));
if (null != span.timestamp) {
bound = bound.setLong("ts", span.timestamp);
}
if (null != span.duration) {
bound = bound.setLong("duration", span.duration);
}
if (null != span.parentId) {
bound = bound.setLong("parent_id", span.parentId);
}
return session.executeAsync(bound);
} catch (RuntimeException ex) {
return Futures.immediateFailedFuture(ex);
}
}
Aggregations