Search in sources :

Example 1 with AnnotationUDT

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));
}
Also used : EndpointUDT(zipkin.storage.cassandra3.Schema.EndpointUDT) TypeCodecImpl(zipkin.storage.cassandra3.Schema.TypeCodecImpl) MappingManager(com.datastax.driver.mapping.MappingManager) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) AnnotationUDT(zipkin.storage.cassandra3.Schema.AnnotationUDT) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata) TraceIdUDT(zipkin.storage.cassandra3.Schema.TraceIdUDT)

Example 2 with AnnotationUDT

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);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) AnnotationUDT(zipkin.storage.cassandra3.Schema.AnnotationUDT) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) BinaryAnnotation(zipkin.BinaryAnnotation) BinaryAnnotationUDT(zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) TraceIdUDT(zipkin.storage.cassandra3.Schema.TraceIdUDT)

Aggregations

AnnotationUDT (zipkin.storage.cassandra3.Schema.AnnotationUDT)2 BinaryAnnotationUDT (zipkin.storage.cassandra3.Schema.BinaryAnnotationUDT)2 TraceIdUDT (zipkin.storage.cassandra3.Schema.TraceIdUDT)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 MappingManager (com.datastax.driver.mapping.MappingManager)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Annotation (zipkin.Annotation)1 BinaryAnnotation (zipkin.BinaryAnnotation)1 EndpointUDT (zipkin.storage.cassandra3.Schema.EndpointUDT)1 TypeCodecImpl (zipkin.storage.cassandra3.Schema.TypeCodecImpl)1