Merge branch 'master' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2017-06-07 10:41:44 +02:00
2 changed files with 19 additions and 11 deletions

View File

@@ -365,7 +365,7 @@ public class Span implements SpanContext {
* @return this Span instance, for chaining
*/
public Span setBaggageItem(String key, String value) {
this.baggage.put(key, value);
this.baggage.put(key.toLowerCase(), value);
return this;
}
@@ -373,7 +373,7 @@ public class Span implements SpanContext {
* @return the value of the baggage item identified by the given key, or null if no such item could be found
*/
public String getBaggageItem(String key) {
return this.baggage.get(key);
return this.baggage.get(key.toLowerCase());
}
@Override
@@ -732,7 +732,7 @@ public class Span implements SpanContext {
}
public Span.SpanBuilder baggage(String baggageKey, String baggageValue) {
this.baggage.put(baggageKey, baggageValue);
this.baggage.put(baggageKey.toLowerCase(), baggageValue);
return this;
}

View File

@@ -16,17 +16,21 @@
package org.springframework.cloud.sleuth.trace;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.cloud.sleuth.*;
import org.springframework.cloud.sleuth.log.Slf4jSpanLogger;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import java.lang.invoke.MethodHandles;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
import org.springframework.cloud.sleuth.NoOpSpanReporter;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.cloud.sleuth.log.Slf4jSpanLogger;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
/**
@@ -39,13 +43,16 @@ public class CustomLoggerTests {
new DefaultSpanNamer(), this.spanLogger, new NoOpSpanReporter(), new TraceKeys());
// https://github.com/spring-cloud/spring-cloud-sleuth/issues/547
// https://github.com/spring-cloud/spring-cloud-sleuth/issues/605
@Test
public void should_pass_baggage_to_custom_span_logger() {
Span parent = Span.builder().spanId(1).traceId(2).baggage("foo", "bar").build();
Span parent = Span.builder().spanId(1).traceId(2).baggage("FOO", "bar").build();
parent.setBaggageItem("bAz", "baz");
Span child = this.tracer.createSpan("child", parent);
then(child).hasBaggageItem("foo", "bar");
then(child.getBaggageItem("FoO")).isEqualTo("bar");
then(this.spanLogger.called.get()).isTrue();
TestSpanContextHolder.removeCurrentSpan();
}
@@ -66,6 +73,7 @@ class CustomSpanLogger extends Slf4jSpanLogger {
called.set(true);
then(parent).hasBaggageItem("foo", "bar");
then(span).hasBaggageItem("foo", "bar");
then(span).hasBaggageItem("baz", "baz");
log.info("Baggage item foo=>bar found");
log.info("Parent's baggage: " + parent.getBaggage());
log.info("Child's baggage: " + span.getBaggage());