@Override void name(Span span, String name) { synchronized (span) { span.setName(name); } }
/** * 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; }
/** * 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.setParent_id(parentId); String serviceName = invoker.getInterface().getSimpleName() + "." + invocation.getMethodName(); consumeSpan.setName(serviceName); long timestamp = Times.currentMicros(); consumeSpan.setTimestamp(timestamp);
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; }
/** * Start a new span for a new client request that will be bound to current thread. The ClientTracer can decide to return * <code>null</code> in case this request should not be traced (eg sampling). * * @param requestName Request name. Should be lowercase and not <code>null</code> or empty. * @return Span id for new request or <code>null</code> in case we should not trace this new client request. */ public SpanId startNewSpan(String requestName) { Boolean sample = spanAndEndpoint().state().sample(); if (Boolean.FALSE.equals(sample)) { spanAndEndpoint().state().setCurrentClientSpan(null); return null; } SpanId newSpanId = getNewSpanId(); if (sample == null) { // No sample indication is present. if (!traceSampler().isSampled(newSpanId.traceId)) { spanAndEndpoint().state().setCurrentClientSpan(null); return null; } } Span newSpan = newSpanId.toSpan(); newSpan.setName(requestName); spanAndEndpoint().state().setCurrentClientSpan(newSpan); return newSpanId; }
newSpan.setParent_id(newSpanId.getParentSpanId()); newSpan.setName(requestName); state.setCurrentClientSpan(newSpan); return newSpanId;
/** * 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; }
newSpan.setName(operation); newSpan.setTimestamp(timestamp); newSpan.addToBinary_annotations(
/** * 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; }
unsetName(); } else { setName((String)value);
unsetName(); } else { setName((String)value);
unsetName(); } else { setName((String)value);
public static Span fromZipkin(zipkin2.Span v2) { V1Span in = V2SpanConverter.create().convert(v2); Span result = newSpan(SpanId.builder() .traceIdHigh(in.traceIdHigh()) .traceId(in.traceId()) .spanId(in.id()) .parentId(in.parentId() != 0L ? in.parentId() : null) .debug(in.debug() != null ? in.debug() : false).build() ); result.setName(in.name()); result.setTimestamp(in.timestamp() != 0L ? in.timestamp() : null); result.setDuration(in.duration() != 0L ? in.duration() : null); for (zipkin2.v1.V1Annotation a : in.annotations()) { result.addToAnnotations(Annotation.create( a.timestamp(), a.value(), to(a.endpoint()))); } for (zipkin2.v1.V1BinaryAnnotation a : in.binaryAnnotations()) { if (a.type() != 0 && a.type() != 6) continue;; result.addToBinary_annotations(BinaryAnnotation.create( a.key(), a.type() == 0 ? new byte[]{1}: a.stringValue().getBytes(UTF_8), a.type() == 0 ? AnnotationType.BOOL : AnnotationType.STRING, to(a.endpoint()))); } return result; }