@Test public void testTranslateSpans() { Span span1 = Span.newBuilder().id("1").traceId("1").name("/a").timestamp(1L).duration(1L).build(); Span span2 = Span.newBuilder().id("2").traceId("2").name("/b").timestamp(2L).duration(1L).build(); Span span3 = Span.newBuilder().id("3").traceId("1").name("/c").timestamp(3L).duration(1L).build(); List<Span> spans = asList(span1, span2, span3); List<com.google.devtools.cloudtrace.v2.Span> stackdriverSpans = new ArrayList<>(SpanTranslator.translate("test-project", spans)); assertThat(stackdriverSpans).hasSize(3); assertThat(stackdriverSpans).extracting(com.google.devtools.cloudtrace.v2.Span::getName) .containsExactlyInAnyOrder( "projects/test-project/traces/00000000000000000000000000000001/spans/0000000000000001", "projects/test-project/traces/00000000000000000000000000000002/spans/0000000000000002", "projects/test-project/traces/00000000000000000000000000000001/spans/0000000000000003"); }
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);  }