zipkin2.codec.SpanBytesEncoder Java Examples

The following examples show how to use zipkin2.codec.SpanBytesEncoder. 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: AsyncReporterTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
@Test
public void flush_incrementsMetrics() {
  reporter = AsyncReporter.builder(FakeSender.create())
      .metrics(metrics)
      .messageMaxBytes(sizeInBytesOfSingleSpanMessage)
      .messageTimeout(0, TimeUnit.MILLISECONDS)
      .build();

  // Queue up 2 spans
  reporter.report(span);
  reporter.report(span);

  reporter.flush();
  assertThat(metrics.queuedSpans()).isEqualTo(1); // still one span in the backlog
  assertThat(metrics.queuedBytes()).isEqualTo(SpanBytesEncoder.JSON_V2.encode(span).length);
  assertThat(metrics.messages()).isEqualTo(1);
  assertThat(metrics.messageBytes()).isEqualTo(sizeInBytesOfSingleSpanMessage);

  reporter.flush();
  assertThat(metrics.queuedSpans()).isZero();
  assertThat(metrics.queuedBytes()).isZero();
  assertThat(metrics.messages()).isEqualTo(2);
  assertThat(metrics.messageBytes()).isEqualTo(sizeInBytesOfSingleSpanMessage * 2);
}
 
Example #2
Source File: ZipkinQueryApiV2.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
static byte[] writeTraces(SpanBytesEncoder codec, List<List<zipkin2.Span>> traces) {
  // Get the encoded size of the nested list so that we don't need to grow the buffer
  int length = traces.size();
  int sizeInBytes = 2; // []
  if (length > 1) sizeInBytes += length - 1; // comma to join elements

  for (int i = 0; i < length; i++) {
    List<zipkin2.Span> spans = traces.get(i);
    int jLength = spans.size();
    sizeInBytes += 2; // []
    if (jLength > 1) sizeInBytes += jLength - 1; // comma to join elements
    for (int j = 0; j < jLength; j++) {
      sizeInBytes += codec.sizeInBytes(spans.get(j));
    }
  }

  byte[] out = new byte[sizeInBytes];
  int pos = 0;
  out[pos++] = '['; // start list of traces
  for (int i = 0; i < length; i++) {
    pos += codec.encodeList(traces.get(i), out, pos);
    if (i + 1 < length) out[pos++] = ',';
  }
  out[pos] = ']'; // stop list of traces
  return out;
}
 
Example #3
Source File: URLConnectionSenderTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
Call<Void> send(Span... spans) {
  SpanBytesEncoder bytesEncoder;
  switch (sender.encoding()) {
    case JSON:
      bytesEncoder = SpanBytesEncoder.JSON_V2;
      break;
    case THRIFT:
      bytesEncoder = SpanBytesEncoder.THRIFT;
      break;
    case PROTO3:
      bytesEncoder = SpanBytesEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("encoding: " + sender.encoding());
  }
  return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}
 
Example #4
Source File: ZipkinExporterConfigurationTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void updateConfigs() {
  ZipkinExporterConfiguration configuration =
      ZipkinExporterConfiguration.builder()
          .setServiceName(SERVICE)
          .setDeadline(ONE_MIN)
          .setSender(mockSender)
          .setV2Url(END_POINT)
          .setEncoder(SpanBytesEncoder.PROTO3)
          .build();
  assertThat(configuration.getServiceName()).isEqualTo(SERVICE);
  assertThat(configuration.getDeadline()).isEqualTo(ONE_MIN);
  assertThat(configuration.getV2Url()).isEqualTo(END_POINT);
  assertThat(configuration.getSender()).isEqualTo(mockSender);
  assertThat(configuration.getEncoder()).isEqualTo(SpanBytesEncoder.PROTO3);
}
 
Example #5
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
static byte[] writeTraces(List<List<Span>> traces) {
  // Get the encoded size of the nested list so that we don't need to grow the buffer
  int length = traces.size();
  int sizeInBytes = 2; // []
  if (length > 1) sizeInBytes += length - 1; // comma to join elements

  for (List<Span> spans : traces) {
    int jLength = spans.size();
    sizeInBytes += 2; // []
    if (jLength > 1) sizeInBytes += jLength - 1; // comma to join elements
    for (Span span : spans) {
      sizeInBytes += SpanBytesEncoder.JSON_V2.sizeInBytes(span);
    }
  }

  byte[] out = new byte[sizeInBytes];
  int pos = 0;
  out[pos++] = '['; // start list of traces
  for (int i = 0; i < length; i++) {
    pos += SpanBytesEncoder.JSON_V2.encodeList(traces.get(i), out, pos);
    if (i + 1 < length) out[pos++] = ',';
  }
  out[pos] = ']'; // stop list of traces
  return out;
}
 
