zipkin2.codec.SpanBytesDecoder Java Examples
The following examples show how to use
zipkin2.codec.SpanBytesDecoder.
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: UdpReporterTest.java From servicetalk with Apache License 2.0 | 7 votes |
TestReceiver(SpanBytesDecoder decoder) throws Exception { channel = new Bootstrap() .group(group) .channel(NioDatagramChannel.class) .option(ChannelOption.RCVBUF_ALLOCATOR, DEFAULT_RECV_BUF_ALLOCATOR) .handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) { ch.pipeline().addLast(new SimpleChannelInboundHandler<DatagramPacket>() { @Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) { byte[] b = new byte[msg.content().readableBytes()]; msg.content().readBytes(b); decoder.decode(b, queue); } }); } }) .localAddress(localAddress(0)) .bind().sync().channel(); }
Example #2
Source File: RoutingConfig.java From pitchfork with Apache License 2.0 | 6 votes |
/** * This service does not support any of the read operations. * At this moment we support {@code POST}s for the v1 api encoded in Json or Thrift, or for the v2 api in Json. */ @Bean public RouterFunction<ServerResponse> myRoutes(ZipkinController zipkinController, MetersProvider metersProvider) { var counterJsonV1 = metersProvider.getSpansCounter("http", "jsonv1"); var counterJsonV2 = metersProvider.getSpansCounter("http", "jsonv2"); var counterThrift = metersProvider.getSpansCounter("http", "thrift"); var counterProtobuf = metersProvider.getSpansCounter("http", "protobuf"); return nest(method(HttpMethod.POST), nest(contentType(APPLICATION_JSON), route(path("/api/v1/spans"), request -> zipkinController.addSpans(request, SpanBytesDecoder.JSON_V1, counterJsonV1)) .andRoute(path("/api/v2/spans"), request -> zipkinController.addSpans(request, SpanBytesDecoder.JSON_V2, counterJsonV2))) .andRoute(contentType(APPLICATION_THRIFT), request -> zipkinController.addSpans(request, SpanBytesDecoder.THRIFT, counterThrift)) .andRoute(contentType(APPLICATION_PROTOBUF), request -> zipkinController.addSpans(request, SpanBytesDecoder.PROTO3, counterProtobuf))) .andRoute(RequestPredicates.all(), zipkinController::unmatched); }
Example #3
Source File: SpanV2JettyHandler.java From skywalking with Apache License 2.0 | 6 votes |
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); try { String type = request.getHeader("Content-Type"); int encode = type != null && type.contains("/x-protobuf") ? SpanEncode.PROTO3 : SpanEncode.JSON_V2; SpanBytesDecoder decoder = SpanEncode.isProto3(encode) ? SpanBytesDecoder.PROTO3 : SpanBytesDecoder.JSON_V2; SpanProcessor processor = new SpanProcessor(sourceReceiver); processor.convert(config, decoder, request); response.setStatus(202); } catch (Exception e) { response.setStatus(500); logger.error(e.getMessage(), e); } }
Example #4
Source File: SpanV1JettyHandler.java From skywalking with Apache License 2.0 | 6 votes |
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); try { String type = request.getHeader("Content-Type"); int encode = type != null && type.contains("/x-thrift") ? SpanEncode.THRIFT : SpanEncode.JSON_V1; SpanBytesDecoder decoder = SpanEncode.isThrift(encode) ? SpanBytesDecoder.THRIFT : SpanBytesDecoder.JSON_V1; SpanProcessor processor = new SpanProcessor(sourceReceiver); processor.convert(config, decoder, request); response.setStatus(202); } catch (Exception e) { response.setStatus(500); logger.error(e.getMessage(), e); } }
Example #5
Source File: SpanProcessor.java From skywalking with Apache License 2.0 | 6 votes |
void convert(ZipkinReceiverConfig config, SpanBytesDecoder decoder, HttpServletRequest request) throws IOException { InputStream inputStream = getInputStream(request); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int readCntOnce; while ((readCntOnce = inputStream.read(buffer)) >= 0) { out.write(buffer, 0, readCntOnce); } List<Span> spanList = decoder.decodeList(out.toByteArray()); if (config.isNeedAnalysis()) { ZipkinSkyWalkingTransfer transfer = new ZipkinSkyWalkingTransfer(); transfer.doTransfer(config, spanList); } else { SpanForward forward = new SpanForward(config, receiver); forward.send(spanList); } }
Example #6
Source File: ZipkinTests.java From spring-cloud-sleuth with Apache License 2.0 | 6 votes |
void spansSentToZipkin(MockWebServer zipkin, long traceId) throws InterruptedException { RecordedRequest request = zipkin.takeRequest(); List<Span> spans = SpanBytesDecoder.JSON_V2 .decodeList(request.getBody().readByteArray()); List<String> traceIdsNotFoundInZipkin = traceIdsNotFoundInZipkin(spans, traceId); List<String> serviceNamesNotFoundInZipkin = serviceNamesNotFoundInZipkin(spans); List<String> tagsNotFoundInZipkin = hasRequiredTag(spans); log.info(String.format("The following trace IDs were not found in Zipkin %s", traceIdsNotFoundInZipkin)); log.info(String.format("The following services were not found in Zipkin %s", serviceNamesNotFoundInZipkin)); log.info(String.format("The following tags were not found in Zipkin %s", tagsNotFoundInZipkin)); then(traceIdsNotFoundInZipkin).isEmpty(); then(serviceNamesNotFoundInZipkin).isEmpty(); then(tagsNotFoundInZipkin).isEmpty(); log.info("Zipkin tracing is working! Sleuth is working! Let's be happy!"); }
Example #7
Source File: KafkaRecordsConsumer.java From pitchfork with Apache License 2.0 | 6 votes |
public void initialize() { logger.info("operation=initialize"); String sourceFormat = properties.getSourceFormat(); SpanBytesDecoder decoder = SpanBytesDecoder.valueOf(sourceFormat); Counter spansCounter = metersProvider.getSpansCounter("tcp", "kafka"); int numberOfConsumers = properties.getNumberConsumers(); ExecutorService executor = Executors.newFixedThreadPool(numberOfConsumers); for (int i = 0; i < numberOfConsumers; i++) { KafkaConsumerLoop consumer = new KafkaConsumerLoop( properties, fork, spanValidator, decoder, spansCounter, meterRegistry); consumer.initialize(); consumers.add(consumer); executor.submit(consumer); } }
Example #8
Source File: StrictTraceIdFalseTest.java From pivotal-bank-demo with Apache License 2.0 | 6 votes |
@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 #9
Source File: ZipkinHttpCollector.java From pivotal-bank-demo with Apache License 2.0 | 6 votes |
@Autowired ZipkinHttpCollector( StorageComponent storage, CollectorSampler sampler, CollectorMetrics metrics) { this.metrics = metrics.forTransport("http"); this.collector = Collector.newBuilder(getClass()) .storage(storage) .sampler(sampler) .metrics(this.metrics) .build(); this.JSON_V2 = new HttpCollector(SpanBytesDecoder.JSON_V2); this.PROTO3 = new HttpCollector(SpanBytesDecoder.PROTO3); this.JSON_V1 = new HttpCollector(SpanBytesDecoder.JSON_V1); this.THRIFT = new HttpCollector(SpanBytesDecoder.THRIFT); this.errorCallback = new Receiver.ErrorCallback() { @Override public void error(HttpServerExchange exchange, IOException e) { ZipkinHttpCollector.this.metrics.incrementMessagesDropped(); ZipkinHttpCollector.error(exchange, e); } }; }
Example #10
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_THRIFT() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.THRIFT).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.THRIFT.decodeList(readMessages().get(0))) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #11
Source File: OkHttpSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_THRIFT() throws Exception { sender = sender.toBuilder().encoding(Encoding.THRIFT).build(); server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.THRIFT.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #12
Source File: OkHttpSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.PROTO3.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #13
Source File: OkHttpSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans() throws Exception { server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.JSON_V2.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #14
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpansToCorrectTopic() throws Exception { sender.close(); sender = sender.toBuilder().topic("customzipkintopic").build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.JSON_V2.decodeList(readMessages("customzipkintopic").get(0))) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #15
Source File: FakeSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
public static FakeSender create() { return new FakeSender( Encoding.JSON, Integer.MAX_VALUE, BytesMessageEncoder.forEncoding(Encoding.JSON), SpanBytesEncoder.JSON_V2, SpanBytesDecoder.JSON_V2, spans -> { } ); }
Example #16
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessages().get(0))) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #17
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans() throws Exception { send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.JSON_V2.decodeList(readMessages().get(0))) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #18
Source File: URLConnectionSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_THRIFT() throws Exception { sender = sender.toBuilder().encoding(Encoding.THRIFT).build(); server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.THRIFT.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #19
Source File: URLConnectionSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.PROTO3.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #20
Source File: URLConnectionSenderTest.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans() throws Exception { server.enqueue(new MockResponse()); send(CLIENT_SPAN, CLIENT_SPAN).execute(); // Ensure only one request was sent assertThat(server.getRequestCount()).isEqualTo(1); // Now, let's read back the spans we sent! assertThat(SpanBytesDecoder.JSON_V2.decodeList(server.takeRequest().getBody().readByteArray())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #21
Source File: ITActiveMQSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender.close(); sender = builder().encoding(Encoding.PROTO3).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #22
Source File: ITActiveMQSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_THRIFT() throws Exception { sender.close(); sender = builder().encoding(Encoding.THRIFT).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.THRIFT.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #23
Source File: ITActiveMQSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpansToCorrectQueue() throws Exception { sender.close(); sender = builder().queue("customzipkinqueue").build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.JSON_V2.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #24
Source File: ITRabbitMQSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender.close(); sender = rabbit.tryToInitializeSender(rabbit.newSenderBuilder().encoding(Encoding.PROTO3)); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #25
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans() throws Exception { send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.JSON_V2.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #26
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_PROTO3() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.PROTO3).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.PROTO3.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #27
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpans_THRIFT() throws Exception { sender.close(); sender = sender.toBuilder().encoding(Encoding.THRIFT).build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.THRIFT.decodeList(readMessage())) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #28
Source File: ITKafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
@Test public void sendsSpansToCorrectTopic() throws Exception { sender.close(); sender = sender.toBuilder().topic("customzipkintopic").build(); send(CLIENT_SPAN, CLIENT_SPAN).execute(); assertThat(SpanBytesDecoder.JSON_V2.decodeList(readMessage("customzipkintopic"))) .containsExactly(CLIENT_SPAN, CLIENT_SPAN); }
Example #29
Source File: ElasticsearchDependenciesJob.java From zipkin-dependencies with Apache License 2.0 | 5 votes |
public void run() { run( // single-type index index + ":span-" + dateStamp + "/span", index + ":dependency-" + dateStamp + "/dependency", SpanBytesDecoder.JSON_V2); run( // single-type index with ES 7+ index + "-span-" + dateStamp, index + "-dependency-" + dateStamp, SpanBytesDecoder.JSON_V2); log.info("Done"); }
Example #30
Source File: ElasticsearchDependenciesJob.java From zipkin-dependencies with Apache License 2.0 | 5 votes |
void run(String spanResource, String dependencyLinkResource, SpanBytesDecoder decoder) { log.info("Processing spans from {}", spanResource); JavaSparkContext sc = new JavaSparkContext(conf); try { JavaRDD<Map<String, Object>> links = JavaEsSpark.esJsonRDD(sc, spanResource) .groupBy(JSON_TRACE_ID) .flatMapValues(new TraceIdAndJsonToDependencyLinks(logInitializer, decoder)) .values() .mapToPair(l -> Tuple2.apply(Tuple2.apply(l.parent(), l.child()), l)) .reduceByKey((l, r) -> DependencyLink.newBuilder() .parent(l.parent()) .child(l.child()) .callCount(l.callCount() + r.callCount()) .errorCount(l.errorCount() + r.errorCount()) .build()) .values() .map(DEPENDENCY_LINK_JSON); if (links.isEmpty()) { log.info("No dependency links could be processed from spans in index {}", spanResource); } else { log.info("Saving dependency links to {}", dependencyLinkResource); JavaEsSpark.saveToEs( links, dependencyLinkResource, Collections.singletonMap("es.mapping.id", "id")); // allows overwriting the link } } finally { sc.stop(); } }