Java Code Examples for org.springframework.cloud.sleuth.Span#getSavedSpan()

The following examples show how to use org.springframework.cloud.sleuth.Span#getSavedSpan() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenCensusSleuthTracer.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
@javax.annotation.Nullable
public Span detach(/*@Nullable*/ Span span) {
  if (span == null) {
    return null;
  }
  Span current = OpenCensusSleuthSpanContextHolder.getCurrentSpan();
  if (current == null) {
    if (log.isTraceEnabled()) {
      log.trace(
          "Span in the context is null so something has already detached the span. "
              + "Won't do anything about it");
    }
    return null;
  }
  if (!span.equals(current)) {
    ExceptionUtils.warn(
        "Tried to detach trace span but "
            + "it is not the current span: "
            + span
            + ". You may have forgotten to close or detach "
            + current);
  } else {
    OpenCensusSleuthSpanContextHolder.removeCurrentSpan();
  }
  return span.getSavedSpan();
}
 
Example 2
Source File: OpenCensusSleuthTracer.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Override
@javax.annotation.Nullable
public Span close(/*@Nullable*/ Span span) {
  if (span == null) {
    return null;
  }
  final Span savedSpan = span.getSavedSpan();
  Span current = OpenCensusSleuthSpanContextHolder.getCurrentSpan();
  if (current == null || !span.equals(current)) {
    ExceptionUtils.warn(
        "Tried to close span but it is not the current span: "
            + span
            + ".  You may have forgotten to close or detach "
            + current);
  } else {
    span.stop();
    if (savedSpan != null && span.getParents().contains(savedSpan.getSpanId())) {
      this.spanReporter.report(span);
      this.spanLogger.logStoppedSpan(savedSpan, span);
    } else {
      if (!span.isRemote()) {
        this.spanReporter.report(span);
        this.spanLogger.logStoppedSpan(null, span);
      }
    }
    OpenCensusSleuthSpanContextHolder.close(
        new OpenCensusSleuthSpanContextHolder.SpanFunction() {
          @Override
          public void apply(Span closedSpan) {
            // Note: hasn't this already been done?
            OpenCensusSleuthTracer.this.spanLogger.logStoppedSpan(savedSpan, closedSpan);
          }
        });
  }
  return savedSpan;
}
 
Example 3
Source File: OpenCensusSleuthTracer.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static Span createContinuedSpan(Span span, /*@Nullable*/ Span saved) {
  if (saved == null && span.getSavedSpan() != null) {
    saved = span.getSavedSpan();
  }
  return new Span(span, saved);
}