Example #6
Source File: KinesisSpanProcessorTest.java    From zipkin-aws with Apache License 2.0 6 votes vote down vote up
@Test
public void collectorFailsWhenRecordEncodedAsSingleSpan() {
  Span span = TestObjects.LOTS_OF_SPANS[0];
  byte[] encodedSpan = SpanBytesEncoder.THRIFT.encode(span);
  Record kinesisRecord = new Record().withData(ByteBuffer.wrap(encodedSpan));
  ProcessRecordsInput kinesisInput =
      new ProcessRecordsInput().withRecords(Collections.singletonList(kinesisRecord));

  kinesisSpanProcessor.processRecords(kinesisInput);

  assertThat(storage.spanStore().getTraces().size()).isEqualTo(0);

  assertThat(metrics.messages()).isEqualTo(1);
  assertThat(metrics.messagesDropped()).isEqualTo(1);
  assertThat(metrics.bytes()).isEqualTo(encodedSpan.length);
}
 
Example #7
Source File: ZipkinQueryApiV2.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/traces", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public String getTraces(
    @Nullable @RequestParam(value = "serviceName", required = false) String serviceName,
    @Nullable @RequestParam(value = "spanName", required = false) String spanName,
    @Nullable @RequestParam(value = "annotationQuery", required = false) String annotationQuery,
    @Nullable @RequestParam(value = "minDuration", required = false) Long minDuration,
    @Nullable @RequestParam(value = "maxDuration", required = false) Long maxDuration,
    @Nullable @RequestParam(value = "endTs", required = false) Long endTs,
    @Nullable @RequestParam(value = "lookback", required = false) Long lookback,
    @RequestParam(value = "limit", defaultValue = "10") int limit)
    throws IOException {
  QueryRequest queryRequest =
      QueryRequest.newBuilder()
          .serviceName(serviceName)
          .spanName(spanName)
          .parseAnnotationQuery(annotationQuery)
          .minDuration(minDuration)
          .maxDuration(maxDuration)
          .endTs(endTs != null ? endTs : System.currentTimeMillis())
          .lookback(lookback != null ? lookback : defaultLookback)
          .limit(limit)
          .build();

  List<List<Span>> traces = storage.spanStore().getTraces(queryRequest).execute();
  return new String(writeTraces(SpanBytesEncoder.JSON_V2, traces), UTF_8);
}
 
Example #8
Source File: KafkaStorageHttpService.java    From zipkin-storage-kafka with Apache License 2.0 6 votes vote down vote up
@Get("/traces/:trace_id")
public AggregatedHttpResponse getTrace(@Param("trace_id") String traceId) {
  try {
    if (!storage.traceByIdQueryEnabled) return AggregatedHttpResponse.of(HttpStatus.NOT_FOUND);
    ReadOnlyKeyValueStore<String, List<Span>> store =
        storage.getTraceStorageStream()
            .store(TRACES_STORE_NAME, QueryableStoreTypes.keyValueStore());
    List<Span> spans = store.get(traceId);
    return AggregatedHttpResponse.of(
        HttpStatus.OK,
        MediaType.JSON,
        SpanBytesEncoder.JSON_V2.encodeList(spans));
  } catch (InvalidStateStoreException e) {
    LOG.debug("State store is not ready", e);
    return AggregatedHttpResponse.of(HttpStatus.SERVICE_UNAVAILABLE);
  }
}
 
