I AM GROOT

This commit is contained in:
Anuraag Agrawal 2021-10-20 18:27:20 +09:00
parent 2079eec55a
commit c23ac3131e
67 changed files with 199 additions and 196 deletions

View File

@ -33,7 +33,7 @@ class NoopOpenTelemetryTest {
void contextNoOp() {
// Context.root() is not a no-op Context, so the default context is never root.
Context context = Context.current();
assertThat(context).isNotSameAs(Context.root());
assertThat(context).isNotSameAs(Context.groot());
// No allocations
assertThat(context.with(Span.wrap(SPAN_CONTEXT))).isSameAs(context);
assertThat(SPAN_CONTEXT.isValid()).isTrue();

View File

@ -74,7 +74,7 @@ public class W3CBaggagePropagatorBenchmark {
@Warmup(iterations = 5, time = 1)
public Context smallBaggage() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
return propagator.extract(Context.root(), SMALL_BAGGAGE, getter);
return propagator.extract(Context.groot(), SMALL_BAGGAGE, getter);
}
@Benchmark
@ -85,6 +85,6 @@ public class W3CBaggagePropagatorBenchmark {
@Warmup(iterations = 5, time = 1)
public Context largeBaggage() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
return propagator.extract(Context.root(), LARGE_BAGGAGE, getter);
return propagator.extract(Context.groot(), LARGE_BAGGAGE, getter);
}
}

View File

@ -73,7 +73,7 @@ public class W3CTraceContextPropagatorBenchmark {
public Context measureExtractCreateInject() {
Context result = null;
for (int i = 0; i < COUNT; i++) {
result = w3cTraceContextPropagator.extract(Context.root(), carriers.get(i), getter);
result = w3cTraceContextPropagator.extract(Context.groot(), carriers.get(i), getter);
SpanContext current = Span.fromContext(result).getSpanContext();
SpanContext clientSpanContext =
SpanContext.create(

View File

@ -67,7 +67,7 @@ public class W3CTraceContextPropagatorExtractBenchmark {
public Context measureExtract() {
Context result = null;
for (int i = 0; i < COUNT; i++) {
result = w3cTraceContextPropagator.extract(Context.root(), carriers.get(i), getter);
result = w3cTraceContextPropagator.extract(Context.groot(), carriers.get(i), getter);
}
return result;
}

View File

@ -68,7 +68,7 @@ public class W3CTraceContextPropagatorInjectBenchmark {
private static List<Context> createContexts(List<SpanContext> spanContexts) {
List<Context> contexts = new ArrayList<>();
for (SpanContext context : spanContexts) {
contexts.add(Context.root().with(Span.wrap(context)));
contexts.add(Context.groot().with(Span.wrap(context)));
}
return contexts;
}

View File

@ -71,7 +71,7 @@ public final class W3CBaggagePropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -147,7 +147,7 @@ public final class W3CTraceContextPropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -15,7 +15,7 @@ class BaggageContextTest {
@Test
void testGetCurrentBaggage_Default() {
try (Scope s = Context.root().makeCurrent()) {
try (Scope s = Context.groot().makeCurrent()) {
Baggage baggage = Baggage.current();
assertThat(baggage).isSameAs(Baggage.empty());
}
@ -24,34 +24,34 @@ class BaggageContextTest {
@Test
void testGetCurrentBaggage_SetCorrContext() {
Baggage baggage = Baggage.empty();
try (Scope ignored = Context.root().with(baggage).makeCurrent()) {
try (Scope ignored = Context.groot().with(baggage).makeCurrent()) {
assertThat(Baggage.current()).isSameAs(baggage);
}
}
@Test
void testGetBaggage_DefaultContext() {
Baggage baggage = Baggage.fromContext(Context.root());
Baggage baggage = Baggage.fromContext(Context.groot());
assertThat(baggage).isSameAs(Baggage.empty());
}
@Test
void testGetBaggage_ExplicitContext() {
Baggage baggage = Baggage.empty();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(Baggage.fromContext(context)).isSameAs(baggage);
}
@Test
void testGetBaggageWithoutDefault_DefaultContext() {
Baggage baggage = Baggage.fromContextOrNull(Context.root());
Baggage baggage = Baggage.fromContextOrNull(Context.groot());
assertThat(baggage).isNull();
}
@Test
void testGetBaggageWithoutDefault_ExplicitContext() {
Baggage baggage = Baggage.empty();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(Baggage.fromContextOrNull(context)).isSameAs(baggage);
}
}

View File

@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
class BaggageTest {
@Test
void current_empty() {
try (Scope scope = Context.root().makeCurrent()) {
try (Scope scope = Context.groot().makeCurrent()) {
assertThat(Baggage.current()).isEqualTo(Baggage.empty());
}
}
@ -22,7 +22,7 @@ class BaggageTest {
@Test
void current() {
try (Scope scope =
Context.root().with(Baggage.builder().put("foo", "bar").build()).makeCurrent()) {
Context.groot().with(Baggage.builder().put("foo", "bar").build()).makeCurrent()) {
Baggage result = Baggage.current();
assertThat(result.getEntryValue("foo")).isEqualTo("bar");
}

View File

@ -39,9 +39,9 @@ class W3CBaggagePropagatorFuzzTest {
.put("b", baggageValue, BaggageEntryMetadata.create(metadataBlob))
.build();
Map<String, String> carrier = new HashMap<>();
baggagePropagator.inject(Context.root().with(baggage), carrier, Map::put);
baggagePropagator.inject(Context.groot().with(baggage), carrier, Map::put);
Context extractedContext =
baggagePropagator.extract(Context.root(), carrier, new MapTextMapGetter());
baggagePropagator.extract(Context.groot(), carrier, new MapTextMapGetter());
Baggage extractedBaggage = Baggage.fromContext(extractedContext);
assertThat(extractedBaggage).isEqualTo(baggage);
}
@ -56,9 +56,9 @@ class W3CBaggagePropagatorFuzzTest {
.put("b", baggageValue, BaggageEntryMetadata.create(metadataBlob))
.build();
Map<String, String> carrier = new HashMap<>();
baggagePropagator.inject(Context.root().with(baggage), carrier, Map::put);
baggagePropagator.inject(Context.groot().with(baggage), carrier, Map::put);
Context extractedContext =
baggagePropagator.extract(Context.root(), carrier, new MapTextMapGetter());
baggagePropagator.extract(Context.groot(), carrier, new MapTextMapGetter());
Baggage extractedBaggage = Baggage.fromContext(extractedContext);
assertThat(extractedBaggage).isEqualTo(baggage);
}

View File

@ -47,7 +47,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key=value1,key=value2"), getter);
Context.groot(), ImmutableMap.of("baggage", "key=value1,key=value2"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value2").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -58,7 +58,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", " key=value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", " key=value1"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -69,7 +69,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key =value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key =value1"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -80,7 +80,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", " =value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", " =value1"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -90,7 +90,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "ke y=value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "ke y=value1"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -100,7 +100,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "ke?y=value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "ke?y=value1"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -111,7 +111,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(),
Context.groot(),
ImmutableMap.of(
"baggage",
"ke<y=value1, ;sss,key=value;meta1=value1;meta2=value2,ke(y=value;meta=val "),
@ -129,7 +129,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", " key= value1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", " key= value1"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -140,7 +140,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value%201"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key=value%201"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value 1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -151,7 +151,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value1 "), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key=value1 "), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -163,7 +163,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key=value1 ;meta1=meta2"), getter);
Context.groot(), ImmutableMap.of("baggage", "key=value1 ;meta1=meta2"), getter);
Baggage expectedBaggage =
Baggage.builder().put("key", "value1", BaggageEntryMetadata.create("meta1=meta2")).build();
@ -175,7 +175,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1="), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key1="), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -186,7 +186,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key1=;metakey=metaval"), getter);
Context.groot(), ImmutableMap.of("baggage", "key1=;metakey=metaval"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -196,7 +196,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1= "), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key1= "), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -206,7 +206,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=valu e1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key=valu e1"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -216,7 +216,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=val\\ue1"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key=val\\ue1"), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -227,7 +227,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key= value1,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key= value1,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -239,7 +239,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key=value1 ,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key=value1 ,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -251,7 +251,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key1=;metakey=metaval,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key1=;metakey=metaval,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -262,7 +262,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1=,key1=val"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key1=,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -274,7 +274,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key1= ,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key1= ,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -286,7 +286,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key=valu e1,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key=valu e1,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -298,7 +298,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key=val\\ue1,key1=val"), getter);
Context.groot(), ImmutableMap.of("baggage", "key=val\\ue1,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -308,15 +308,15 @@ class W3CBaggagePropagatorTest {
void extract_header_missing() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result = propagator.extract(Context.root(), ImmutableMap.of(), getter);
assertThat(result).isEqualTo(Context.root());
Context result = propagator.extract(Context.groot(), ImmutableMap.of(), getter);
assertThat(result).isEqualTo(Context.groot());
}
@Test
void extract_header_empty() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", ""), getter);
Context result = propagator.extract(Context.groot(), ImmutableMap.of("baggage", ""), getter);
assertThat(Baggage.fromContext(result)).isEqualTo(Baggage.empty());
}
@ -325,7 +325,7 @@ class W3CBaggagePropagatorTest {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result =
propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value"), getter);
propagator.extract(Context.groot(), ImmutableMap.of("baggage", "key=value"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -337,7 +337,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(), ImmutableMap.of("baggage", "key1=value1,key2=value2"), getter);
Context.groot(), ImmutableMap.of("baggage", "key1=value1,key2=value2"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "value1").put("key2", "value2").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
@ -349,7 +349,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(),
Context.groot(),
ImmutableMap.of("baggage", "key=value;metadata-key=value;othermetadata"),
getter);
@ -366,7 +366,7 @@ class W3CBaggagePropagatorTest {
Context result =
propagator.extract(
Context.root(),
Context.groot(),
ImmutableMap.of(
"baggage",
"key1= value1; metadata-key = value; othermetadata, "
@ -411,7 +411,7 @@ class W3CBaggagePropagatorTest {
@Test
void extract_nullContext() {
assertThat(W3CBaggagePropagator.getInstance().extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test
@ -425,7 +425,7 @@ class W3CBaggagePropagatorTest {
void inject_noBaggage() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Map<String, String> carrier = new HashMap<>();
propagator.inject(Context.root(), carrier, Map::put);
propagator.inject(Context.groot(), carrier, Map::put);
assertThat(carrier).isEmpty();
}
@ -434,7 +434,7 @@ class W3CBaggagePropagatorTest {
Baggage baggage = Baggage.empty();
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Map<String, String> carrier = new HashMap<>();
propagator.inject(Context.root().with(baggage), carrier, Map::put);
propagator.inject(Context.groot().with(baggage), carrier, Map::put);
assertThat(carrier).isEmpty();
}
@ -448,7 +448,7 @@ class W3CBaggagePropagatorTest {
.build();
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Map<String, String> carrier = new HashMap<>();
propagator.inject(Context.root().with(baggage), carrier, Map::put);
propagator.inject(Context.groot().with(baggage), carrier, Map::put);
assertThat(carrier)
.containsExactlyInAnyOrderEntriesOf(
singletonMap(

View File

@ -35,7 +35,7 @@ class DefaultTracerTest {
Span span =
defaultTracer
.spanBuilder(SPAN_NAME)
.setParent(Context.root().with(Span.wrap(spanContext)))
.setParent(Context.groot().with(Span.wrap(spanContext)))
.startSpan();
assertThat(span.getSpanContext()).isSameAs(spanContext);
}
@ -45,7 +45,7 @@ class DefaultTracerTest {
Span parent = Span.wrap(spanContext);
Span span =
defaultTracer.spanBuilder(SPAN_NAME).setParent(Context.root().with(parent)).startSpan();
defaultTracer.spanBuilder(SPAN_NAME).setParent(Context.groot().with(parent)).startSpan();
assertThat(span.getSpanContext()).isSameAs(spanContext);
}

View File

@ -42,8 +42,8 @@ class SpanBuilderTest {
spanBuilder.setAttribute(stringKey("foo"), null);
spanBuilder.setStartTimestamp(-1, TimeUnit.MILLISECONDS);
spanBuilder.setStartTimestamp(1, null);
spanBuilder.setParent(Context.root().with(Span.wrap(null)));
spanBuilder.setParent(Context.root());
spanBuilder.setParent(Context.groot().with(Span.wrap(null)));
spanBuilder.setParent(Context.groot());
spanBuilder.setNoParent();
spanBuilder.addLink(Span.getInvalid().getSpanContext());
spanBuilder.addLink(Span.getInvalid().getSpanContext(), Attributes.empty());

View File

@ -28,27 +28,27 @@ class SpanTest {
@Test
void testGetSpan_DefaultContext() {
Span span = Span.fromContext(Context.root());
Span span = Span.fromContext(Context.groot());
assertThat(span).isSameAs(Span.getInvalid());
}
@Test
void testGetSpan_ExplicitContext() {
Span span = Span.wrap(SpanContext.getInvalid());
Context context = Context.root().with(span);
Context context = Context.groot().with(span);
assertThat(Span.fromContext(context)).isSameAs(span);
}
@Test
void testGetSpanWithoutDefault_DefaultContext() {
Span span = Span.fromContextOrNull(Context.root());
Span span = Span.fromContextOrNull(Context.groot());
assertThat(span).isNull();
}
@Test
void testGetSpanWithoutDefault_ExplicitContext() {
Span span = Span.wrap(SpanContext.getInvalid());
Context context = Context.root().with(span);
Context context = Context.groot().with(span);
assertThat(Span.fromContextOrNull(context)).isSameAs(span);
}

View File

@ -27,7 +27,7 @@ public class W3CTraceContextPropagatorFuzzTest {
public void safeForRandomInputs(String traceParentHeader, String traceStateHeader) {
Context context =
w3cTraceContextPropagator.extract(
Context.root(),
Context.groot(),
ImmutableMap.of("traceparent", traceParentHeader, "tracestate", traceStateHeader),
new TextMapGetter<Map<String, String>>() {
@Override

View File

@ -514,7 +514,7 @@ class W3CTraceContextPropagatorTest {
@Test
void extract_nullContext() {
assertThat(w3cTraceContextPropagator.extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test
@ -538,7 +538,7 @@ class W3CTraceContextPropagatorTest {
invalidHeaders.put(W3CTraceContextPropagator.TRACE_PARENT, TRACEPARENT_HEADER_SAMPLED);
invalidHeaders.put(W3CTraceContextPropagator.TRACE_STATE, traceState);
Context context =
W3CTraceContextPropagator.getInstance().extract(Context.root(), invalidHeaders, getter);
W3CTraceContextPropagator.getInstance().extract(Context.groot(), invalidHeaders, getter);
assertThat(Span.fromContext(context).getSpanContext().getTraceState().get("bar")).isNull();
}
}

View File

@ -34,7 +34,7 @@ public class ContextBenchmark {
private int middle;
private List<ContextKey<String>> keys;
private Context context = Context.root();
private Context context = Context.groot();
@Setup
public void setup() {
@ -71,12 +71,12 @@ public class ContextBenchmark {
@Benchmark
public Context writeOne() {
return Context.root().with(keys.get(0), "value");
return Context.groot().with(keys.get(0), "value");
}
@Benchmark
public Context writeAll() {
Context context = Context.root();
Context context = Context.groot();
for (int i = 0; i < size; i++) {
context = context.with(keys.get(i), "value");
}

View File

@ -84,7 +84,7 @@ public interface Context {
/** Return the context associated with the current {@link Scope}. */
static Context current() {
Context current = ContextStorage.get().current();
return current != null ? current : root();
return current != null ? current : groot();
}
/**
@ -95,7 +95,7 @@ public interface Context {
* you are absolutely sure you need to disregard the current {@link Context} - this almost always
* is only a workaround hiding an underlying context propagation issue.
*/
static Context root() {
static Context groot() {
return ContextStorage.get().root();
}

View File

@ -56,7 +56,7 @@ final class MultiTextMapPropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -28,7 +28,7 @@ final class NoopTextMapPropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
return context;
}

View File

@ -110,7 +110,7 @@ public class BraveContextStorageProvider implements ContextStorageProvider {
return ((ContextWrapper) nextExtra).context;
}
}
return Context.root();
return Context.groot();
}
private static final class ContextWrapper {

View File

@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
class OtelInBraveTest {
private static final ContextKey<String> ANIMAL = ContextKey.named("animal");
private static final Context CONTEXT_WITH_ANIMAL = Context.root().with(ANIMAL, "japan");
private static final Context CONTEXT_WITH_ANIMAL = Context.groot().with(ANIMAL, "japan");
private static final Tracing TRACING =
Tracing.newBuilder().currentTraceContext(CurrentTraceContext.Default.create()).build();

View File

@ -56,7 +56,7 @@ class StrictContextStorageTest {
// strict storage.
@AfterEach
void resetContext() {
ThreadLocalContextStorage.INSTANCE.attach(Context.root());
ThreadLocalContextStorage.INSTANCE.attach(Context.groot());
}
// TODO(anuraaga): These rules conflict with error prone so one or the other needs to be

View File

@ -58,12 +58,12 @@ class ContextTest {
// Make sure all tests clean up
@AfterEach
void tearDown() {
assertThat(Context.current()).isEqualTo(Context.root());
assertThat(Context.current()).isEqualTo(Context.groot());
}
@Test
void startsWithRoot() {
assertThat(Context.current()).isEqualTo(Context.root());
assertThat(Context.current()).isEqualTo(Context.groot());
}
@Test
@ -73,7 +73,7 @@ class ContextTest {
try (Scope ignored = context.makeCurrent()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat");
try (Scope ignored2 = Context.root().makeCurrent()) {
try (Scope ignored2 = Context.groot().makeCurrent()) {
assertThat(Context.current().get(ANIMAL)).isNull();
}
@ -107,7 +107,7 @@ class ContextTest {
Thread thread = new Thread(() -> current.set(Context.current()));
thread.start();
thread.join();
assertThat(current.get()).isEqualTo(Context.root());
assertThat(current.get()).isEqualTo(Context.groot());
}
}
@ -489,20 +489,20 @@ class ContextTest {
@Test
void emptyContext() {
assertThat(Context.root().get(new HashCollidingKey())).isEqualTo(null);
assertThat(Context.groot().get(new HashCollidingKey())).isEqualTo(null);
}
@Test
void string() {
assertThat(Context.root()).hasToString("{}");
assertThat(Context.root().with(ANIMAL, "cat")).hasToString("{animal=cat}");
assertThat(Context.root().with(ANIMAL, "cat").with(BAG, 10))
assertThat(Context.groot()).hasToString("{}");
assertThat(Context.groot().with(ANIMAL, "cat")).hasToString("{animal=cat}");
assertThat(Context.groot().with(ANIMAL, "cat").with(BAG, 10))
.hasToString("{animal=cat, bag=10}");
}
@Test
void hashcodeCollidingKeys() {
Context context = Context.root();
Context context = Context.groot();
HashCollidingKey cheese = new HashCollidingKey();
HashCollidingKey wine = new HashCollidingKey();

View File

@ -142,7 +142,7 @@ class MultiTextMapPropagatorTest {
assertThat(
new MultiTextMapPropagator(propagator1, propagator2)
.extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test

View File

@ -38,7 +38,7 @@ class NoopTextMapPropagatorTest {
assertThat(
TextMapPropagator.noop()
.extract(null, Collections.emptyMap(), MapTextMapGetter.INSTANCE))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test

View File

@ -1,2 +1,5 @@
Comparing source compatibility of against
No changes.
***! MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.context.Context (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++! NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.context.Context groot()
---! REMOVED METHOD: PUBLIC(-) STATIC(-) io.opentelemetry.context.Context root()

View File

@ -160,7 +160,7 @@ public final class AwsXrayPropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -356,7 +356,7 @@ class AwsXrayPropagatorTest {
@Test
void extract_nullContext() {
assertThat(xrayPropagator.extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test

View File

@ -44,7 +44,7 @@ public class PassThroughPropagatorBenchmark {
static {
Map<String, String> incoming = new HashMap<>();
W3CTraceContextPropagator.getInstance()
.inject(Context.root().with(Span.wrap(SPAN_CONTEXT)), incoming, Map::put);
.inject(Context.groot().with(Span.wrap(SPAN_CONTEXT)), incoming, Map::put);
INCOMING = Collections.unmodifiableMap(incoming);
}
@ -67,14 +67,14 @@ public class PassThroughPropagatorBenchmark {
@Benchmark
public void passthrough() {
Context extracted = passthrough.extract(Context.root(), INCOMING, getter);
Context extracted = passthrough.extract(Context.groot(), INCOMING, getter);
passthrough.inject(extracted, new HashMap<>(), Map::put);
}
@Benchmark
public void parse() {
Context extracted =
W3CTraceContextPropagator.getInstance().extract(Context.root(), INCOMING, getter);
W3CTraceContextPropagator.getInstance().extract(Context.groot(), INCOMING, getter);
W3CTraceContextPropagator.getInstance().inject(extracted, new HashMap<>(), Map::put);
}
}

View File

@ -42,7 +42,7 @@ class PassThroughPropagatorTest {
incoming.put("food", "pizza");
incoming.put("country", "japan");
Context context = propagator.extract(Context.root(), incoming, getter);
Context context = propagator.extract(Context.groot(), incoming, getter);
Map<String, String> outgoing = new HashMap<>();
propagator.inject(context, outgoing, Map::put);
@ -57,7 +57,7 @@ class PassThroughPropagatorTest {
incoming.put("food", "pizza");
incoming.put("country", "japan");
Context context = propagator.extract(Context.root(), incoming, getter);
Context context = propagator.extract(Context.groot(), incoming, getter);
Map<String, String> outgoing = new HashMap<>();
propagator.inject(context, outgoing, Map::put);
@ -68,7 +68,7 @@ class PassThroughPropagatorTest {
void emptyMap() {
Map<String, String> incoming = new HashMap<>();
Context context = propagator.extract(Context.root(), incoming, getter);
Context context = propagator.extract(Context.groot(), incoming, getter);
Map<String, String> outgoing = new HashMap<>();
propagator.inject(context, outgoing, Map::put);

View File

@ -33,5 +33,5 @@ fun CoroutineContext.getOpenTelemetryContext(): Context {
if (element is KotlinContextElement) {
return element.context
}
return Context.root()
return Context.groot()
}

View File

@ -26,7 +26,7 @@ class KotlinCoroutinesTest {
@Test
fun runWithContext() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
runBlocking(Dispatchers.Default + context1.asContextElement()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat")
@ -68,7 +68,7 @@ class KotlinCoroutinesTest {
@Test
fun getOpenTelemetryContextOutsideOfContext() {
runBlocking(Dispatchers.Default) {
assertThat(Context.root()).isSameAs(coroutineContext.getOpenTelemetryContext())
assertThat(Context.groot()).isSameAs(coroutineContext.getOpenTelemetryContext())
}
}
@ -76,7 +76,7 @@ class KotlinCoroutinesTest {
@Test
@DelicateCoroutinesApi
fun stressTest() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
runBlocking(context1.asContextElement()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat")
for (i in 0 until 100) {

View File

@ -23,7 +23,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun noMakeCurrentSucceeds() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
runBlocking(Dispatchers.Default + context1.asContextElement()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat")
@ -32,7 +32,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun noMakeCurrentNestedContextSucceeds() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
runBlocking(Dispatchers.Default + context1.asContextElement()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat")
@ -50,7 +50,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun makeCurrentInTopLevelCoroutineFails() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
assertThatThrownBy {
runBlocking(Dispatchers.Default + context1.asContextElement()) {
@ -64,7 +64,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun makeCurrentInNestedCoroutineFails() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
assertThatThrownBy {
runBlocking(Dispatchers.Default + context1.asContextElement()) {
@ -81,7 +81,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun makeCurrentInSuspendingFunctionFails() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
assertThatThrownBy {
runBlocking(Dispatchers.Default + context1.asContextElement()) {
@ -93,7 +93,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun makeCurrentInSuspendingFunctionWithManualCloseFails() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
assertThatThrownBy {
runBlocking(Dispatchers.Default + context1.asContextElement()) {
@ -105,7 +105,7 @@ class StrictContextWithCoroutinesTest {
@Test
fun noMakeCurrentInSuspendingFunctionSucceeds() {
val context1 = Context.root().with(ANIMAL, "cat")
val context1 = Context.groot().with(ANIMAL, "cat")
assertThat(Context.current().get(ANIMAL)).isNull()
runBlocking(Dispatchers.Default + context1.asContextElement()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("cat")

View File

@ -22,7 +22,7 @@ final class B3PropagatorExtractorMultipleHeaders implements B3PropagatorExtracto
public <C> Optional<Context> extract(
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Optional.of(Context.root());
return Optional.of(Context.groot());
}
if (getter == null) {
return Optional.of(context);

View File

@ -23,7 +23,7 @@ final class B3PropagatorExtractorSingleHeader implements B3PropagatorExtractor {
public <C> Optional<Context> extract(
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Optional.of(Context.root());
return Optional.of(Context.groot());
}
if (getter == null) {
return Optional.of(context);

View File

@ -126,7 +126,7 @@ public final class JaegerPropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -85,7 +85,7 @@ public final class OtTracePropagator implements TextMapPropagator {
@Override
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
if (context == null) {
return Context.root();
return Context.groot();
}
if (getter == null) {
return context;

View File

@ -591,9 +591,9 @@ class B3PropagatorTest {
@Test
void extract_nullContext() {
assertThat(b3Propagator.extract(null, Collections.emptyMap(), getter)).isSameAs(Context.root());
assertThat(b3Propagator.extract(null, Collections.emptyMap(), getter)).isSameAs(Context.groot());
assertThat(b3PropagatorSingleHeader.extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test

View File

@ -164,7 +164,7 @@ class JaegerPropagatorTest {
.put("meta", "meta-value", BaggageEntryMetadata.create("somemetadata; someother=foo"))
.build();
Map<String, String> carrier = new LinkedHashMap<>();
jaegerPropagator.inject(Context.root().with(baggage), carrier, Map::put);
jaegerPropagator.inject(Context.groot().with(baggage), carrier, Map::put);
assertThat(carrier)
.containsExactlyInAnyOrderEntriesOf(
ImmutableMap.of(
@ -448,7 +448,7 @@ class JaegerPropagatorTest {
@Test
void extract_nullContext() {
assertThat(jaegerPropagator.extract(null, Collections.emptyMap(), getter))
.isSameAs(Context.root());
.isSameAs(Context.groot());
}
@Test

View File

@ -329,7 +329,7 @@ class OtTracePropagatorTest {
@Test
void extract_nullContext() {
assertThat(propagator.extract(null, Collections.emptyMap(), getter)).isSameAs(Context.root());
assertThat(propagator.extract(null, Collections.emptyMap(), getter)).isSameAs(Context.groot());
}
@Test

View File

@ -215,7 +215,7 @@ class B3PropagationIntegrationTest {
return sdk.getPropagators()
.getTextMapPropagator()
.extract(
Context.root(),
Context.groot(),
request,
new TextMapGetter<HttpRequest>() {
@Override

View File

@ -192,12 +192,12 @@ final class SpanBuilderShim extends BaseShimObject implements SpanBuilder {
if (ignoreActiveSpan && parentSpan == null && parentSpanContext == null) {
builder.setNoParent();
} else if (parentSpan != null) {
builder.setParent(Context.root().with(parentSpan.getSpan()));
builder.setParent(Context.groot().with(parentSpan.getSpan()));
SpanContextShim contextShim = spanContextTable().get(parentSpan);
baggage = contextShim == null ? null : contextShim.getBaggage();
} else if (parentSpanContext != null) {
builder.setParent(
Context.root()
Context.groot()
.with(io.opentelemetry.api.trace.Span.wrap(parentSpanContext.getSpanContext())));
baggage = parentSpanContext.getBaggage();
}

View File

@ -26,7 +26,7 @@ class RateLimitingSamplerTest {
private static final String TRACE_ID = "12345678876543211234567887654321";
private static final String PARENT_SPAN_ID = "8765432112345678";
private static final Context spanContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.create(

View File

@ -57,7 +57,7 @@ class TracezSpanProcessorTest {
TracezSpanProcessor spanProcessor = TracezSpanProcessor.builder().build();
/* Return a sampled span, which should be added to the running cache by default */
when(readWriteSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT);
spanProcessor.onStart(Context.root(), readWriteSpan);
spanProcessor.onStart(Context.groot(), readWriteSpan);
assertSpanCacheSizes(spanProcessor, 1, 0);
}
@ -67,7 +67,7 @@ class TracezSpanProcessorTest {
/* Return a sampled span, which should be added to the completed cache upon ending */
when(readWriteSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT);
when(readWriteSpan.getName()).thenReturn(SPAN_NAME);
spanProcessor.onStart(Context.root(), readWriteSpan);
spanProcessor.onStart(Context.groot(), readWriteSpan);
when(readableSpan.getSpanContext()).thenReturn(SAMPLED_SPAN_CONTEXT);
when(readableSpan.getName()).thenReturn(SPAN_NAME);
@ -82,7 +82,7 @@ class TracezSpanProcessorTest {
TracezSpanProcessor spanProcessor = TracezSpanProcessor.builder().build();
/* Return a non-sampled span, which should not be added to the running cache by default */
when(readWriteSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT);
spanProcessor.onStart(Context.root(), readWriteSpan);
spanProcessor.onStart(Context.groot(), readWriteSpan);
assertSpanCacheSizes(spanProcessor, 1, 0);
}
@ -92,7 +92,7 @@ class TracezSpanProcessorTest {
/* Return a non-sampled span, which should not be added to the running cache by default */
when(readWriteSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT);
when(readableSpan.getSpanContext()).thenReturn(NOT_SAMPLED_SPAN_CONTEXT);
spanProcessor.onStart(Context.root(), readWriteSpan);
spanProcessor.onStart(Context.groot(), readWriteSpan);
spanProcessor.onEnd(readableSpan);
assertSpanCacheSizes(spanProcessor, 0, 0);
}

View File

@ -601,7 +601,7 @@ class SdkMeterProviderTest {
.build();
Meter meter = provider.get(SdkMeterProviderTest.class.getName());
Baggage baggage = Baggage.builder().put("baggage", "value").build();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
LongCounter counter = meter.counterBuilder("test").build();
// Make sure whether or not we explicitly pass baggage, all values have it appended.

View File

@ -23,7 +23,7 @@ class ExemplarFilterTest {
void never_NeverReturnsTrue() {
assertThat(
ExemplarFilter.neverSample()
.shouldSampleMeasurement(1, Attributes.empty(), Context.root()))
.shouldSampleMeasurement(1, Attributes.empty(), Context.groot()))
.isFalse();
}
@ -31,7 +31,7 @@ class ExemplarFilterTest {
void always_AlwaysReturnsTrue() {
assertThat(
ExemplarFilter.alwaysSample()
.shouldSampleMeasurement(1, Attributes.empty(), Context.root()))
.shouldSampleMeasurement(1, Attributes.empty(), Context.groot()))
.isTrue();
}
@ -39,14 +39,14 @@ class ExemplarFilterTest {
void withSampledTrace_ReturnsFalseOnNoContext() {
assertThat(
ExemplarFilter.sampleWithTraces()
.shouldSampleMeasurement(1, Attributes.empty(), Context.root()))
.shouldSampleMeasurement(1, Attributes.empty(), Context.groot()))
.isFalse();
}
@Test
void withSampledTrace_sampleWithTrace() {
final Context context =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.createFromRemoteParent(
@ -60,7 +60,7 @@ class ExemplarFilterTest {
@Test
void withSampledTrace_notSampleUnsampledTrace() {
final Context context =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.createFromRemoteParent(

View File

@ -29,30 +29,30 @@ class FilteredExemplarReservoirTest {
void testFilter_preventsSamplingDoubles() {
when(filter.shouldSampleMeasurement(anyDouble(), any(), any())).thenReturn(false);
ExemplarReservoir filtered = new FilteredExemplarReservoir(filter, reservoir);
filtered.offerMeasurement(1.0, Attributes.empty(), Context.root());
filtered.offerMeasurement(1.0, Attributes.empty(), Context.groot());
}
@Test
void testFilter_allowsSamplingDoubles() {
when(filter.shouldSampleMeasurement(anyDouble(), any(), any())).thenReturn(true);
ExemplarReservoir filtered = new FilteredExemplarReservoir(filter, reservoir);
filtered.offerMeasurement(1.0, Attributes.empty(), Context.root());
verify(reservoir).offerMeasurement(1.0, Attributes.empty(), Context.root());
filtered.offerMeasurement(1.0, Attributes.empty(), Context.groot());
verify(reservoir).offerMeasurement(1.0, Attributes.empty(), Context.groot());
}
@Test
void testFilter_preventsSamplingLongs() {
when(filter.shouldSampleMeasurement(anyLong(), any(), any())).thenReturn(false);
ExemplarReservoir filtered = new FilteredExemplarReservoir(filter, reservoir);
filtered.offerMeasurement(1L, Attributes.empty(), Context.root());
filtered.offerMeasurement(1L, Attributes.empty(), Context.groot());
}
@Test
void testFilter_allowsSamplingLongs() {
when(filter.shouldSampleMeasurement(anyLong(), any(), any())).thenReturn(true);
ExemplarReservoir filtered = new FilteredExemplarReservoir(filter, reservoir);
filtered.offerMeasurement(1L, Attributes.empty(), Context.root());
verify(reservoir).offerMeasurement(1L, Attributes.empty(), Context.root());
filtered.offerMeasurement(1L, Attributes.empty(), Context.groot());
verify(reservoir).offerMeasurement(1L, Attributes.empty(), Context.groot());
}
@Test

View File

@ -38,7 +38,7 @@ class FixedSizeExemplarReservoirTest {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir =
new FixedSizeExemplarReservoir(clock, 1, RandomSupplier.platformDefault());
reservoir.offerMeasurement(1L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(1L, Attributes.empty(), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
@ -50,7 +50,7 @@ class FixedSizeExemplarReservoirTest {
// Measurement count is reset, we should sample a new measurement (and only one)
clock.advance(Duration.ofSeconds(1));
reservoir.offerMeasurement(2L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(2L, Attributes.empty(), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
@ -70,7 +70,7 @@ class FixedSizeExemplarReservoirTest {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir =
new FixedSizeExemplarReservoir(clock, 1, RandomSupplier.platformDefault());
reservoir.offerMeasurement(1L, all, Context.root());
reservoir.offerMeasurement(1L, all, Context.groot());
assertThat(reservoir.collectAndReset(partial))
.satisfiesExactly(
exemplar ->
@ -85,7 +85,7 @@ class FixedSizeExemplarReservoirTest {
Attributes all =
Attributes.builder().put("one", 1).put("two", "two").put("three", true).build();
final Context context =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.createFromRemoteParent(
@ -124,9 +124,9 @@ class FixedSizeExemplarReservoirTest {
};
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new FixedSizeExemplarReservoir(clock, 2, () -> mockRandom);
reservoir.offerMeasurement(1, Attributes.of(key, 1L), Context.root());
reservoir.offerMeasurement(2, Attributes.of(key, 2L), Context.root());
reservoir.offerMeasurement(3, Attributes.of(key, 3L), Context.root());
reservoir.offerMeasurement(1, Attributes.of(key, 1L), Context.groot());
reservoir.offerMeasurement(2, Attributes.of(key, 2L), Context.groot());
reservoir.offerMeasurement(3, Attributes.of(key, 3L), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.satisfiesExactlyInAnyOrder(
exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasValue(2),

View File

@ -27,7 +27,7 @@ class HistogramBucketExemplarReservoirTest {
public void oneBucket_samplesEverything() {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new HistogramBucketExemplarReservoir(clock, new double[] {});
reservoir.offerMeasurement(1L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(1L, Attributes.empty(), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
@ -38,7 +38,7 @@ class HistogramBucketExemplarReservoirTest {
.hasValue(1));
// Measurement count is reset, we should sample a new measurement (and only one)
clock.advance(Duration.ofSeconds(1));
reservoir.offerMeasurement(2L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(2L, Attributes.empty(), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
@ -49,8 +49,8 @@ class HistogramBucketExemplarReservoirTest {
.hasValue(2));
// only latest measurement is kept per-bucket
clock.advance(Duration.ofSeconds(1));
reservoir.offerMeasurement(3L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(4L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(3L, Attributes.empty(), Context.groot());
reservoir.offerMeasurement(4L, Attributes.empty(), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(1)
.satisfiesExactly(
@ -67,10 +67,10 @@ class HistogramBucketExemplarReservoirTest {
AttributeKey<Long> bucketKey = AttributeKey.longKey("bucket");
ExemplarReservoir reservoir =
new HistogramBucketExemplarReservoir(clock, new double[] {0, 10, 20});
reservoir.offerMeasurement(-1, Attributes.of(bucketKey, 0L), Context.root());
reservoir.offerMeasurement(1, Attributes.of(bucketKey, 1L), Context.root());
reservoir.offerMeasurement(11, Attributes.of(bucketKey, 2L), Context.root());
reservoir.offerMeasurement(21, Attributes.of(bucketKey, 3L), Context.root());
reservoir.offerMeasurement(-1, Attributes.of(bucketKey, 0L), Context.groot());
reservoir.offerMeasurement(1, Attributes.of(bucketKey, 1L), Context.groot());
reservoir.offerMeasurement(11, Attributes.of(bucketKey, 2L), Context.groot());
reservoir.offerMeasurement(21, Attributes.of(bucketKey, 3L), Context.groot());
assertThat(reservoir.collectAndReset(Attributes.empty()))
.hasSize(4)
.satisfiesExactlyInAnyOrder(

View File

@ -109,7 +109,7 @@ public class AggregatorHandleTest {
void testOfferMeasurementLongToExemplar() {
TestAggregatorHandle testAggregator = new TestAggregatorHandle(reservoir);
Attributes attributes = Attributes.builder().put("test", "value").build();
Context context = Context.root();
Context context = Context.groot();
testAggregator.recordLong(1L, attributes, context);
Mockito.verify(reservoir).offerMeasurement(1L, attributes, context);
}
@ -118,7 +118,7 @@ public class AggregatorHandleTest {
void testOfferMeasurementDoubleToExemplar() {
TestAggregatorHandle testAggregator = new TestAggregatorHandle(reservoir);
Attributes attributes = Attributes.builder().put("test", "value").build();
Context context = Context.root();
Context context = Context.groot();
testAggregator.recordDouble(1.0d, attributes, context);
Mockito.verify(reservoir).offerMeasurement(1.0d, attributes, context);
}
@ -129,7 +129,7 @@ public class AggregatorHandleTest {
Attributes attributes = Attributes.builder().put("test", "value").build();
ExemplarData result = DoubleExemplarData.create(attributes, 2L, "spanid", "traceid", 1);
// We need to first record a value so that collect and reset does something.
testAggregator.recordDouble(1.0, Attributes.empty(), Context.root());
testAggregator.recordDouble(1.0, Attributes.empty(), Context.groot());
Mockito.when(reservoir.collectAndReset(attributes))
.thenReturn(Collections.singletonList(result));
testAggregator.accumulateThenReset(attributes);

View File

@ -78,7 +78,7 @@ public class DoubleHistogramAggregatorTest {
/* stateful= */ false,
() -> reservoir);
AggregatorHandle<HistogramAccumulation> aggregatorHandle = aggregator.createHandle();
aggregatorHandle.recordDouble(0, attributes, Context.root());
aggregatorHandle.recordDouble(0, attributes, Context.groot());
assertThat(aggregatorHandle.accumulateThenReset(Attributes.empty()))
.isEqualTo(HistogramAccumulation.create(0, new long[] {1, 0, 0, 0}, exemplars));
}

View File

@ -114,7 +114,7 @@ class DoubleSumAggregatorTest {
AggregationTemporality.CUMULATIVE,
() -> reservoir);
AggregatorHandle<DoubleAccumulation> aggregatorHandle = aggregator.createHandle();
aggregatorHandle.recordDouble(0, attributes, Context.root());
aggregatorHandle.recordDouble(0, attributes, Context.groot());
assertThat(aggregatorHandle.accumulateThenReset(Attributes.empty()))
.isEqualTo(DoubleAccumulation.create(0, exemplars));
}

View File

@ -117,7 +117,7 @@ class LongSumAggregatorTest {
AggregationTemporality.CUMULATIVE,
() -> reservoir);
AggregatorHandle<LongAccumulation> aggregatorHandle = aggregator.createHandle();
aggregatorHandle.recordLong(0, attributes, Context.root());
aggregatorHandle.recordLong(0, attributes, Context.groot());
assertThat(aggregatorHandle.accumulateThenReset(Attributes.empty()))
.isEqualTo(LongAccumulation.create(0, exemplars));
}

View File

@ -61,13 +61,13 @@ class DeltaMetricStorageTest {
@Test
void collectionDeltaForMultiReader() {
BoundStorageHandle bound = storage.bind(Attributes.empty());
bound.recordDouble(1, Attributes.empty(), Context.root());
bound.recordDouble(1, Attributes.empty(), Context.groot());
// First collector only sees first recording.
assertThat(storage.collectFor(collector1, allCollectors, /* suppressCollection=*/ false))
.hasSize(1)
.hasEntrySatisfying(Attributes.empty(), value -> assertThat(value.getValue()).isEqualTo(1));
bound.recordDouble(2, Attributes.empty(), Context.root());
bound.recordDouble(2, Attributes.empty(), Context.groot());
// First collector only sees second recording.
assertThat(storage.collectFor(collector1, allCollectors, /* suppressCollection=*/ false))
.hasSize(1)
@ -90,13 +90,13 @@ class DeltaMetricStorageTest {
@Test
void avoidCollectionInRapidSuccession() {
BoundStorageHandle bound = storage.bind(Attributes.empty());
bound.recordDouble(1, Attributes.empty(), Context.root());
bound.recordDouble(1, Attributes.empty(), Context.groot());
// First collector only sees first recording.
assertThat(storage.collectFor(collector1, allCollectors, /* suppressCollection=*/ false))
.hasSize(1)
.hasEntrySatisfying(Attributes.empty(), value -> assertThat(value.getValue()).isEqualTo(1));
// Add some data immediately after read, but pretent it hasn't been long.
bound.recordDouble(2, Attributes.empty(), Context.root());
bound.recordDouble(2, Attributes.empty(), Context.groot());
// Collector1 doesn't see new data, because we don't recollect, but collector2 sees old delta.
assertThat(storage.collectFor(collector1, allCollectors, /* suppressCollection=*/ true))
.isEmpty();

View File

@ -74,7 +74,7 @@ public class SynchronousMetricStorageTest {
SynchronousMetricStorage accumulator =
new DefaultSynchronousMetricStorage<>(METRIC_DESCRIPTOR, aggregator, spyLabelsProcessor);
BoundStorageHandle handle = accumulator.bind(labels);
handle.recordDouble(1, labels, Context.root());
handle.recordDouble(1, labels, Context.groot());
MetricData md =
accumulator.collectAndReset(collector, allCollectors, 0, testClock.now(), false);
assertThat(md)

View File

@ -22,7 +22,7 @@ public class AttributesProcessorTest {
assertThat(
processor.process(
Attributes.builder().put("remove", "me").put("test", "keep").build(),
Context.root()))
Context.groot()))
.hasSize(1)
.containsEntry("test", "keep");
}
@ -31,7 +31,7 @@ public class AttributesProcessorTest {
public void append_works() {
AttributesProcessor processor =
AttributesProcessor.append(Attributes.builder().put("append", "me").build());
assertThat(processor.process(Attributes.empty(), Context.root()))
assertThat(processor.process(Attributes.empty(), Context.groot()))
.hasSize(1)
.containsEntry("append", "me");
}
@ -40,7 +40,7 @@ public class AttributesProcessorTest {
public void append_doesNotOverrideExistingKeys() {
AttributesProcessor processor =
AttributesProcessor.append(Attributes.builder().put("test", "drop").build());
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), Context.root()))
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), Context.groot()))
.hasSize(1)
.containsEntry("test", "keep");
}
@ -49,7 +49,7 @@ public class AttributesProcessorTest {
public void appendBaggage_works() {
AttributesProcessor processor = AttributesProcessor.appendBaggageByKeyName(ignored -> true);
Baggage baggage = Baggage.builder().put("baggage", "value").build();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), context))
.hasSize(2)
@ -61,7 +61,7 @@ public class AttributesProcessorTest {
public void appendBaggage_doesNotOverrideExistingKeys() {
AttributesProcessor processor = AttributesProcessor.appendBaggageByKeyName(ignored -> true);
Baggage baggage = Baggage.builder().put("test", "drop").build();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), context))
.hasSize(1)
@ -73,7 +73,7 @@ public class AttributesProcessorTest {
AttributesProcessor processor =
AttributesProcessor.appendBaggageByKeyName(name -> "keep".equals(name));
Baggage baggage = Baggage.builder().put("baggage", "value").put("keep", "baggage").build();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), context))
.hasSize(2)
@ -88,7 +88,7 @@ public class AttributesProcessorTest {
AttributesProcessor.appendBaggageByKeyName(ignored -> true)
.then(AttributesProcessor.filterByKeyName(name -> "baggage".equals(name)));
Baggage baggage = Baggage.builder().put("baggage", "value").put("keep", "baggage").build();
Context context = Context.root().with(baggage);
Context context = Context.groot().with(baggage);
assertThat(processor.process(Attributes.builder().put("test", "keep").build(), context))
.containsEntry("baggage", "value")

View File

@ -67,7 +67,7 @@ final class SdkSpanBuilder implements SpanBuilder {
@Override
public SpanBuilder setNoParent() {
this.parent = Context.root();
this.parent = Context.groot();
return this;
}

View File

@ -47,7 +47,7 @@ class MultiSpanProcessorTest {
@Test
void empty() {
SpanProcessor multiSpanProcessor = SpanProcessor.composite(Collections.emptyList());
multiSpanProcessor.onStart(Context.root(), readWriteSpan);
multiSpanProcessor.onStart(Context.groot(), readWriteSpan);
multiSpanProcessor.onEnd(readableSpan);
multiSpanProcessor.shutdown();
}
@ -63,9 +63,9 @@ class MultiSpanProcessorTest {
void twoSpanProcessor() {
SpanProcessor multiSpanProcessor =
SpanProcessor.composite(Arrays.asList(spanProcessor1, spanProcessor2));
multiSpanProcessor.onStart(Context.root(), readWriteSpan);
verify(spanProcessor1).onStart(same(Context.root()), same(readWriteSpan));
verify(spanProcessor2).onStart(same(Context.root()), same(readWriteSpan));
multiSpanProcessor.onStart(Context.groot(), readWriteSpan);
verify(spanProcessor1).onStart(same(Context.groot()), same(readWriteSpan));
verify(spanProcessor2).onStart(same(Context.groot()), same(readWriteSpan));
multiSpanProcessor.onEnd(readableSpan);
verify(spanProcessor1).onEnd(same(readableSpan));
@ -90,8 +90,8 @@ class MultiSpanProcessorTest {
assertThat(multiSpanProcessor.isStartRequired()).isTrue();
assertThat(multiSpanProcessor.isEndRequired()).isTrue();
multiSpanProcessor.onStart(Context.root(), readWriteSpan);
verify(spanProcessor1).onStart(same(Context.root()), same(readWriteSpan));
multiSpanProcessor.onStart(Context.groot(), readWriteSpan);
verify(spanProcessor1).onStart(same(Context.groot()), same(readWriteSpan));
verify(spanProcessor2, times(0)).onStart(any(Context.class), any(ReadWriteSpan.class));
multiSpanProcessor.onEnd(readableSpan);

View File

@ -21,7 +21,7 @@ class NoopSpanProcessorTest {
@Test
void noCrash() {
SpanProcessor noopSpanProcessor = NoopSpanProcessor.getInstance();
noopSpanProcessor.onStart(Context.root(), readWriteSpan);
noopSpanProcessor.onStart(Context.groot(), readWriteSpan);
assertThat(noopSpanProcessor.isStartRequired()).isFalse();
noopSpanProcessor.onEnd(readableSpan);
assertThat(noopSpanProcessor.isEndRequired()).isFalse();

View File

@ -1043,7 +1043,7 @@ class RecordEventsReadableSpanTest {
SpanContext.create(
traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault()))
: Span.getInvalid(),
Context.root(),
Context.groot(),
config,
spanProcessor,
testClock,
@ -1052,7 +1052,7 @@ class RecordEventsReadableSpanTest {
links,
1,
0);
Mockito.verify(spanProcessor, Mockito.times(1)).onStart(Context.root(), span);
Mockito.verify(spanProcessor, Mockito.times(1)).onStart(Context.groot(), span);
return span;
}
@ -1132,7 +1132,7 @@ class RecordEventsReadableSpanTest {
SpanContext.create(
traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault()))
: Span.getInvalid(),
Context.root(),
Context.groot(),
spanLimits,
spanProcessor,
clock,

View File

@ -728,7 +728,7 @@ class SdkSpanBuilderTest {
assertThat(span.getSpanContext().getTraceId())
.isNotEqualTo(parent.getSpanContext().getTraceId());
Mockito.verify(mockedSpanProcessor)
.onStart(Mockito.same(Context.root()), Mockito.same((ReadWriteSpan) span));
.onStart(Mockito.same(Context.groot()), Mockito.same((ReadWriteSpan) span));
Span spanNoParent =
sdkTracer
.spanBuilder(SPAN_NAME)
@ -740,7 +740,7 @@ class SdkSpanBuilderTest {
assertThat(span.getSpanContext().getTraceId())
.isNotEqualTo(parent.getSpanContext().getTraceId());
Mockito.verify(mockedSpanProcessor)
.onStart(Mockito.same(Context.root()), Mockito.same((ReadWriteSpan) spanNoParent));
.onStart(Mockito.same(Context.groot()), Mockito.same((ReadWriteSpan) spanNoParent));
} finally {
spanNoParent.end();
}
@ -1040,8 +1040,8 @@ class SdkSpanBuilderTest {
spanBuilder.setAttribute(stringKey("foo"), null);
spanBuilder.setStartTimestamp(-1, TimeUnit.MILLISECONDS);
spanBuilder.setStartTimestamp(1, null);
spanBuilder.setParent(Context.root().with(Span.wrap(null)));
spanBuilder.setParent(Context.root());
spanBuilder.setParent(Context.groot().with(Span.wrap(null)));
spanBuilder.setParent(Context.groot());
spanBuilder.setNoParent();
spanBuilder.addLink(Span.getInvalid().getSpanContext());
spanBuilder.addLink(Span.getInvalid().getSpanContext(), Attributes.empty());

View File

@ -77,7 +77,7 @@ class SimpleSpanProcessorTest {
@Test
void onStartSync() {
simpleSampledSpansProcessor.onStart(Context.root(), readWriteSpan);
simpleSampledSpansProcessor.onStart(Context.groot(), readWriteSpan);
verifyNoInteractions(spanExporter);
}

View File

@ -27,9 +27,9 @@ class AlwaysOffSamplerTest {
private final String parentSpanId = idsGenerator.generateSpanId();
private final SpanContext sampledSpanContext =
SpanContext.create(traceId, parentSpanId, TraceFlags.getSampled(), TraceState.getDefault());
private final Context sampledParentContext = Context.root().with(Span.wrap(sampledSpanContext));
private final Context sampledParentContext = Context.groot().with(Span.wrap(sampledSpanContext));
private final Context notSampledParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.create(

View File

@ -27,9 +27,9 @@ class AlwaysOnSamplerTest {
private final String parentSpanId = idsGenerator.generateSpanId();
private final SpanContext sampledSpanContext =
SpanContext.create(traceId, parentSpanId, TraceFlags.getSampled(), TraceState.getDefault());
private final Context sampledParentContext = Context.root().with(Span.wrap(sampledSpanContext));
private final Context sampledParentContext = Context.groot().with(Span.wrap(sampledSpanContext));
private final Context notSampledParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.create(

View File

@ -27,22 +27,22 @@ class ParentBasedSamplerTest {
private final String parentSpanId = idsGenerator.generateSpanId();
private final SpanContext sampledSpanContext =
SpanContext.create(traceId, parentSpanId, TraceFlags.getSampled(), TraceState.getDefault());
private final Context sampledParentContext = Context.root().with(Span.wrap(sampledSpanContext));
private final Context sampledParentContext = Context.groot().with(Span.wrap(sampledSpanContext));
private final Context notSampledParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.create(
traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault())));
private final Context invalidParentContext = Context.root().with(Span.getInvalid());
private final Context invalidParentContext = Context.groot().with(Span.getInvalid());
private final Context sampledRemoteParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.createFromRemoteParent(
traceId, parentSpanId, TraceFlags.getSampled(), TraceState.getDefault())));
private final Context notSampledRemoteParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.createFromRemoteParent(

View File

@ -32,14 +32,14 @@ class TraceIdRatioBasedSamplerTest {
private final String parentSpanId = idsGenerator.generateSpanId();
private final SpanContext sampledSpanContext =
SpanContext.create(traceId, parentSpanId, TraceFlags.getSampled(), TraceState.getDefault());
private final Context sampledParentContext = Context.root().with(Span.wrap(sampledSpanContext));
private final Context sampledParentContext = Context.groot().with(Span.wrap(sampledSpanContext));
private final Context notSampledParentContext =
Context.root()
Context.groot()
.with(
Span.wrap(
SpanContext.create(
traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault())));
private final Context invalidParentContext = Context.root().with(Span.getInvalid());
private final Context invalidParentContext = Context.groot().with(Span.getInvalid());
private final LinkData sampledParentLink = LinkData.create(sampledSpanContext);
@Test