Skip to content

Commit

Permalink
Merge pull request #523 from ePaul/522-tolerate-nooptracer-writeto
Browse files Browse the repository at this point in the history
DefaultTracer#writeTo now tolerates NoopTracer
  • Loading branch information
zeitlinger authored Apr 13, 2021
2 parents bde4465 + 035b658 commit fcdd9aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public String currentId() {

@Override
public void writeTo(final BiConsumer<String, String> writer) {
writer.accept(Header.FLOW_ID, currentId());
extractor.extract(activeSpan())
.map(FlowId::getValue)
.ifPresent(value ->
writer.accept(Header.FLOW_ID, value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import io.opentracing.noop.NoopTracerFactory;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static java.util.Collections.emptyMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class DefaultFlowNoopTracerTest {
Expand All @@ -12,4 +17,11 @@ class DefaultFlowNoopTracerTest {
void shouldThrowNoActiveSpanFoundException() {
assertThrows(IllegalStateException.class, unit::currentId);
}

@Test
void writeToShouldNotThrow() {
final Map<String, String> target = new HashMap<>();
unit.writeTo(target::put);
assertEquals(emptyMap(), target);
}
}

0 comments on commit fcdd9aa

Please sign in to comment.