Example #9
Source File: ITZipkinMetricsHealth.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test public void writeSpans_updatesMetrics() throws Exception {
  List<Span> spans = asList(LOTS_OF_SPANS[0], LOTS_OF_SPANS[1], LOTS_OF_SPANS[2]);
  byte[] body = SpanBytesEncoder.JSON_V2.encodeList(spans);
  double messagesCount =
    registry.counter("zipkin_collector.messages", "transport", "http").count();
  double bytesCount = registry.counter("zipkin_collector.bytes", "transport", "http").count();
  double spansCount = registry.counter("zipkin_collector.spans", "transport", "http").count();
  post("/api/v2/spans", body);
  post("/api/v2/spans", body);

  String json = getAsString("/metrics");

  assertThat(readDouble(json, "$.['counter.zipkin_collector.messages.http']"))
    .isEqualTo(messagesCount + 2.0);
  assertThat(readDouble(json, "$.['counter.zipkin_collector.bytes.http']"))
    .isEqualTo(bytesCount + (body.length * 2));
  assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_bytes.http']"))
    .isEqualTo(body.length);
  assertThat(readDouble(json, "$.['counter.zipkin_collector.spans.http']"))
    .isEqualTo(spansCount + (spans.size() * 2));
  assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_spans.http']"))
    .isEqualTo(spans.size());
}
 
Example #10
Source File: ZipkinServerTest.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test public void readsBackSpanName() throws Exception {
  String service = "web";
  Span span = Span.newBuilder().traceId("463ac35c9f6413ad48485a3953bb6124").id("a")
    .name("test-span")
    .localEndpoint(Endpoint.newBuilder().serviceName(service).build())
    .addAnnotation(System.currentTimeMillis() * 1000L, "hello").build();

  byte[] spansInJson = SpanBytesEncoder.JSON_V2.encodeList(Collections.singletonList(span));

  // write the span to the server
  Response post = post("/api/v2/spans", spansInJson);
  assertThat(post.isSuccessful()).isTrue();

  // sleep as the the storage operation is async
  Thread.sleep(1000);

  // read back the span name, given its service
  Response get = get("/api/v2/spans?serviceName=" + service);
  assertThat(get.isSuccessful()).isTrue();
  assertThat(get.body().string())
    .isEqualTo("[\"" + span.name() + "\"]");
}
 
Example #11
Source File: StrictTraceIdFalseTest.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test
public void canSearchByLower64Bits() throws IOException {
  Span span = Span.newBuilder().traceId("463ac35c9f6413ad48485a3953bb6124").id("a")
    .name("test-span")
    .localEndpoint(Endpoint.newBuilder().serviceName("foo-service").build())
    .addAnnotation(System.currentTimeMillis() * 1000L, "hello").build();

  byte[] spansInJson = SpanBytesEncoder.JSON_V2.encodeList(Collections.singletonList(span));

  client.newCall(new Request.Builder()
      .url("http://localhost:" + zipkin.port() + "/api/v2/spans")
      .post(RequestBody.create(MediaType.parse("application/json"), spansInJson)).build())
      .execute();

  Response response = client.newCall(new Request.Builder()
      .url("http://localhost:" + zipkin.port() + "/api/v2/trace/" + span.traceId())
      .build()).execute();

  assertEquals(span, SpanBytesDecoder.JSON_V2.decodeList(response.body().bytes()).get(0));
}
 
Example #12
Source File: ITZipkinMetricsHealth.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
/** Makes sure the prometheus filter doesn't count twice */
@Test public void writeSpans_updatesPrometheusMetrics() throws Exception {
  List<Span> spans = asList(LOTS_OF_SPANS[0], LOTS_OF_SPANS[1], LOTS_OF_SPANS[2]);
  byte[] body = SpanBytesEncoder.JSON_V2.encodeList(spans);

  post("/api/v2/spans", body);
  post("/api/v2/spans", body);

  double messagesCount = registry.counter("zipkin_collector.spans", "transport", "http").count();
  // Get the http count from the registry and it should match the summation previous count
  // and count of calls below
  long httpCount = registry
    .find("http.server.requests")
    .tag("uri", "/api/v2/spans")
    .timer()
    .count();

  // ensure unscoped counter does not exist
  assertThat(scrape())
    .doesNotContain("zipkin_collector_spans_total " + messagesCount)
    .contains("zipkin_collector_spans_total{transport=\"http\",} " + messagesCount)
    .contains(
      "http_server_requests_seconds_count{method=\"POST\",status=\"202\",uri=\"/api/v2/spans\",} "
        + httpCount);
}
 
