Search in sources :

Example 31 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.

the class W3CBaggagePropagatorTest method inject.

@Test
void inject() {
    Baggage baggage = Baggage.builder().put("nometa", "nometa-value").put("needsEncoding", "blah blah blah").put("meta", "meta-value", BaggageEntryMetadata.create("somemetadata; someother=foo")).put("\2ab\3cd", "wacky key nonprintable").put(null, "null key").put("nullvalue", null).build();
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Map<String, String> carrier = new HashMap<>();
    propagator.inject(Context.root().with(baggage), carrier, Map::put);
    assertThat(carrier).containsExactlyInAnyOrderEntriesOf(singletonMap("baggage", "meta=meta-value;somemetadata%3B%20someother%3Dfoo,needsEncoding=blah%20blah%20blah,nometa=nometa-value"));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Baggage(io.opentelemetry.api.baggage.Baggage) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.jupiter.api.Test)

Example 32 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.

the class W3CBaggagePropagatorTest method extract_member_fullComplexities.

@Test
void extract_member_fullComplexities() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1= value1; metadata-key = value; othermetadata, " + "key2 =value2 , key3 =\tvalue3 ; "), getter);
    Baggage expectedBaggage = Baggage.builder().put("key1", "value1", BaggageEntryMetadata.create("metadata-key = value; othermetadata")).put("key2", "value2", BaggageEntryMetadata.empty()).put("key3", "value3").build();
    assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Example 33 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.

the class W3CBaggagePropagatorTest method extract_member_multi.

@Test
void extract_member_multi() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), 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);
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Example 34 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.

the class W3CBaggagePropagatorTest method extract_value_urlEncoding.

@Test
void extract_value_urlEncoding() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value%201"), getter);
    Baggage expectedBaggage = Baggage.builder().put("key", "value 1").build();
    assertThat(Baggage.fromContext(result)).isEqualTo(expectedBaggage);
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Example 35 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project opentelemetry-java by open-telemetry.

the class W3CBaggagePropagatorTest method extract_value_multiple_trailingSpaces.

@Test
void extract_value_multiple_trailingSpaces() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), 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);
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Aggregations

Baggage (io.opentelemetry.api.baggage.Baggage)40 Test (org.junit.jupiter.api.Test)33 Context (io.opentelemetry.context.Context)28 LinkedHashMap (java.util.LinkedHashMap)7 SpanContext (io.opentelemetry.api.trace.SpanContext)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 AttributeKey (io.opentelemetry.api.common.AttributeKey)2 Attributes (io.opentelemetry.api.common.Attributes)2 Span (io.opentelemetry.api.trace.Span)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 BaggageBuilder (io.opentelemetry.api.baggage.BaggageBuilder)1 BaggageEntry (io.opentelemetry.api.baggage.BaggageEntry)1 DoubleCounter (io.opentelemetry.api.metrics.DoubleCounter)1 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)1 DoubleUpDownCounter (io.opentelemetry.api.metrics.DoubleUpDownCounter)1 LongCounter (io.opentelemetry.api.metrics.LongCounter)1 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)1 LongUpDownCounter (io.opentelemetry.api.metrics.LongUpDownCounter)1