use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.
the class W3CBaggagePropagatorTest method extract_value_trailingSpaces_withMetadata.
@Test
void extract_value_trailingSpaces_withMetadata() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value1 ;meta1=meta2"), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1", BaggageEntryMetadata.create("meta1=meta2")).build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}
use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.
the class W3CBaggagePropagatorTest method extract_value_trailingSpaces.
@Test
void extract_value_trailingSpaces() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value1 "), getter);
Baggage expectedBaggage = Baggage.builder().put("key", "value1").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}
use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.
the class W3CBaggagePropagatorTest method extract_value_multiple_withSeparators.
@Test
void extract_value_multiple_withSeparators() {
W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=val\\ue1,key1=val"), getter);
Baggage expectedBaggage = Baggage.builder().put("key1", "val").build();
assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}
use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.
the class W3CBaggagePropagator method inject.
@Override
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
if (context == null || setter == null) {
return;
}
Baggage baggage = Baggage.fromContext(context);
if (baggage.isEmpty()) {
return;
}
String headerContent = baggageToString(baggage);
if (!headerContent.isEmpty()) {
setter.set(carrier, FIELD, headerContent);
}
}
use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.
the class AwsXrayPropagatorTest method inject_WithBaggage_LimitTruncates.
@Test
void inject_WithBaggage_LimitTruncates() {
Map<String, String> carrier = new LinkedHashMap<>();
// Limit is 256 characters for all baggage. We add a 254-character key/value pair and a
// 3 character key value pair.
String key1 = Stream.generate(() -> "a").limit(252).collect(Collectors.joining());
// 252 + 1 (=) + 1 = 254
String value1 = "a";
String key2 = "b";
// 1 + 1 (=) + 1 = 3
String value2 = "b";
Baggage baggage = Baggage.builder().put(key1, value1).put(key2, value2).build();
xrayPropagator.inject(withSpanContext(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getDefault(), TraceState.getDefault()), Context.current()).with(baggage), carrier, setter);
assertThat(carrier).containsEntry(TRACE_HEADER_KEY, "Root=1-8a3c60f7-d188f8fa79d48a391a778fa6;Parent=53995c3f42cd8ad8;Sampled=0;" + key1 + '=' + value1);
}
Aggregations