@Override public String getRequestId() { return String.valueOf(spanAccessor.getCurrentSpan().getSpanId()); } }
private void debug() { Span span = this.spanAccessor.getCurrentSpan(); this.log.info(String.format("traceId: %s, spanId: %s", span.getTraceId(), span.getSpanId())); } }
/** * Operation id is id of service call itself, its always presents and always unique for this service call * @return operation id */ @Override public UUID getOperationId() { ContextVerifier.assertWithinContext(); return UUID.fromString(TraceContextHolder.getCurrentSpan().getSpanId()); }
/** * Operation id is id of service call itself, its always presents and always unique for this service call * @return operation id */ @Override public UUID getOperationId() { ContextVerifier.assertWithinContext(); return UUID.fromString(TraceContextHolder.getCurrentSpan().getSpanId()); }
@SuppressWarnings("deprecation") private static SpanContext fromSleuthSpan(org.springframework.cloud.sleuth.Span span) { return SpanContext.create( TraceId.fromBytes( ByteBuffer.allocate(TraceId.SIZE) .putLong(span.getTraceIdHigh()) .putLong(span.getTraceId()) .array()), SpanId.fromBytes(ByteBuffer.allocate(SpanId.SIZE).putLong(span.getSpanId()).array()), Boolean.TRUE.equals(span.isExportable()) ? sampledOptions : notSampledOptions); } }
@Override public void inject(Span span, RpcContext carrier) { Map<String, String> attachments = carrier.getAttachments(); if (span.getTraceId() != 0) { attachments.put(Span.TRACE_ID_NAME, Span.idToHex(span.getTraceId())); } if (span.getSpanId() != 0) { attachments.put(Span.SPAN_ID_NAME, Span.idToHex(span.getSpanId())); } attachments.put(Span.SAMPLED_NAME, span.isExportable() ? Span.SPAN_SAMPLED : Span.SPAN_NOT_SAMPLED); attachments.put(Span.SPAN_NAME_NAME, span.getName()); Long parentId = getParentId(span); if (parentId != null && parentId != 0) { attachments.put(Span.PARENT_ID_NAME, Span.idToHex(parentId)); } attachments.put(Span.PROCESS_ID_NAME, span.getProcessId()); }
@SuppressWarnings("unchecked") private HttpEntity createNewHttpEntity(HttpEntity httpEntity, Span span) { HttpHeaders newHttpHeaders = new HttpHeaders(); newHttpHeaders.putAll(httpEntity.getHeaders()); if (span != null) { addHeaderIfPresent(newHttpHeaders, Span.SPAN_ID_NAME, String.valueOf(span.getSpanId())); addHeaderIfPresent(newHttpHeaders, Span.TRACE_ID_NAME, String.valueOf(span.getTraceId())); addHeaderIfPresent(newHttpHeaders, OLD_CORRELATION_ID_HEADER, String.valueOf(span.getTraceId())); addHeaderIfPresent(newHttpHeaders, Span.SPAN_NAME_NAME, span.getName()); addHeaderIfPresent(newHttpHeaders, Span.PARENT_ID_NAME, getFirst(span.getParents())); addHeaderIfPresent(newHttpHeaders, Span.PROCESS_ID_NAME, span.getProcessId()); } return new HttpEntity(httpEntity.getBody(), newHttpHeaders); }
private static void assertSpanEquals( Span span, org.springframework.cloud.sleuth.Span sleuthSpan) { assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16)) .isEqualTo(sleuthSpan.getTraceIdHigh()); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16)) .isEqualTo(sleuthSpan.getTraceId()); assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16)) .isEqualTo(sleuthSpan.getSpanId()); assertThat(span.getContext().getTraceOptions().isSampled()) .isEqualTo(sleuthSpan.isExportable()); } }
private static final void assertSpanEquals(io.opencensus.trace.Span span, Span sleuthSpan) { assertThat(span.getContext().isValid()).isTrue(); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16)) .isEqualTo(sleuthSpan.getTraceIdHigh()); assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16)) .isEqualTo(sleuthSpan.getTraceId()); assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16)) .isEqualTo(sleuthSpan.getSpanId()); assertThat(span.getContext().getTraceOptions().isSampled()) .isEqualTo(sleuthSpan.isExportable()); } }
} else { span.stop(); if (savedSpan != null && span.getParents().contains(savedSpan.getSpanId())) { this.spanReporter.report(span); this.spanLogger.logStoppedSpan(savedSpan, span);
protected TraceSpan convert(Span span) { Span adjustedSpan = span; for (SpanAdjuster adjuster : this.spanAdjusters) { adjustedSpan = adjuster.adjust(adjustedSpan); } TraceSpan.Builder builder = TraceSpan.newBuilder(); // Set name if (StringUtils.hasText(adjustedSpan.getName())) { builder.setName(adjustedSpan.getName()); } TraceSpan.SpanKind kind = getKind(adjustedSpan); builder.setKind(kind); builder.setSpanId(adjustedSpan.getSpanId()); rewriteIds(adjustedSpan, kind, builder); writeStartEndTime(adjustedSpan, builder); builder.putAllLabels(this.labelExtractor.extract(adjustedSpan, builder.getKind(), this.instanceId)); return builder.build(); }
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; }
protected void attachTraceInfo(Tracer tracer, Span span, final Request request) { if (span == null) { setHeader(request, Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED); return; } setHeader(request, TraceRequestAttributes.HANDLED_SPAN_REQUEST_ATTR, "true"); setHeader(request, Span.SPAN_ID_NAME, Span.idToHex(span.getSpanId())); setHeader(request, Span.TRACE_ID_NAME, span.traceIdString()); setHeader(request, Span.SPAN_NAME_NAME, span.getName()); setHeader(request, Span.SAMPLED_NAME, span.isExportable() ? Span.SPAN_SAMPLED : Span.SPAN_NOT_SAMPLED); setHeader(request, Span.PARENT_ID_NAME,Span.idToHex(getParentId(span))); setHeader(request, Span.PROCESS_ID_NAME, span.getProcessId()); if(span.getSavedSpan()!=null && span.getSavedSpan().tags()!=null){ for (Entry<String, String> stringStringEntry : span.getSavedSpan().tags().entrySet()) { setHeader(request, stringStringEntry.getKey(), stringStringEntry.getValue()); } } /*spanInjector.inject(span,null); tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMap() { @Override public void put(String key, String value) { request.setAttachment(key, value); } @Override public Iterator<Entry<String, String>> iterator() { throw new UnsupportedOperationException("TextMapInjectAdapter should only be used with Tracer.inject()"); } });*/ }
zipkinSpan.id(Span.idToHex(convertedSpan.getSpanId())); if (StringUtils.hasText(convertedSpan.getName())) { zipkinSpan.name(convertedSpan.getName());
.traceIdHigh(parent.getTraceIdHigh()) .traceId(parent.getTraceId()) .parent(parent.getSpanId()) .spanId(id) .processId(parent.getProcessId())