Makes a nice toString on RestTemplateSender (#1686)
The AsyncZipkinSpanHandler calls 'check' once on startup to let someone know an error that may affect tracing up front. Before, this didn't include the endpoint so it is less obvious what could be the problem. Ex people goof the URL (don't add /api/v2/spans or it is added twice)
This commit is contained in:
@@ -129,6 +129,11 @@ final class RestTemplateSender extends Sender {
|
||||
this.restTemplate.exchange(requestEntity, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RestTemplateSender{" + url + "}";
|
||||
}
|
||||
|
||||
class HttpPostCall extends Call.Base<Void> {
|
||||
|
||||
private final byte[] message;
|
||||
|
||||
@@ -28,6 +28,8 @@ import zipkin2.Endpoint;
|
||||
import zipkin2.Span;
|
||||
import zipkin2.codec.Encoding;
|
||||
import zipkin2.codec.SpanBytesEncoder;
|
||||
import zipkin2.reporter.Sender;
|
||||
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
|
||||
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -49,9 +51,9 @@ public class RestTemplateSenderTest {
|
||||
@Rule
|
||||
public MockWebServer server = new MockWebServer();
|
||||
|
||||
String endpoint = this.server.url("/api/v2/spans").toString();
|
||||
String baseUrl = "http://localhost:" + this.server.getPort();
|
||||
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint,
|
||||
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.baseUrl,
|
||||
JSON_V2);
|
||||
|
||||
/**
|
||||
@@ -71,7 +73,7 @@ public class RestTemplateSenderTest {
|
||||
@Test
|
||||
public void proto3() throws Exception {
|
||||
this.server.enqueue(new MockResponse());
|
||||
this.sender = new RestTemplateSender(new RestTemplate(), this.endpoint, PROTO3);
|
||||
this.sender = new RestTemplateSender(new RestTemplate(), this.baseUrl, PROTO3);
|
||||
|
||||
send(SPAN).execute();
|
||||
|
||||
@@ -83,6 +85,19 @@ public class RestTemplateSenderTest {
|
||||
.containsExactly(SpanBytesEncoder.PROTO3.encode(SPAN));
|
||||
}
|
||||
|
||||
/**
|
||||
* The output of toString() on {@link Sender} implementations appears in thread names
|
||||
* created by {@link AsyncZipkinSpanHandler}. Since thread names are likely to be
|
||||
* exposed in logs and other monitoring tools, care should be taken to ensure the
|
||||
* toString() output is a reasonable length and does not contain sensitive
|
||||
* information.
|
||||
*/
|
||||
@Test
|
||||
public void toStringContainsOnlySenderTypeAndEndpoint() {
|
||||
assertThat(sender.toString())
|
||||
.isEqualTo("RestTemplateSender{" + baseUrl + "/api/v2/spans}");
|
||||
}
|
||||
|
||||
Call<Void> send(Span... spans) {
|
||||
SpanBytesEncoder bytesEncoder = this.sender.encoding() == Encoding.JSON
|
||||
? SpanBytesEncoder.JSON_V2 : SpanBytesEncoder.PROTO3;
|
||||
|
||||
Reference in New Issue
Block a user