Non-ASCII characters included in X-SPAN-NAME header. (#735)

This commit is contained in:
Robert Hafner
2017-10-16 02:05:16 -04:00
committed by Marcin Grzejszczak
parent 7ce35e51dc
commit d7cebccf0c
2 changed files with 21 additions and 1 deletions

View File

@@ -66,7 +66,9 @@ abstract class AbstractTraceHttpRequestInterceptor {
}
private String getName(URI uri) {
return SpanNameUtil.shorten(uriScheme(uri) + ":" + uri.getPath());
// The returned name should comply with RFC 882 - Section 3.1.2.
// i.e Header values must composed of printable ASCII values.
return SpanNameUtil.shorten(uriScheme(uri) + ":" + uri.getRawPath());
}
private String uriScheme(URI uri) {

View File

@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -156,6 +157,23 @@ public class TraceRestTemplateInterceptorTests {
then(this.testController.span).hasNameEqualTo("http:/");
}
@Test
public void createdSpanNameHasOnlyPrintableAsciiCharactersForNonEncodedURIWithNonAsciiChars() {
this.tracer.continueSpan(Span.builder().traceId(1L).spanId(2L).exportable(false).build());
try {
this.template.getForEntity("/cas~fs~划", Map.class).getBody();
}
catch (Exception e) {
}
String spanName = this.spanAccumulator.getSpans().get(0).getName();
then(this.spanAccumulator.getSpans().get(0).getName()).isEqualTo("http:/cas~fs~%C3%A5%CB%86%E2%80%99");
then(StringUtils.isAsciiPrintable(spanName));
then(ExceptionUtils.getLastException()).isNull();
}
@Test
public void willShortenTheNameOfTheSpan() {
this.tracer.continueSpan(Span.builder().traceId(1L).spanId(2L).exportable(false).build());