zipkin2.reporter.BytesMessageEncoder Java Examples

The following examples show how to use zipkin2.reporter.BytesMessageEncoder. 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: HttpSender.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Override protected Request makeRequest(List<byte[]> spans) throws IOException {
  byte[] json = BytesMessageEncoder.JSON.encode(spans);
  Request request = Request.apply(POST, "/api/v2/spans");
  request.headerMap().add("Host", config.hostHeader());
  request.headerMap().add("Content-Type", "application/json");
  // Eventhough finagle compression flag exists, it only works for servers!
  if (config.compressionEnabled()) {
    request.headerMap().add("Content-Encoding", "gzip");
    ByteArrayOutputStream gzipped = new ByteArrayOutputStream();
    try (GZIPOutputStream compressor = new GZIPOutputStream(gzipped)) {
      compressor.write(json);
    }
    json = gzipped.toByteArray();
  }
  request.headerMap().add("Content-Length", String.valueOf(json.length));
  request.write(json);
  return request;
}
 
Example #2
Source File: URLConnectionSender.java    From zipkin-reporter-java with Apache License 2.0 6 votes vote down vote up
URLConnectionSender(Builder builder) {
  if (builder.endpoint == null) throw new NullPointerException("endpoint == null");
  this.endpoint = builder.endpoint;
  this.encoding = builder.encoding;
  switch (builder.encoding) {
    case JSON:
      this.mediaType = "application/json";
      this.encoder = BytesMessageEncoder.JSON;
      break;
    case THRIFT:
      this.mediaType = "application/x-thrift";
      this.encoder = BytesMessageEncoder.THRIFT;
      break;
    case PROTO3:
      this.mediaType = "application/x-protobuf";
      this.encoder = BytesMessageEncoder.PROTO3;
      break;
    default:
      throw new UnsupportedOperationException("Unsupported encoding: " + encoding.name());
  }
  this.messageMaxBytes = builder.messageMaxBytes;
  this.connectTimeout = builder.connectTimeout;
  this.readTimeout = builder.readTimeout;
  this.compressionEnabled = builder.compressionEnabled;
}
 
Example #3
Source File: RestTemplateSender.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
RestTemplateSender(RestTemplate restTemplate, String baseUrl,
		BytesEncoder<Span> encoder) {
	this.restTemplate = restTemplate;
	this.encoding = encoder.encoding();
	if (encoder.equals(JSON_V2)) {
		this.mediaType = MediaType.APPLICATION_JSON;
		this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v2/spans";
	}
	else if (this.encoding == Encoding.PROTO3) {
		this.mediaType = MediaType.parseMediaType("application/x-protobuf");
		this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v2/spans";
	}
	else if (this.encoding == Encoding.JSON) {
		this.mediaType = MediaType.APPLICATION_JSON;
		this.url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/v1/spans";
	}
	else {
		throw new UnsupportedOperationException(
				"Unsupported encoding: " + this.encoding.name());
	}
	this.messageEncoder = BytesMessageEncoder.forEncoding(this.encoding);
}
 
Example #4
Source File: ZipkinRestTemplateSender.java    From sofa-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public Call<Void> sendSpans(List<byte[]> encodedSpans) {
    try {
        byte[] message = BytesMessageEncoder.JSON.encode(encodedSpans);
        post(message);
    } catch (Throwable e) {
        SelfLog.error("Failed to report span to remote server. Current rest url is " + url, e);
    }
    return Call.create(null);
}
 
Example #5
Source File: FakeSender.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
static FakeSender create() {
  return new FakeSender(
      Encoding.THRIFT,
      Integer.MAX_VALUE,
      BytesMessageEncoder.forEncoding(Encoding.THRIFT),
      SpanBytesEncoder.THRIFT,
      SpanBytesDecoder.THRIFT,
      spans -> {
      }
  );
}
 
Example #6
Source File: FakeSender.java    From zipkin-finagle with Apache License 2.0 5 votes vote down vote up
FakeSender(
    Encoding encoding,
    int messageMaxBytes,
    BytesMessageEncoder messageEncoder,
    BytesEncoder<Span> encoder,
    BytesDecoder<Span> decoder,
    Consumer<List<Span>> onSpans
) {
  this.encoding = encoding;
  this.messageMaxBytes = messageMaxBytes;
  this.messageEncoder = messageEncoder;
  this.encoder = encoder;
  this.decoder = decoder;
  this.onSpans = onSpans;
}
 
Example #7
Source File: KinesisSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  ByteBuffer message = ByteBuffer.wrap(BytesMessageEncoder.forEncoding(encoding()).encode(list));

  PutRecordRequest request = new PutRecordRequest();
  request.setStreamName(streamName);
  request.setData(message);
  request.setPartitionKey(getPartitionKey());

  return new KinesisCall(request);
}
 
Example #8
Source File: AbstractSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  byte[] encodedSpans = BytesMessageEncoder.forEncoding(encoding()).encode(list);
  String body =
      encoding() == Encoding.JSON && isAscii(encodedSpans)
          ? new String(encodedSpans, StandardCharsets.UTF_8)
          : Base64.getEncoder().encodeToString(encodedSpans);

  return call(SendMessageRequest.builder().messageBody(body).queueUrl(queueUrl).build());
}
 
Example #9
Source File: SQSSender.java    From zipkin-aws with Apache License 2.0 5 votes vote down vote up
@Override
public Call<Void> sendSpans(List<byte[]> list) {
  if (closeCalled) throw new IllegalStateException("closed");

  byte[] encodedSpans = BytesMessageEncoder.forEncoding(encoding()).encode(list);
  String body =
      encoding() == Encoding.JSON && isAscii(encodedSpans)
          ? new String(encodedSpans, UTF_8)
          : Base64.encodeAsString(encodedSpans);

  return new SQSCall(new SendMessageRequest(queueUrl, body));
}
 
Example #10
Source File: RabbitMQSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
RabbitMQSender(Builder builder) {
  if (builder.addresses == null) throw new NullPointerException("addresses == null");
  encoding = builder.encoding;
  encoder = BytesMessageEncoder.forEncoding(encoding);
  messageMaxBytes = builder.messageMaxBytes;
  addresses = builder.addresses;
  queue = builder.queue;
  connectionFactory = builder.connectionFactory.clone();
}
 
Example #11
Source File: KafkaSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
KafkaSender(Builder builder) {
  properties = new Properties();
  properties.putAll(builder.properties);
  topic = builder.topic;
  encoding = builder.encoding;
  encoder = BytesMessageEncoder.forEncoding(builder.encoding);
  messageMaxBytes = builder.messageMaxBytes;
}
 
Example #12
Source File: KafkaSender.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
KafkaSender(Builder builder) {
  properties = new Properties();
  properties.putAll(builder.properties);
  topic = builder.topic;
  encoding = builder.encoding;
  encoder = BytesMessageEncoder.forEncoding(builder.encoding);
  messageMaxBytes = builder.messageMaxBytes;
}
 
Example #13
Source File: ActiveMQSender.java    From zipkin-reporter-java with Apache License 2.0 4 votes vote down vote up
ActiveMQSender(Builder builder) {
  this.encoding = builder.encoding;
  this.messageMaxBytes = builder.messageMaxBytes;
  this.encoder = BytesMessageEncoder.forEncoding(encoding);
  this.lazyInit = new LazyInit(builder);
}