@Test public void testTranslateSpanEmptyName() { Span spanNullName = Span.newBuilder().id("1").traceId("1").timestamp(1L).duration(1L).build(); Span spanEmptyName = Span.newBuilder().id("2").traceId("2").name("").timestamp(2L).duration(1L).build(); Span spanNonEmptyName = Span.newBuilder().id("2").traceId("2").name("somename").timestamp(2L).duration(1L).build(); List<Span> spans = asList(spanNullName, spanEmptyName, spanNonEmptyName); List<com.google.devtools.cloudtrace.v2.Span> stackdriverSpans = new ArrayList<>(SpanTranslator.translate("test-project", spans)); assertThat(stackdriverSpans).hasSize(3); assertThat(stackdriverSpans.get(0).getDisplayName().getValue()).isEqualTo("unknown"); assertThat(stackdriverSpans.get(1).getDisplayName().getValue()).isEqualTo("unknown"); assertThat(stackdriverSpans.get(2).getDisplayName().getValue()).isEqualTo("somename"); }
public static List<com.google.devtools.cloudtrace.v2.Span> translate( String projectId, List<Span> zipkinSpans) { List<com.google.devtools.cloudtrace.v2.Span> result = new ArrayList<>(zipkinSpans.size()); for (int i = 0, len = zipkinSpans.size(); i < len; i++) { Span zipkinSpan = zipkinSpans.get(i); com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder = translate( com.google.devtools.cloudtrace.v2.Span.newBuilder(), zipkinSpan); spanBuilder.setName( "projects/" + projectId + "/traces/" + paddedTraceId(zipkinSpan.traceId()) + "/spans/" + zipkinSpan.id()); result.add(spanBuilder.build()); } return result; }
SpanTranslator { public static List<com.google.devtools.cloudtrace.v2.Span> translate( String projectId, List<Span> zipkinSpans) { List<com.google.devtools.cloudtrace.v2.Span> result = new ArrayList<>(zipkinSpans.size()); for (int i = 0, len = zipkinSpans.size(); i < len; i++) { Span zipkinSpan = zipkinSpans.get(i); com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder = translate( com.google.devtools.cloudtrace.v2.Span.newBuilder(), zipkinSpan); spanBuilder.setName( "projects/" + projectId + "/traces/" + paddedTraceId(zipkinSpan.traceId()) + "/spans/" + zipkinSpan.id()); result.add(spanBuilder.build()); } return result; } }
SpanTranslator { public static List<com.google.devtools.cloudtrace.v2.Span> translate( String projectId, List<Span> zipkinSpans) { List<com.google.devtools.cloudtrace.v2.Span> result = new ArrayList<>(zipkinSpans.size()); for (int i = 0, len = zipkinSpans.size(); i < len; i++) { Span zipkinSpan = zipkinSpans.get(i); com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder = translate( com.google.devtools.cloudtrace.v2.Span.newBuilder(), zipkinSpan); spanBuilder.setName( "projects/" + projectId + "/traces/" + paddedTraceId(zipkinSpan.traceId()) + "/spans/" + zipkinSpan.id()); result.add(spanBuilder.build()); } return result; }  }
SpanTranslator { public static List<com.google.devtools.cloudtrace.v2.Span> translate( String projectId, List<Span> zipkinSpans) { List<com.google.devtools.cloudtrace.v2.Span> result = new ArrayList<>(zipkinSpans.size()); for (int i = 0, len = zipkinSpans.size(); i < len; i++) { Span zipkinSpan = zipkinSpans.get(i); com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder = translate( com.google.devtools.cloudtrace.v2.Span.newBuilder(), zipkinSpan); spanBuilder.setName( "projects/" + projectId + "/traces/" + paddedTraceId(zipkinSpan.traceId()) + "/spans/" + zipkinSpan.id()); result.add(spanBuilder.build()); } return result; }  static List<com.google.devtools.cloudtrace.v2.Span> translate(
      String projectId, List<Span> zipkinSpans); static com.google.devtools.cloudtrace.v2.Span.Builder translate(
      com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder,
      Span zipkinSpan); }
SpanTranslator { public static List<com.google.devtools.cloudtrace.v2.Span> translate( String projectId, List<Span> zipkinSpans) { List<com.google.devtools.cloudtrace.v2.Span> result = new ArrayList<>(zipkinSpans.size()); for (int i = 0, len = zipkinSpans.size(); i < len; i++) { Span zipkinSpan = zipkinSpans.get(i); com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder = translate( com.google.devtools.cloudtrace.v2.Span.newBuilder(), zipkinSpan); spanBuilder.setName( "projects/" + projectId + "/traces/" + paddedTraceId(zipkinSpan.traceId()) + "/spans/" + zipkinSpan.id()); result.add(spanBuilder.build()); } return result; }  static List<com.google.devtools.cloudtrace.v2.Span> translate(
      String projectId, List<Span> zipkinSpans); static com.google.devtools.cloudtrace.v2.Span.Builder translate(
      com.google.devtools.cloudtrace.v2.Span.Builder spanBuilder,
      Span zipkinSpan);  }