/** * Creates a new initializes instance. Using this constructor also indicates we need to sample this request. * * @param traceId Trace id. * @param spanId Span id. * @param parentSpanId Parent span id, can be <code>null</code>. * @param name Span name. */ ServerSpanImpl(final long traceId, final long spanId, final Long parentSpanId, final String name) { span = new Span(); span.setTrace_id(traceId); span.setId(spanId); if (parentSpanId != null) { span.setParent_id(parentSpanId); } span.setName(name); sample = true; }
/** Preferred way to create spans, as it properly deals with the parent id */ public Span toSpan() { Span result = new Span(); result.setId(spanId); result.setTrace_id(traceId); result.setParent_id(nullableParentId()); if (debug()) result.setDebug(debug()); return result; }
/** * Creates a new initializes instance. Using this constructor also indicates we need to sample this request. * * @param traceId Trace id. * @param spanId Span id. * @param parentSpanId Parent span id, can be <code>null</code>. * @param name Span name. Should be lowercase and not <code>null</code> or empty. */ static ServerSpan create(long traceId, long spanId, @Nullable Long parentSpanId, String name) { Span span = new Span(); span.setTrace_id(traceId); span.setId(spanId); if (parentSpanId != null) { span.setParent_id(parentSpanId); } span.setName(name); return create(span, true); }
consumeSpan.setId(Ids.get()); long traceId = TraceContext.getTraceId(); long parentId = TraceContext.getSpanId();
private Span startTrace(HttpServletRequest req, TracePoint point) { String apiName = req.getRequestURI(); Span apiSpan = new Span(); // span basic data long id = Ids.get(); apiSpan.setId(id); apiSpan.setTrace_id(id); apiSpan.setName(point.getKey()); long timestamp = Times.currentMicros(); apiSpan.setTimestamp(timestamp); // sr annotation apiSpan.addToAnnotations( Annotation.create(timestamp, TraceConstants.ANNO_SR, Endpoint.create(apiName, ServerInfo.IP4, req.getLocalPort()))); // app name apiSpan.addToBinary_annotations(BinaryAnnotation.create( "name", conf.getName(), null )); // app owner apiSpan.addToBinary_annotations(BinaryAnnotation.create( "owner", conf.getOwner(), null )); // trace desc if (!Strings.isNullOrEmpty(point.getDesc())){ apiSpan.addToBinary_annotations(BinaryAnnotation.create( "description", point.getDesc(), null )); } return apiSpan; }
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.cloudera.htrace.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getProcessId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getTraceId()); if (hTraceSpan.getParentId() != org.cloudera.htrace.Span.ROOT_SPAN_ID) { zipkinSpan.setParent_id(hTraceSpan.getParentId()); } zipkinSpan.setId(hTraceSpan.getSpanId()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
newSpan.setId(newSpanId.getSpanId()); newSpan.setTrace_id(newSpanId.getTraceId()); if (newSpanId.getParentSpanId() != null) {
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
@Override public Span readSpan(byte[] bytes) { zipkin.Span in = codec.readSpan(bytes); Span result = new Span(); result.setTrace_id(in.traceId); result.setId(in.id); result.setParent_id(in.parentId); result.setName(in.name); result.setTimestamp(in.timestamp); result.setDuration(in.duration); result.setDebug(in.debug); for (zipkin.Annotation a : in.annotations) { result.addToAnnotations(Annotation.create( a.timestamp, a.value, to(a.endpoint))); } for (zipkin.BinaryAnnotation a : in.binaryAnnotations) { result.addToBinary_annotations(BinaryAnnotation.create( a.key, a.value, AnnotationType.fromValue(a.type.value), to(a.endpoint))); } return result; }
unsetId(); } else { setId((Long)value);
unsetId(); } else { setId((Long)value);
unsetId(); } else { setId((Long)value);