Add toString implementation to various propagator components (#4996)
This commit is contained in:
parent
5442ea0b30
commit
5fb50c1d5e
|
|
@ -139,4 +139,9 @@ public final class W3CBaggagePropagator implements TextMapPropagator {
|
|||
private static boolean isValidBaggageValue(String value) {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "W3CBaggagePropagator";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,4 +213,9 @@ public final class W3CTraceContextPropagator implements TextMapPropagator {
|
|||
OtelEncodingUtils.byteFromBase16(firstTraceFlagsChar, secondTraceFlagsChar));
|
||||
return SpanContext.createFromRemoteParent(traceId, spanId, traceFlags, TraceState.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "W3CTraceContextPropagator";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,4 +473,9 @@ class W3CBaggagePropagatorTest {
|
|||
W3CBaggagePropagator.getInstance().inject(context, carrier, null);
|
||||
assertThat(carrier).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(W3CBaggagePropagator.getInstance().toString()).isEqualTo("W3CBaggagePropagator");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -528,6 +528,11 @@ class W3CTraceContextPropagatorTest {
|
|||
.isSameAs(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(w3cTraceContextPropagator.toString()).isEqualTo("W3CTraceContextPropagator");
|
||||
}
|
||||
|
||||
// Tests transplanted from the w3c test suite
|
||||
|
||||
@ParameterizedTest
|
||||
|
|
|
|||
|
|
@ -33,4 +33,9 @@ final class DefaultContextPropagators implements ContextPropagators {
|
|||
DefaultContextPropagators(TextMapPropagator textMapPropagator) {
|
||||
this.textMapPropagator = textMapPropagator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultContextPropagators{textMapPropagator=" + textMapPropagator + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,17 @@ import java.util.Set;
|
|||
import javax.annotation.Nullable;
|
||||
|
||||
final class MultiTextMapPropagator implements TextMapPropagator {
|
||||
private final TextMapPropagator[] textPropagators;
|
||||
private final TextMapPropagator[] textMapPropagators;
|
||||
private final Collection<String> allFields;
|
||||
|
||||
MultiTextMapPropagator(TextMapPropagator... textPropagators) {
|
||||
this(Arrays.asList(textPropagators));
|
||||
MultiTextMapPropagator(TextMapPropagator... textMapPropagators) {
|
||||
this(Arrays.asList(textMapPropagators));
|
||||
}
|
||||
|
||||
MultiTextMapPropagator(List<TextMapPropagator> textPropagators) {
|
||||
this.textPropagators = new TextMapPropagator[textPropagators.size()];
|
||||
textPropagators.toArray(this.textPropagators);
|
||||
this.allFields = Collections.unmodifiableList(getAllFields(this.textPropagators));
|
||||
MultiTextMapPropagator(List<TextMapPropagator> textMapPropagators) {
|
||||
this.textMapPropagators = new TextMapPropagator[textMapPropagators.size()];
|
||||
textMapPropagators.toArray(this.textMapPropagators);
|
||||
this.allFields = Collections.unmodifiableList(getAllFields(this.textMapPropagators));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,7 +48,7 @@ final class MultiTextMapPropagator implements TextMapPropagator {
|
|||
if (context == null || setter == null) {
|
||||
return;
|
||||
}
|
||||
for (TextMapPropagator textPropagator : textPropagators) {
|
||||
for (TextMapPropagator textPropagator : textMapPropagators) {
|
||||
textPropagator.inject(context, carrier, setter);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,9 +61,14 @@ final class MultiTextMapPropagator implements TextMapPropagator {
|
|||
if (getter == null) {
|
||||
return context;
|
||||
}
|
||||
for (TextMapPropagator textPropagator : textPropagators) {
|
||||
for (TextMapPropagator textPropagator : textMapPropagators) {
|
||||
context = textPropagator.extract(context, carrier, getter);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MultiTextMapPropagator{textMapPropagators=" + Arrays.toString(textMapPropagators) + '}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,9 @@ final class NoopTextMapPropagator implements TextMapPropagator {
|
|||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NoopTextMapPropagator";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,4 +167,10 @@ class MultiTextMapPropagatorTest {
|
|||
new MultiTextMapPropagator(propagator1, propagator2).inject(context, carrier, null);
|
||||
assertThat(carrier).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(new MultiTextMapPropagator(propagator1, propagator2).toString())
|
||||
.isEqualTo("MultiTextMapPropagator{textMapPropagators=[propagator1, propagator2]}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,11 @@ class NoopTextMapPropagatorTest {
|
|||
assertThat(carrier).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(TextMapPropagator.noop().toString()).isEqualTo("NoopTextMapPropagator");
|
||||
}
|
||||
|
||||
enum MapTextMapGetter implements TextMapGetter<Map<? extends Object, ? extends Object>> {
|
||||
INSTANCE;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,7 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
|
||||
|
|
|
|||
|
|
@ -1,2 +1,10 @@
|
|||
Comparing source compatibility of against
|
||||
No changes.
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.B3Propagator (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.JaegerPropagator (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
|
||||
*** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.extension.trace.propagation.OtTracePropagator (not serializable)
|
||||
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
|
||||
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
|
||||
|
|
|
|||
|
|
@ -99,4 +99,9 @@ public final class PassThroughPropagator implements TextMapPropagator {
|
|||
}
|
||||
return extracted != null ? context.with(EXTRACTED_KEY_VALUES, extracted) : context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PassThroughPropagator{fields=" + fields + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,4 +87,9 @@ class PassThroughPropagatorTest {
|
|||
.isInstanceOf(NullPointerException.class)
|
||||
.hasMessageContaining("field");
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(propagator.toString()).isEqualTo("PassThroughPropagator{fields=[animal, food]}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,4 +123,9 @@ public final class B3Propagator implements TextMapPropagator {
|
|||
.findFirst()
|
||||
.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B3Propagator{b3PropagatorInjector=" + b3PropagatorInjector + "}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,4 +54,9 @@ final class B3PropagatorInjectorMultipleHeaders implements B3PropagatorInjector
|
|||
public Collection<String> fields() {
|
||||
return FIELDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B3PropagatorInjectorMultipleHeaders";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,4 +67,9 @@ final class B3PropagatorInjectorSingleHeader implements B3PropagatorInjector {
|
|||
public Collection<String> fields() {
|
||||
return FIELDS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "B3PropagatorInjectorSingleHeader";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,6 +145,11 @@ public final class JaegerPropagator implements TextMapPropagator {
|
|||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JaegerPropagator";
|
||||
}
|
||||
|
||||
private static <C> SpanContext getSpanContextFromHeader(
|
||||
@Nullable C carrier, TextMapGetter<C> getter) {
|
||||
String value = getter.get(carrier, PROPAGATION_HEADER);
|
||||
|
|
|
|||
|
|
@ -133,4 +133,9 @@ public final class OtTracePropagator implements TextMapPropagator {
|
|||
}
|
||||
return Common.buildSpanContext(traceId, spanId, sampled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OtTracePropagator";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -724,4 +724,12 @@ class B3PropagatorTest {
|
|||
B3Propagator.COMBINED_HEADER,
|
||||
TRACE_ID + "-" + SPAN_ID + "-" + B3Propagator.SINGLE_HEADER_DEBUG);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(b3Propagator.toString())
|
||||
.isEqualTo("B3Propagator{b3PropagatorInjector=B3PropagatorInjectorMultipleHeaders}");
|
||||
assertThat(b3PropagatorSingleHeader.toString())
|
||||
.isEqualTo("B3Propagator{b3PropagatorInjector=B3PropagatorInjectorSingleHeader}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -460,6 +460,11 @@ class JaegerPropagatorTest {
|
|||
assertThat(jaegerPropagator.extract(context, Collections.emptyMap(), null)).isSameAs(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(jaegerPropagator.toString()).isEqualTo("JaegerPropagator");
|
||||
}
|
||||
|
||||
private static String generateTraceIdHeaderValue(
|
||||
String traceId, String spanId, char parentSpan, String sampled) {
|
||||
return traceId
|
||||
|
|
|
|||
|
|
@ -340,4 +340,9 @@ class OtTracePropagatorTest {
|
|||
Context.current());
|
||||
assertThat(propagator.extract(context, Collections.emptyMap(), null)).isSameAs(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
void toString_Valid() {
|
||||
assertThat(propagator.toString()).isEqualTo("OtTracePropagator");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ public final class OpenTelemetrySdk implements OpenTelemetry {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO(anuraaga): Add propagators
|
||||
return "OpenTelemetrySdk{"
|
||||
+ "tracerProvider="
|
||||
+ tracerProvider.unobfuscate()
|
||||
|
|
@ -88,6 +87,8 @@ public final class OpenTelemetrySdk implements OpenTelemetry {
|
|||
+ meterProvider.unobfuscate()
|
||||
+ ", loggerProvider="
|
||||
+ loggerProvider
|
||||
+ ", propagators="
|
||||
+ propagators
|
||||
+ "}";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -326,6 +326,8 @@ class OpenTelemetrySdkTest {
|
|||
when(metricExporter.toString()).thenReturn("MockMetricExporter{}");
|
||||
LogRecordExporter logRecordExporter = mock(LogRecordExporter.class);
|
||||
when(logRecordExporter.toString()).thenReturn("MockLogRecordExporter{}");
|
||||
TextMapPropagator propagator = mock(TextMapPropagator.class);
|
||||
when(propagator.toString()).thenReturn("MockTextMapPropagator{}");
|
||||
Resource resource =
|
||||
Resource.builder().put(AttributeKey.stringKey("service.name"), "otel-test").build();
|
||||
OpenTelemetrySdk sdk =
|
||||
|
|
@ -352,6 +354,7 @@ class OpenTelemetrySdkTest {
|
|||
SimpleLogRecordProcessor.create(
|
||||
LogRecordExporter.composite(logRecordExporter, logRecordExporter)))
|
||||
.build())
|
||||
.setPropagators(ContextPropagators.create(propagator))
|
||||
.build();
|
||||
|
||||
assertThat(sdk.toString())
|
||||
|
|
@ -376,7 +379,8 @@ class OpenTelemetrySdkTest {
|
|||
+ "resource=Resource{schemaUrl=null, attributes={service.name=\"otel-test\"}}, "
|
||||
+ "logLimits=LogLimits{maxNumberOfAttributes=128, maxAttributeValueLength=2147483647}, "
|
||||
+ "logRecordProcessor=SimpleLogRecordProcessor{logRecordExporter=MultiLogRecordExporter{logRecordExporters=[MockLogRecordExporter{}, MockLogRecordExporter{}]}}"
|
||||
+ "}"
|
||||
+ "}, "
|
||||
+ "propagators=DefaultContextPropagators{textMapPropagator=MockTextMapPropagator{}}"
|
||||
+ "}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue