private Span buildParentSpan(RpcContext carrier, boolean skip, long traceId, long spanId) { Map<String, String> attachments = carrier.getAttachments(); SpanBuilder span = Span.builder().traceId(traceId).spanId(spanId); String processId = attachments.get(Span.PROCESS_ID_NAME); String parentName = attachments.get(Span.SPAN_NAME_NAME); if (StringUtils.hasText(parentName)) { span.name(parentName); } if (StringUtils.hasText(processId)) { span.processId(processId); } if (attachments.get(Span.PARENT_ID_NAME) != null) { span.parent(Span .hexToId(attachments.get(Span.PARENT_ID_NAME))); } span.remote(true); if (skip) { span.exportable(false); } return span.build(); } }
Span span = spanBuilder.build(); tracer.createSpan(name, span); TraceLogWrap.response("MQ", 200, name, "");
spanBuilder.name(request.getAttachments().get(TraceMessageHeaders.SPAN_NAME_NAME)); spanBuilder.remote(true); parentSpan = spanBuilder.build(); }else if(request.getAttachments().get(Span.TRACE_ID_NAME)!=null && !"".equals(request.getAttachments().get(Span.TRACE_ID_NAME))){ parentSpan = spanBuilder.build();
@Override @javax.annotation.Nullable public Span createSpan(String name, /*@Nullable*/ Sampler sampler) { String shortenedName = SpanNameUtil.shorten(name); Span span; if (isTracing()) { span = createChild(getCurrentSpan(), shortenedName); } else { long id = createId(); span = Span.builder() .name(shortenedName) .traceIdHigh(this.traceId128 ? createTraceIdHigh() : 0L) .traceId(id) .spanId(id) .build(); if (sampler == null) { sampler = this.defaultSampler; } span = sampledSpan(span, sampler); this.spanLogger.logStartedSpan(null, span); } return continueSpan(span); }
private static Span sampledSpan(Span span, Sampler sampler) { if (!sampler.isSampled(span)) { // Copy everything, except set exportable to false return Span.builder() .begin(span.getBegin()) .traceIdHigh(span.getTraceIdHigh()) .traceId(span.getTraceId()) .spanId(span.getSpanId()) .name(span.getName()) .exportable(false) .build(); } return span; }
@Test public void testFromSleuthNotSampled() { Span sleuthSpan = Span.builder() .name("name") .traceIdHigh(12L) .traceId(22L) .spanId(23L) .exportable(false) .build(); assertSpanEquals(new OpenCensusSleuthSpan(sleuthSpan), sleuthSpan); }
@Test public void testFromSleuthSampled() { Span sleuthSpan = Span.builder() .name("name") .traceIdHigh(12L) .traceId(22L) .spanId(23L) .exportable(true) .build(); assertSpanEquals(new OpenCensusSleuthSpan(sleuthSpan), sleuthSpan); }
private static org.springframework.cloud.sleuth.Span createSleuthSpan( long tidHi, long tidLo, long sid, boolean exportable) { return org.springframework.cloud.sleuth.Span.builder() .name("name") .traceIdHigh(tidHi) .traceId(tidLo) .spanId(sid) .exportable(exportable) .build(); }