Example #13
Source File: ITZipkinMetricsHealth.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test public void writesSpans_readMetricsFormat() throws Exception {
  byte[] span = {'z', 'i', 'p', 'k', 'i', 'n'};
  List<Span> spans = asList(LOTS_OF_SPANS[0], LOTS_OF_SPANS[1], LOTS_OF_SPANS[2]);
  byte[] body = SpanBytesEncoder.JSON_V2.encodeList(spans);
  post("/api/v2/spans", body);
  post("/api/v2/spans", body);
  post("/api/v2/spans", span);
  Thread.sleep(1500);

  String metrics = getAsString("/metrics");

  assertThat(readJson(metrics))
    .containsExactlyInAnyOrder(
      "gauge.zipkin_collector.message_spans.http"
      , "gauge.zipkin_collector.message_bytes.http"
      , "counter.zipkin_collector.messages.http"
      , "counter.zipkin_collector.bytes.http"
      , "counter.zipkin_collector.spans.http"
      , "counter.zipkin_collector.messages_dropped.http"
      , "counter.zipkin_collector.spans_dropped.http"
    );
}
 
Example #14
Source File: ITKafkaSender.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
Call<Void> send(Span... spans) {
  SpanBytesEncoder bytesEncoder;
  switch (sender.encoding()) {
    case JSON:
      bytesEncoder = SpanBytesEncoder.JSON_V2;
      break;
    case THRIFT:
      bytesEncoder = SpanBytesEncoder.THRIFT;
      break;
    case PROTO3:
      bytesEncoder = SpanBytesEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("encoding: " + sender.encoding());
  }
  return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}
 
Example #15
Source File: ITZipkinServer.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test public void writeSpans_gzipEncoded() throws Exception {
  byte[] message = SpanBytesEncoder.JSON_V2.encodeList(TRACE);

  Buffer sink = new Buffer();
  GzipSink gzipSink = new GzipSink(sink);
  gzipSink.write(new Buffer().write(message), message.length);
  gzipSink.close();
  byte[] gzippedBody = sink.readByteArray();

  Response response = client.newCall(new Request.Builder()
    .url("http://localhost:" + zipkinPort + "/api/v2/spans")
    .header("Content-Encoding", "gzip")
    .post(RequestBody.create(null, gzippedBody))
    .build()).execute();

  assertThat(response.isSuccessful());
}
 
Example #16
Source File: OkHttpSenderTest.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
Call<Void> send(Span... spans) {
  SpanBytesEncoder bytesEncoder;
  switch (sender.encoding()) {
    case JSON:
      bytesEncoder = SpanBytesEncoder.JSON_V2;
      break;
    case THRIFT:
      bytesEncoder = SpanBytesEncoder.THRIFT;
      break;
    case PROTO3:
      bytesEncoder = SpanBytesEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("encoding: " + sender.encoding());
  }
  return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}
 
Example #17
Source File: ITZipkinServer.java    From pivotal-bank-demo with Apache License 2.0 6 votes vote down vote up
@Test public void setsCacheControlOnNameEndpointsWhenMoreThan3Services() throws Exception {
  List<String> services = Arrays.asList("foo", "bar", "baz", "quz");
  for (int i = 0; i < services.size(); i++) {
    post("/api/v2/spans", SpanBytesEncoder.JSON_V2.encodeList(Arrays.asList(
      Span.newBuilder().traceId("a").id(i + 1).timestamp(TODAY).name("whopper").localEndpoint(
        Endpoint.newBuilder().serviceName(services.get(i)).build()
      ).build()
    )));
  }

  assertThat(get("/api/v2/services").header("Cache-Control"))
    .isEqualTo("max-age=300, must-revalidate");

  assertThat(get("/api/v2/spans?serviceName=web").header("Cache-Control"))
    .isEqualTo("max-age=300, must-revalidate");
}
 
Example #18
Source File: ITActiveMQSender.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
Call<Void> send(Span... spans) {
  SpanBytesEncoder bytesEncoder;
  switch (sender.encoding()) {
    case JSON:
      bytesEncoder = SpanBytesEncoder.JSON_V2;
      break;
    case THRIFT:
      bytesEncoder = SpanBytesEncoder.THRIFT;
      break;
    case PROTO3:
      bytesEncoder = SpanBytesEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("encoding: " + sender.encoding());
  }
  return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}
 
