@SuppressWarnings("deprecation")
  private static void emitSingleSpan(Formatter formatter, SpanData span) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(TimeUnit.SECONDS.toMillis(span.getStartTimestamp().getSeconds()));
    long microsField = TimeUnit.NANOSECONDS.toMicros(span.getStartTimestamp().getNanos());
    String elapsedSecondsStr =
        span.getEndTimestamp() != null
            ? String.format(
                "%13.6f",
                durationToNanos(span.getEndTimestamp().subtractTimestamp(span.getStartTimestamp()))
                    * 1.0e-9)
            : String.format("%13s", " ");

    SpanContext spanContext = span.getContext();
    formatter.format(
        "<b>%04d/%02d/%02d-%02d:%02d:%02d.%06d %s     TraceId: <b style=\"color:%s;\">%s</b> "
            + "SpanId: %s ParentSpanId: %s</b>%n",
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH) + 1,
        calendar.get(Calendar.DAY_OF_MONTH),
        calendar.get(Calendar.HOUR_OF_DAY),
        calendar.get(Calendar.MINUTE),
        calendar.get(Calendar.SECOND),
        microsField,
        elapsedSecondsStr,
        spanContext.getTraceOptions().isSampled()
            ? SAMPLED_TRACE_ID_COLOR
            : NOT_SAMPLED_TRACE_ID_COLOR,
        BaseEncoding.base16().lowerCase().encode(spanContext.getTraceId().getBytes()),
        BaseEncoding.base16().lowerCase().encode(spanContext.getSpanId().getBytes()),
        BaseEncoding.base16()
            .lowerCase()
            .encode(
                span.getParentSpanId() == null
                    ? SpanId.INVALID.getBytes()
                    : span.getParentSpanId().getBytes()));

    int lastEntryDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);

    Timestamp lastTimestampNanos = span.getStartTimestamp();
    TimedEvents<Annotation> annotations = span.getAnnotations();
    TimedEvents<io.opencensus.trace.NetworkEvent> networkEvents = span.getNetworkEvents();
    List<TimedEvent<?>> timedEvents = new ArrayList<TimedEvent<?>>(annotations.getEvents());
    timedEvents.addAll(networkEvents.getEvents());
    Collections.sort(timedEvents, new TimedEventComparator());
    for (TimedEvent<?> event : timedEvents) {
      // Special printing so that durations smaller than one second
      // are left padded with blanks instead of '0' characters.
      // E.g.,
      //        Number                  Printout
      //        ---------------------------------
      //        0.000534                  .   534
      //        1.000534                 1.000534
      long deltaMicros =
          TimeUnit.NANOSECONDS.toMicros(
              durationToNanos(event.getTimestamp().subtractTimestamp(lastTimestampNanos)));
      String deltaString;
      if (deltaMicros >= 1000000) {
        deltaString = String.format("%.6f", (deltaMicros / 1000000.0));
      } else {
        deltaString = String.format(".%6d", deltaMicros);
      }

      calendar.setTimeInMillis(
          TimeUnit.SECONDS.toMillis(event.getTimestamp().getSeconds())
              + TimeUnit.NANOSECONDS.toMillis(event.getTimestamp().getNanos()));
      microsField = TimeUnit.NANOSECONDS.toMicros(event.getTimestamp().getNanos());

      int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
      if (dayOfYear == lastEntryDayOfYear) {
        formatter.format("%11s", "");
      } else {
        formatter.format(
            "%04d/%02d/%02d-",
            calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH) + 1,
            calendar.get(Calendar.DAY_OF_MONTH));
        lastEntryDayOfYear = dayOfYear;
      }

      formatter.format(
          "%02d:%02d:%02d.%06d %13s ... %s%n",
          calendar.get(Calendar.HOUR_OF_DAY),
          calendar.get(Calendar.MINUTE),
          calendar.get(Calendar.SECOND),
          microsField,
          deltaString,
          htmlEscaper()
              .escape(
                  event.getEvent() instanceof Annotation
                      ? renderAnnotation((Annotation) event.getEvent())
                      : renderNetworkEvents(
                          (io.opencensus.trace.NetworkEvent) castNonNull(event.getEvent()))));
      lastTimestampNanos = event.getTimestamp();
    }
    Status status = span.getStatus();
    if (status != null) {
      formatter.format("%44s %s%n", "", htmlEscaper().escape(renderStatus(status)));
    }
    formatter.format(
        "%44s %s%n",
        "", htmlEscaper().escape(renderAttributes(span.getAttributes().getAttributeMap())));
  }
