Search in sources :

Example 36 with Baggage

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

the class W3CBaggagePropagatorTest method extract_value_multiple_empty.

@Test
void extract_value_multiple_empty() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key1=,key1=val"), getter);
    Baggage expectedBaggage = Baggage.builder().put("key1", "val").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 37 with Baggage

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

the class JaegerPropagatorTest method inject_baggageOnly.

@Test
void inject_baggageOnly() {
    // Metadata won't be propagated, but it MUST NOT cause ay problem.
    Baggage baggage = Baggage.builder().put("nometa", "nometa-value").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);
    assertThat(carrier).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(BAGGAGE_PREFIX + "nometa", "nometa-value", BAGGAGE_PREFIX + "meta", "meta-value"));
}
Also used : Baggage(io.opentelemetry.api.baggage.Baggage) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 38 with Baggage

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

the class OtTracePropagatorTest method extract_Baggage.

@Test
void extract_Baggage() {
    Map<String, String> carrier = new LinkedHashMap<>();
    carrier.put(OtTracePropagator.TRACE_ID_HEADER, TRACE_ID);
    carrier.put(OtTracePropagator.SPAN_ID_HEADER, SPAN_ID);
    carrier.put(OtTracePropagator.SAMPLED_HEADER, Common.TRUE_INT);
    carrier.put(OtTracePropagator.PREFIX_BAGGAGE_HEADER + "foo", "bar");
    carrier.put(OtTracePropagator.PREFIX_BAGGAGE_HEADER + "key", "value");
    Context context = propagator.extract(Context.current(), carrier, getter);
    Baggage expectedBaggage = Baggage.builder().put("foo", "bar").put("key", "value").build();
    assertThat(Baggage.fromContext(context)).isEqualTo(expectedBaggage);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) Baggage(io.opentelemetry.api.baggage.Baggage) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 39 with Baggage

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

the class AttributesProcessorTest method appendBaggage_doesNotOverrideExistingKeys.

@Test
public void appendBaggage_doesNotOverrideExistingKeys() {
    AttributesProcessor processor = AttributesProcessor.appendBaggageByKeyName(ignored -> true);
    Baggage baggage = Baggage.builder().put("test", "drop").build();
    Context context = Context.root().with(baggage);
    assertThat(processor.process(Attributes.builder().put("test", "keep").build(), context)).hasSize(1).containsEntry("test", "keep");
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Example 40 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project jambalaya by tailrocks.

the class TenancyUtilsTests method test1.

@Test
void test1() {
    // GIVEN:
    String tenant = "test";
    // WHEN:
    Context context = TenancyUtils.setTenantString(tenant);
    // THEN:
    assertNotNull(context);
    // WHEN:
    Baggage baggage = Baggage.fromContextOrNull(context);
    // THEN:
    assertNotNull(baggage);
    assertNotNull(baggage.getEntryValue("tenant"));
    assertEquals("dGVzdA", baggage.getEntryValue("tenant"));
}
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