protected URLConnectionSender getSender(ZipkinPlugin zipkinPlugin) { return URLConnectionSender.create(zipkinPlugin.getZipkinEndpoint()); }
private Builder(URLConnectionSender source) { this.encoding = source.encoding(); this.messageMaxBytes = source.messageMaxBytes(); this.encoder = source.encoder(); this.endpoint = source.endpoint(); this.connectTimeout = source.connectTimeout(); this.readTimeout = source.readTimeout(); this.compressionEnabled = source.compressionEnabled(); this.mediaType = source.mediaType(); } @Override
void send(byte[] body, String mediaType) throws IOException { // intentionally not closing the connection, so as to use keep-alives HttpURLConnection connection = (HttpURLConnection) endpoint().openConnection(); connection.setConnectTimeout(connectTimeout()); connection.setReadTimeout(readTimeout()); connection.setRequestMethod("POST"); connection.addRequestProperty("Content-Type", mediaType); if (compressionEnabled()) { connection.addRequestProperty("Content-Encoding", "gzip"); ByteArrayOutputStream gzipped = new ByteArrayOutputStream(); GZIPOutputStream compressor = new GZIPOutputStream(gzipped); try { compressor.write(body); } finally { compressor.close(); } body = gzipped.toByteArray(); } connection.setDoOutput(true); connection.setFixedLengthStreamingMode(body.length); connection.getOutputStream().write(body); skipAllContent(connection); }
/** Creates a sender that posts {@link Encoding#THRIFT} messages. */ public static URLConnectionSender create(String endpoint) { return builder().endpoint(endpoint).build(); }
/** Asynchronously sends the spans as a POST to {@link #endpoint()}. */ @Override public void sendSpans(List<byte[]> encodedSpans, Callback callback) { if (closeCalled) throw new IllegalStateException("close"); try { byte[] message = encoder().encode(encodedSpans); send(message, mediaType()); callback.onComplete(); } catch (Throwable e) { callback.onError(e); if (e instanceof Error) throw (Error) e; } }
@Override public final String toString() { return "URLConnectionSender(" + endpoint() + ")"; }
@Override public int messageSizeInBytes(List<byte[]> encodedSpans) { return encoding().listSizeInBytes(encodedSpans); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof URLConnectionSender) { URLConnectionSender that = (URLConnectionSender) o; return (this.encoding.equals(that.encoding())) && (this.messageMaxBytes == that.messageMaxBytes()) && (this.encoder.equals(that.encoder())) && (this.endpoint.equals(that.endpoint())) && (this.connectTimeout == that.connectTimeout()) && (this.readTimeout == that.readTimeout()) && (this.compressionEnabled == that.compressionEnabled()) && (this.mediaType.equals(that.mediaType())); } return false; }
/** Creates a sender that posts {@link Encoding#JSON} messages. */ public static URLConnectionSender json(String endpoint) { return builder().encoding(Encoding.JSON).endpoint(endpoint).build(); }
.traceSampler(Sampler.create( Float.valueOf(applicationProperties.getProperty("spring.sleuth.sampler.percentage", "1.0")))) .reporter(AsyncReporter.builder(URLConnectionSender.builder().endpoint( applicationProperties.getProperty("spring.zipkin.baseUrl", DEFAULT_ZIPKIN_HOSTNAME)).build()) .build()).build();
public Brave getBraveInstance() { Brave.Builder builder = new Brave.Builder(name.get()); if (this.url.isDefault()) { builder.reporter(new LoggingReporter()) .traceSampler(Sampler.create(1.0f)); } else { AsyncReporter<Span> asyncReporter = AsyncReporter.builder(URLConnectionSender.create(url.get())).build(); builder.reporter(asyncReporter) .traceSampler(Sampler.create(rate.get())); } return builder.build(); }
public static Brave brave(String serviceName) { return new Brave.Builder(serviceName) .traceSampler(Sampler.ALWAYS_SAMPLE) .reporter(AsyncReporter.builder(URLConnectionSender.builder() .endpoint("http://docker-machine.dev:8080/api/v1/spans") .build()).build()) .build(); } }