@ SuppressWarnings ( "deprecation" ) private static void emitSingleSpan ( Formatter formatter , SpanData span ) { Calendar calendar = Calendar . getInstance ( ) ; calendar . setTimeInMillis ( TimeUnit . SECONDS . toMillis ( span . getStartTimestamp ( ) . getSeconds ( ) ) ) ; long microsField = TimeUnit . NANOSECONDS . toMicros ( span . getStartTimestamp ( ) . getNanos ( ) ) ; String elapsedSecondsStr = span . getEndTimestamp ( ) != null ? String . format ( "%13.6f" , durationToNanos ( span . getEndTimestamp ( ) . subtractTimestamp ( span . getStartTimestamp ( ) ) ) * 1.0e-9 ) : String . format ( "%13s" , " " ) ; SpanContext spanContext = span . getContext ( ) ; formatter . format ( "<b>%04d/%02d/%02d-%02d:%02d:%02d.%06d %s     TraceId: <b style=\"color:%s;\">%s</b> " + "SpanId: %s ParentSpanId: %s</b>%n" , calendar . get ( Calendar . YEAR ) , calendar . get ( Calendar . MONTH ) + 1 , calendar . get ( Calendar . DAY_OF_MONTH ) , calendar . get ( Calendar . HOUR_OF_DAY ) , calendar . get ( Calendar . MINUTE ) , calendar . get ( Calendar . SECOND ) , microsField , elapsedSecondsStr , spanContext . getTraceOptions ( ) . isSampled ( ) ? SAMPLED_TRACE_ID_COLOR : NOT_SAMPLED_TRACE_ID_COLOR , BaseEncoding . base16 ( ) . lowerCase ( ) . encode ( spanContext . getTraceId ( ) . getBytes ( ) ) , BaseEncoding . base16 ( ) . lowerCase ( ) . encode ( spanContext . getSpanId ( ) . getBytes ( ) ) , BaseEncoding . base16 ( ) . lowerCase ( ) . encode ( span . getParentSpanId ( ) == null ? SpanId . INVALID . getBytes ( ) : span . getParentSpanId ( ) . getBytes ( ) ) ) ; int lastEntryDayOfYear = calendar . get ( Calendar . DAY_OF_YEAR ) ; Timestamp lastTimestampNanos = span . getStartTimestamp ( ) ; TimedEvents < Annotation > annotations = span . getAnnotations ( ) ; TimedEvents < io . opencensus . trace . NetworkEvent > networkEvents = span . getNetworkEvents ( ) ; List < TimedEvent < ? > > timedEvents = new ArrayList < TimedEvent < ? > > ( annotations . getEvents ( ) ) ; timedEvents . addAll ( networkEvents . getEvents ( ) ) ; Collections . sort ( timedEvents , new TimedEventComparator ( ) ) ; for ( TimedEvent < ? > event : timedEvents ) { long deltaMicros = TimeUnit . NANOSECONDS . toMicros ( durationToNanos ( event . getTimestamp ( ) . subtractTimestamp ( lastTimestampNanos ) ) ) ; String deltaString ; if ( deltaMicros >= 1000000 ) { deltaString = String . format ( "%.6f" , ( deltaMicros / 1000000.0 ) ) ; } else { deltaString = String . format ( ".%6d" , deltaMicros ) ; } calendar . setTimeInMillis ( TimeUnit . SECONDS . toMillis ( event . getTimestamp ( ) . getSeconds ( ) ) + TimeUnit . NANOSECONDS . toMillis ( event . getTimestamp ( ) . getNanos ( ) ) ) ; microsField = TimeUnit . NANOSECONDS . toMicros ( event . getTimestamp ( ) . getNanos ( ) ) ; int dayOfYear = calendar . get ( Calendar . DAY_OF_YEAR ) ; if ( dayOfYear == lastEntryDayOfYear ) { formatter . format ( "%11s" , "" ) ; } else { formatter . format ( "%04d/%02d/%02d-" , calendar . get ( Calendar . YEAR ) , calendar . get ( Calendar . MONTH ) + 1 , calendar . get ( Calendar . DAY_OF_MONTH ) ) ; lastEntryDayOfYear = dayOfYear ; } formatter . format ( "%02d:%02d:%02d.%06d %13s ... %s%n" , calendar . get ( Calendar . HOUR_OF_DAY ) , calendar . get ( Calendar . MINUTE ) , calendar . get ( Calendar . SECOND ) , microsField , deltaString , htmlEscaper ( ) . escape ( event . getEvent ( ) instanceof Annotation ? renderAnnotation ( ( Annotation ) event . getEvent ( ) ) : renderNetworkEvents ( ( io . opencensus . trace . NetworkEvent ) castNonNull ( event . getEvent ( ) ) ) ) ) ; lastTimestampNanos = event . getTimestamp ( ) ; } Status status = span . getStatus ( ) ; if ( status != null ) { formatter . format ( "%44s %s%n" , "" , htmlEscaper ( ) . escape ( renderStatus ( status ) ) ) ; } formatter . format ( "%44s %s%n" , "" , htmlEscaper ( ) . escape ( renderAttributes ( span . getAttributes ( ) . getAttributeMap ( ) ) ) ) ; }
Emits the internal html for a single {@link SpanData}.