Search in sources :

Example 1 with Baggage

use of io.opentelemetry.api.baggage.Baggage in project camel-quarkus by apache.

the class CamelQuarkusOpenTelemetryTracer method startExchangeBeginSpan.

@Override
protected SpanAdapter startExchangeBeginSpan(Exchange exchange, SpanDecorator sd, String operationName, SpanKind kind, SpanAdapter parent) {
    // augment the existing incoming one with additional camel specific tags & attributes
    if (sd instanceof PlatformHttpSpanDecorator || sd instanceof ServletSpanDecorator) {
        Span span = Span.fromContext(Context.current());
        Baggage baggage = Baggage.fromContext(Context.current());
        return new OpenTelemetrySpanAdapter(span, baggage);
    }
    return super.startExchangeBeginSpan(exchange, sd, operationName, kind, parent);
}
Also used : PlatformHttpSpanDecorator(org.apache.camel.tracing.decorators.PlatformHttpSpanDecorator) Span(io.opentelemetry.api.trace.Span) Baggage(io.opentelemetry.api.baggage.Baggage) ServletSpanDecorator(org.apache.camel.tracing.decorators.ServletSpanDecorator)

Example 2 with Baggage

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

the class W3CBaggagePropagatorTest method extract_key_trailingSpaces.

@Test
void extract_key_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);
}
Also used : Context(io.opentelemetry.context.Context) Baggage(io.opentelemetry.api.baggage.Baggage) Test(org.junit.jupiter.api.Test)

Example 3 with Baggage

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

the class W3CBaggagePropagatorTest method extract_member_single_withMetadata.

@Test
void extract_member_single_withMetadata() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "key=value;metadata-key=value;othermetadata"), getter);
    Baggage expectedBaggage = Baggage.builder().put("key", "value", BaggageEntryMetadata.create("metadata-key=value;othermetadata")).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 4 with Baggage

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

the class W3CBaggagePropagatorTest method inject_emptyBaggage.

@Test
void inject_emptyBaggage() {
    Baggage baggage = Baggage.empty();
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Map<String, String> carrier = new HashMap<>();
    propagator.inject(Context.root().with(baggage), carrier, Map::put);
    assertThat(carrier).isEmpty();
}
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 5 with Baggage

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

the class W3CBaggagePropagatorTest method extract_key_singleValid_multipleInvalid.

@Test
void extract_key_singleValid_multipleInvalid() {
    W3CBaggagePropagator propagator = W3CBaggagePropagator.getInstance();
    Context result = propagator.extract(Context.root(), ImmutableMap.of("baggage", "ke<y=value1, ;sss,key=value;meta1=value1;meta2=value2,ke(y=value;meta=val "), getter);
    Baggage expectedBaggage = Baggage.builder().put("key", "value", BaggageEntryMetadata.create("meta1=value1;meta2=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)

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