Example #19
Source File: ITKafkaSender.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
Call<Void> send(Span... spans) {
  SpanBytesEncoder bytesEncoder;
  switch (sender.encoding()) {
    case JSON:
      bytesEncoder = SpanBytesEncoder.JSON_V2;
      break;
    case THRIFT:
      bytesEncoder = SpanBytesEncoder.THRIFT;
      break;
    case PROTO3:
      bytesEncoder = SpanBytesEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("encoding: " + sender.encoding());
  }
  return sender.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}
 
Example #20
Source File: ScribeSenderTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test
public void makeRequest() throws TException {
  Endpoint web = Endpoint.newBuilder().serviceName("web").ip("127.0.0.1").build();
  Span span1 =
      Span.newBuilder()
          .traceId(FinagleTestObjects.root.traceId().toString())
          .id(FinagleTestObjects.root.spanId().toLong())
          .name("get")
          .timestamp(FinagleTestObjects.TODAY * 1000)
          .duration(1000L)
          .kind(Span.Kind.SERVER)
          .localEndpoint(web)
          .build();

  Span span2 =
      span1
          .toBuilder()
          .kind(Span.Kind.CLIENT)
          .parentId(FinagleTestObjects.child.parentId().toLong())
          .id(FinagleTestObjects.child.spanId().toLong())
          .build();

  new ScribeSender(config)
      .makeRequest(
          asList(SpanBytesEncoder.THRIFT.encode(span1), SpanBytesEncoder.THRIFT.encode(span2)));
}
 
Example #21
Source File: ITLibthriftSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpansExpectedMetrics() throws Exception {
  send(CLIENT_SPAN, CLIENT_SPAN);

  assertThat(scribeCollectorMetrics.messages()).isEqualTo(1);
  assertThat(scribeCollectorMetrics.messagesDropped()).isZero();
  assertThat(scribeCollectorMetrics.spans()).isEqualTo(2);
  assertThat(scribeCollectorMetrics.spansDropped()).isZero();
  byte[] thrift = SpanBytesEncoder.THRIFT.encode(CLIENT_SPAN);

  // span bytes is cumulative thrift size, not message size
  assertThat(scribeCollectorMetrics.bytes()).isEqualTo(thrift.length * 2);
}
 
Example #22
Source File: ZipkinTest.java    From hippo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
        URLConnectionSender sender = URLConnectionSender.create("http://103.10.0.67:9411/api/v2/spans");
        AsyncReporter reporter = AsyncReporter.builder(sender)
                .closeTimeout(100, TimeUnit.MILLISECONDS)
                .build(SpanBytesEncoder.JSON_V2);
        Tracing tracing = Tracing.newBuilder()
                .localServiceName("test1")
                .spanReporter(reporter)
                .propagationFactory(B3Propagation.FACTORY)
                .currentTraceContext(ThreadLocalCurrentTraceContext.create())
                .build();
        Tracer tracer = tracing.tracer();
        tracer.startScopedSpan("t1");
        Span span = tracer.newTrace().annotate("111").start();
        span.kind(Span.Kind.CLIENT);
       // span1.finish();
        // System.out.println(  span.context().traceId());
        //System.out.println(  span.context().spanId());
        //tracer.nextSpan().start();

       // Span span2=tracer.newChild(TraceContext.newBuilder().parentId(span.context().spanId()).traceId(span.context().traceId()).spanId(span.context().spanId()).build()).name("eeeee").annotate("222").start();
        // Span span2 = tracer.newChild(TraceContext.newBuilder().parentId(span.context().spanId()).traceId(span.context().traceId()).spanId(span.context().spanId()).build()).name("eeeee").start();
       // span2.kind(Span.Kind.SERVER);
//         System.out.println(  span.context().traceId());
//        System.out.println(  span.context().spanId());
        //System.out.println(span.annotate("").kind(Span.Kind.CLIENT));
        //Span action_1 = tracer.newChild(span.context()).name("action-1").start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            //span1.finish();
            span.finish();
            //    action_1.finish();
        }
        Thread.sleep(100000000L);
    }
 
