protected URLConnectionSender getSender(ZipkinPlugin zipkinPlugin) { return URLConnectionSender.create(zipkinPlugin.getZipkinEndpoint()); }
public static Builder builder() { return new AutoValue_URLConnectionSender.Builder() .encoding(Encoding.THRIFT) .connectTimeout(10 * 1000) .readTimeout(60 * 1000) .compressionEnabled(true) .messageMaxBytes(5 * 1024 * 1024); }
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); }
public final URLConnectionSender build() { if (encoding() == Encoding.JSON) { return mediaType("application/json").encoder(BytesMessageEncoder.JSON).autoBuild(); } else if (encoding() == Encoding.THRIFT) { return mediaType("application/x-thrift").encoder(BytesMessageEncoder.THRIFT).autoBuild(); } throw new UnsupportedOperationException("Unsupported encoding: " + encoding().name()); }
/** 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; } }
/** * No default. The POST URL for zipkin's <a href="http://zipkin.io/zipkin-api/#/">v2 api</a>, * usually "http://zipkinhost:9411/api/v2/spans" */ // customizable so that users can re-map /api/v2/spans ex for browser-originated traces public final Builder endpoint(String endpoint) { if (endpoint == null) throw new NullPointerException("endpoint == null"); try { return endpoint(new URL(endpoint)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } }
@Override public URLConnectionSender.Builder toBuilder() { return new Builder(this); }
@Override public final String toString() { return "URLConnectionSender(" + endpoint() + ")"; }
/** This utility is verbose as we have a minimum java version of 6 */ static void skipAllContent(HttpURLConnection connection) throws IOException { InputStream in = connection.getInputStream(); IOException thrown = skipAndSuppress(in); if (thrown == null) return; InputStream err = connection.getErrorStream(); if (err != null) skipAndSuppress(err); // null is possible, if the connection was dropped throw thrown; }
/** Sends an empty json message to the configured endpoint. */ @Override public CheckResult check() { try { send(new byte[] {'[', ']'}, "application/json"); return CheckResult.OK; } catch (Exception e) { return CheckResult.failed(e); } }
@Override public int messageSizeInBytes(List<byte[]> encodedSpans) { return encoding().listSizeInBytes(encodedSpans); }
throw new IllegalStateException("Missing required properties:" + missing); return new AutoValue_URLConnectionSender( this.encoding, this.messageMaxBytes,
@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; }
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(); }
.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();