Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
add override flag
Browse files Browse the repository at this point in the history
  • Loading branch information
black-adder committed Jun 26, 2017
1 parent 146d803 commit 2e82315
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions jaeger-core/src/main/java/com/uber/jaeger/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ public List<LogData> getLogs() {
@Override
public Span setBaggageItem(String key, String value) {
synchronized (this) {
String prevItem = this.getBaggageItem(key);
this.context = this.context.withBaggageItem(key, value);
if (context.isSampled()) {
Map<String, String> fields = new HashMap<String, String>();
fields.put("event", "baggage");
fields.put("key", key);
fields.put("value", value);
if (prevItem != null) {
fields.put("override", "true");
}
return this.log(fields);
}
}
Expand Down
27 changes: 16 additions & 11 deletions jaeger-core/src/test/java/com/uber/jaeger/SpanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testSetAndGetBaggageItem() {
assertEquals(expected, span.getBaggageItem(key));

// Ensure the baggage was logged
this.assertBaggageLogs(span, key, expected);
this.assertBaggageLogs(span, key, expected, false);
}

@Test
Expand Down Expand Up @@ -295,14 +295,14 @@ public void testSpanDetectsSamplingPriorityLessThanZero() {
public void testBaggageOneReference() {
io.opentracing.Span parent = tracer.buildSpan("foo").startManual();
parent.setBaggageItem("foo", "bar");
this.assertBaggageLogs(parent, "foo", "bar");
this.assertBaggageLogs(parent, "foo", "bar", false);

io.opentracing.Span child = tracer.buildSpan("foo")
.asChildOf(parent)
.startManual();

child.setBaggageItem("a", "a");
this.assertBaggageLogs(child, "a", "a");
this.assertBaggageLogs(child, "a", "a", false);

assertNull(parent.getBaggageItem("a"));
assertEquals("a", child.getBaggageItem("a"));
Expand All @@ -313,24 +313,26 @@ public void testBaggageOneReference() {
public void testBaggageMultipleReferences() {
io.opentracing.Span parent1 = tracer.buildSpan("foo").startManual();
parent1.setBaggageItem("foo", "bar");
this.assertBaggageLogs(parent1, "foo", "bar");
this.assertBaggageLogs(parent1, "foo", "bar", false);
io.opentracing.Span parent2 = tracer.buildSpan("foo").startManual();
parent2.setBaggageItem("foo2", "bar");
this.assertBaggageLogs(parent2, "foo2", "bar");
this.assertBaggageLogs(parent2, "foo2", "bar", false);

io.opentracing.Span child = tracer.buildSpan("foo")
.asChildOf(parent1)
.addReference(References.FOLLOWS_FROM, parent2.context())
.startManual();

child.setBaggageItem("a", "a");
this.assertBaggageLogs(child, "a", "a");
this.assertBaggageLogs(child, "a", "a", false);
child.setBaggageItem("foo2", "b");
this.assertBaggageLogs(child, "foo2", "b", true);

assertNull(parent1.getBaggageItem("a"));
assertNull(parent2.getBaggageItem("a"));
assertEquals("a", child.getBaggageItem("a"));
assertEquals("bar", child.getBaggageItem("foo"));
assertEquals("bar", child.getBaggageItem("foo2"));
assertEquals("b", child.getBaggageItem("foo2"));
}

@Test
Expand All @@ -348,14 +350,17 @@ public void testImmutableBaggage() {
assertFalse(baggageIter.hasNext());
}

private void assertBaggageLogs(io.opentracing.Span span, String key, String value) {
private void assertBaggageLogs(io.opentracing.Span span, String key, String value, boolean override) {
Span sp = (Span)span;
List<LogData> logs = sp.getLogs();
assertEquals(1, logs.size());
Map<String, ?> fields = logs.get(0).getFields();
assertEquals(3, fields.size());
assertEquals(false, logs.isEmpty());
Map<String, ?> fields = logs.get(logs.size() - 1).getFields();
assertEquals(override ? 4 : 3, fields.size());
assertEquals("baggage", fields.get("event"));
assertEquals(key, fields.get("key"));
assertEquals(value, fields.get("value"));
if (override) {
assertEquals("true", fields.get("override"));
}
}
}

0 comments on commit 2e82315

Please sign in to comment.