Example #23
Source File: InternalScribeCodecTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void base64SizeInBytes() {
  Endpoint web = Endpoint.newBuilder().serviceName("web").ip("127.0.0.1").build();

  Span span1 =
      Span.newBuilder()
          .traceId("d2f9288a2904503d")
          .id("d2f9288a2904503d")
          .name("get")
          .timestamp(TODAY * 1000)
          .duration(1000L)
          .kind(Span.Kind.SERVER)
          .localEndpoint(web)
          .build();

  Span span2 =
      span1
          .toBuilder()
          .kind(Span.Kind.CLIENT)
          .traceId("d2f9288a2904503d")
          .parentId("d2f9288a2904503d")
          .id("0f28590523a46541")
          .build();

  byte[] thrift1 = SpanBytesEncoder.THRIFT.encode(span1);
  assertThat(InternalScribeCodec.base64(thrift1))
      .hasSize(InternalScribeCodec.base64SizeInBytes(thrift1.length));

  byte[] thrift2 = SpanBytesEncoder.THRIFT.encode(span2);
  assertThat(InternalScribeCodec.base64(thrift2))
      .hasSize(InternalScribeCodec.base64SizeInBytes(thrift2.length));
}
 
Example #24
Source File: KinesisSpanProcessorTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
void messageWithMultipleSpans(SpanBytesEncoder encoder) {
  byte[] message = encoder.encodeList(spans);

  List<Record> records = Arrays.asList(new Record().withData(ByteBuffer.wrap(message)));
  kinesisSpanProcessor.processRecords(new ProcessRecordsInput().withRecords(records));

  assertThat(storage.spanStore().getTraces().size()).isEqualTo(spans.size());
}
 
Example #25
Source File: InternalScribeCodecTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void sendsSpanExpectedMetrics() throws Exception {
  byte[] thrift = SpanBytesEncoder.THRIFT.encode(CLIENT_SPAN);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  TBinaryProtocol prot = new TBinaryProtocol(new TIOStreamTransport(out));

  InternalScribeCodec.writeLogRequest(ScribeClient.category, Arrays.asList(thrift), 1, prot);

  assertThat(InternalScribeCodec.messageSizeInBytes(ScribeClient.category, Arrays.asList(thrift)))
      .isEqualTo(out.size());

  assertThat(InternalScribeCodec.messageSizeInBytes(ScribeClient.category, thrift.length))
      .isEqualTo(out.size());
}
 
Example #26
Source File: ZipkinExporterConfiguration.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new {@link Builder}.
 *
 * @return a {@code Builder}.
 * @since 0.22
 */
public static Builder builder() {
  return new AutoValue_ZipkinExporterConfiguration.Builder()
      .setV2Url("")
      .setEncoder(SpanBytesEncoder.JSON_V2)
      .setDeadline(DEFAULT_DEADLINE);
}
 
Example #27
Source File: AsyncReporter.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
/** Builds an async reporter that encodes zipkin spans as they are reported. */
public AsyncReporter<Span> build() {
  switch (sender.encoding()) {
    case JSON:
      return build(SpanBytesEncoder.JSON_V2);
    case PROTO3:
      return build(SpanBytesEncoder.PROTO3);
    case THRIFT:
      return build(SpanBytesEncoder.THRIFT);
    default:
      throw new UnsupportedOperationException(sender.encoding().name());
  }
}
 
Example #28
Source File: FakeSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
public static FakeSender create() {
  return new FakeSender(
      Encoding.JSON,
      Integer.MAX_VALUE,
      BytesMessageEncoder.forEncoding(Encoding.JSON),
      SpanBytesEncoder.JSON_V2,
      SpanBytesDecoder.JSON_V2,
      spans -> {
      }
  );
}
 
Example #29
Source File: AsyncReporterTest.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
@Test
public void report_incrementsMetrics() {
  reporter = AsyncReporter.builder(FakeSender.create())
      .metrics(metrics)
      .messageTimeout(0, TimeUnit.MILLISECONDS)
      .build();

  reporter.report(span);
  reporter.report(span);
  assertThat(metrics.spans()).isEqualTo(2);
  assertThat(metrics.spanBytes()).isEqualTo(SpanBytesEncoder.JSON_V2.encode(span).length * 2);
}
 
Example #30
Source File: KinesisSpanProcessorTest.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
private ProcessRecordsInput createTestData(int count) {
  List<Record> records = new ArrayList<>();

  Span[] spans = Arrays.copyOfRange(TestObjects.LOTS_OF_SPANS, 0, count);

  Arrays.stream(spans)
      .map(s -> ByteBuffer.wrap(SpanBytesEncoder.THRIFT.encodeList(Collections.singletonList(s))))
      .map(b -> new Record().withData(b))
      .forEach(records::add);

  return new ProcessRecordsInput().withRecords(records);
}