Search in sources :

Example 11 with TracingMetadata

use of io.smallrye.reactive.messaging.TracingMetadata in project smallrye-reactive-messaging by smallrye.

the class TracingPropagationTest method testFromKafkaToAppToKafka.

@Test
public void testFromKafkaToAppToKafka() {
    List<Context> receivedContexts = new CopyOnWriteArrayList<>();
    String resultTopic = topic + "-result";
    String parentTopic = topic + "-parent";
    ConsumerTask<String, Integer> consumed = companion.consumeIntegers().fromTopics(resultTopic, m -> m.plug(until(10L, Duration.ofMinutes(1), null)).onItem().invoke(record -> {
        receivedContexts.add(GlobalOpenTelemetry.getPropagators().getTextMapPropagator().extract(Context.current(), record.headers(), new HeaderExtractAdapter()));
    }));
    MyAppProcessingData bean = runApplication(getKafkaSinkConfigForMyAppProcessingData(resultTopic, parentTopic), MyAppProcessingData.class);
    List<SpanContext> producedSpanContexts = new CopyOnWriteArrayList<>();
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(parentTopic, null, null, "a-key", i, createTracingSpan(producedSpanContexts, parentTopic)), 10);
    await().until(() -> consumed.getRecords().size() >= 10);
    List<Integer> values = new ArrayList<>();
    assertThat(consumed.getRecords()).allSatisfy(record -> {
        assertThat(record.value()).isNotNull();
        values.add(record.value());
    });
    assertThat(values).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    List<String> producedTraceIds = producedSpanContexts.stream().map(SpanContext::getTraceId).collect(Collectors.toList());
    assertThat(producedTraceIds).hasSize(10);
    assertThat(receivedContexts).hasSize(10);
    assertThat(receivedContexts).doesNotContainNull().doesNotHaveDuplicates();
    List<String> receivedSpanIds = receivedContexts.stream().map(context -> Span.fromContextOrNull(context).getSpanContext().getSpanId()).collect(Collectors.toList());
    assertThat(receivedSpanIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
    List<String> receivedTraceIds = receivedContexts.stream().map(context -> Span.fromContextOrNull(context).getSpanContext().getTraceId()).collect(Collectors.toList());
    assertThat(receivedTraceIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
    assertThat(receivedTraceIds).containsExactlyInAnyOrderElementsOf(producedTraceIds);
    assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
    assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
    List<String> spanIds = new ArrayList<>();
    for (TracingMetadata tracing : bean.tracing()) {
        Span span = Span.fromContext(tracing.getCurrentContext());
        spanIds.add(span.getSpanContext().getSpanId());
        assertThat(Span.fromContextOrNull(tracing.getPreviousContext())).isNotNull();
    }
    await().atMost(Duration.ofMinutes(2)).until(() -> testExporter.getFinishedSpanItems().size() >= 10);
    List<String> outgoingParentIds = new ArrayList<>();
    List<String> incomingParentIds = new ArrayList<>();
    for (SpanData data : testExporter.getFinishedSpanItems()) {
        if (data.getKind().equals(SpanKind.CONSUMER)) {
            incomingParentIds.add(data.getParentSpanId());
            assertThat(data.getAttributes().get(SemanticAttributes.MESSAGING_KAFKA_CONSUMER_GROUP)).isNotNull();
            assertThat(data.getAttributes().get(AttributeKey.stringKey("messaging.consumer_id"))).isNotNull();
            // Need to skip the spans created during @Incoming processing
            continue;
        }
        assertThat(data.getSpanId()).isIn(receivedSpanIds);
        assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
        assertThat(data.getTraceId()).isIn(producedTraceIds);
        assertThat(data.getKind()).isEqualByComparingTo(SpanKind.PRODUCER);
        outgoingParentIds.add(data.getParentSpanId());
    }
    // Assert span created on Kafka record is the parent of consumer span we create
    assertThat(producedSpanContexts.stream().map(SpanContext::getSpanId)).containsExactlyElementsOf(incomingParentIds);
    // Assert consumer span is the parent of the producer span we received in Kafka
    assertThat(spanIds.stream()).containsExactlyElementsOf(outgoingParentIds);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing) KafkaCompanionTestBase(io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Multi(io.smallrye.mutiny.Multi) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ConsumerTask(io.smallrye.reactive.messaging.kafka.companion.ConsumerTask) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ContextPropagators(io.opentelemetry.context.propagation.ContextPropagators) Duration(java.time.Duration) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaConnector(io.smallrye.reactive.messaging.kafka.KafkaConnector) Context(io.opentelemetry.context.Context) Awaitility.await(org.awaitility.Awaitility.await) Span(io.opentelemetry.api.trace.Span) SpanContext(io.opentelemetry.api.trace.SpanContext) Publisher(org.reactivestreams.Publisher) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) RecordQualifiers.until(io.smallrye.reactive.messaging.kafka.companion.RecordQualifiers.until) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Collectors(java.util.stream.Collectors) SpanKind(io.opentelemetry.api.trace.SpanKind) StandardCharsets(java.nio.charset.StandardCharsets) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) Test(org.junit.jupiter.api.Test) List(java.util.List) Message(org.eclipse.microprofile.reactive.messaging.Message) AfterEach(org.junit.jupiter.api.AfterEach) CompletionStage(java.util.concurrent.CompletionStage) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) Header(org.apache.kafka.common.header.Header) AttributeKey(io.opentelemetry.api.common.AttributeKey) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SpanData(io.opentelemetry.sdk.trace.data.SpanData) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) SpanContext(io.opentelemetry.api.trace.SpanContext) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Span(io.opentelemetry.api.trace.Span) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 12 with TracingMetadata

use of io.smallrye.reactive.messaging.TracingMetadata in project smallrye-reactive-messaging by smallrye.

the class TracingPropagationTest method testFromKafkaToAppWithNoParent.

@Test
public void testFromKafkaToAppWithNoParent() {
    MyAppReceivingData bean = runApplication(getKafkaSinkConfigForMyAppReceivingData(topic), MyAppReceivingData.class);
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, null, null, "a-key", i), 10);
    await().until(() -> bean.list().size() >= 10);
    assertThat(bean.list()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
    assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
    List<String> spanIds = new ArrayList<>();
    for (TracingMetadata tracing : bean.tracing()) {
        spanIds.add(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
        assertThat(Span.fromContextOrNull(tracing.getPreviousContext())).isNull();
    }
    assertThat(spanIds).doesNotContainNull().doesNotHaveDuplicates().hasSizeGreaterThanOrEqualTo(10);
    for (SpanData data : testExporter.getFinishedSpanItems()) {
        assertThat(data.getSpanId()).isIn(spanIds);
        assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
        assertThat(data.getKind()).isEqualByComparingTo(SpanKind.CONSUMER);
    }
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 13 with TracingMetadata

use of io.smallrye.reactive.messaging.TracingMetadata in project smallrye-reactive-messaging by smallrye.

the class TracingPropagationTest method testFromKafkaToAppWithParentSpan.

@Test
public void testFromKafkaToAppWithParentSpan() {
    String parentTopic = topic + "-parent";
    String stuffTopic = topic + "-stuff";
    MyAppReceivingData bean = runApplication(getKafkaSinkConfigForMyAppReceivingData(parentTopic), MyAppReceivingData.class);
    List<SpanContext> producedSpanContexts = new CopyOnWriteArrayList<>();
    companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(parentTopic, null, null, "a-key", i, createTracingSpan(producedSpanContexts, stuffTopic)), 10);
    await().until(() -> bean.list().size() >= 10);
    assertThat(bean.list()).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    List<String> producedTraceIds = producedSpanContexts.stream().map(SpanContext::getTraceId).collect(Collectors.toList());
    assertThat(producedTraceIds).hasSize(10);
    assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
    assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
    List<String> receivedTraceIds = bean.tracing().stream().map(tracingMetadata -> Span.fromContext(tracingMetadata.getCurrentContext()).getSpanContext().getTraceId()).collect(Collectors.toList());
    assertThat(receivedTraceIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
    assertThat(receivedTraceIds).containsExactlyInAnyOrderElementsOf(producedTraceIds);
    List<String> spanIds = new ArrayList<>();
    for (TracingMetadata tracing : bean.tracing()) {
        spanIds.add(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
        assertThat(tracing.getPreviousContext()).isNotNull();
        Span previousSpan = Span.fromContextOrNull(tracing.getPreviousContext());
        assertThat(previousSpan).isNotNull();
        assertThat(previousSpan.getSpanContext().getTraceId()).isEqualTo(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getTraceId());
        assertThat(previousSpan.getSpanContext().getSpanId()).isNotEqualTo(Span.fromContext(tracing.getCurrentContext()).getSpanContext().getSpanId());
    }
    assertThat(spanIds).doesNotContainNull().doesNotHaveDuplicates().hasSizeGreaterThanOrEqualTo(10);
    List<String> parentIds = bean.tracing().stream().map(tracingMetadata -> Span.fromContextOrNull(tracingMetadata.getPreviousContext()).getSpanContext().getSpanId()).collect(Collectors.toList());
    assertThat(producedSpanContexts.stream().map(SpanContext::getSpanId)).containsExactlyElementsOf(parentIds);
    for (SpanData data : testExporter.getFinishedSpanItems()) {
        assertThat(data.getSpanId()).isIn(spanIds);
        assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
        assertThat(data.getKind()).isEqualByComparingTo(SpanKind.CONSUMER);
        assertThat(data.getParentSpanId()).isNotNull();
        assertThat(data.getParentSpanId()).isIn(parentIds);
    }
}
Also used : Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing) KafkaCompanionTestBase(io.smallrye.reactive.messaging.kafka.base.KafkaCompanionTestBase) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Multi(io.smallrye.mutiny.Multi) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ConsumerTask(io.smallrye.reactive.messaging.kafka.companion.ConsumerTask) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ContextPropagators(io.opentelemetry.context.propagation.ContextPropagators) Duration(java.time.Duration) IntegerSerializer(org.apache.kafka.common.serialization.IntegerSerializer) KafkaConnector(io.smallrye.reactive.messaging.kafka.KafkaConnector) Context(io.opentelemetry.context.Context) Awaitility.await(org.awaitility.Awaitility.await) Span(io.opentelemetry.api.trace.Span) SpanContext(io.opentelemetry.api.trace.SpanContext) Publisher(org.reactivestreams.Publisher) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) RecordQualifiers.until(io.smallrye.reactive.messaging.kafka.companion.RecordQualifiers.until) KafkaMapBasedConfig(io.smallrye.reactive.messaging.kafka.base.KafkaMapBasedConfig) Collectors(java.util.stream.Collectors) SpanKind(io.opentelemetry.api.trace.SpanKind) StandardCharsets(java.nio.charset.StandardCharsets) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) Test(org.junit.jupiter.api.Test) List(java.util.List) Message(org.eclipse.microprofile.reactive.messaging.Message) AfterEach(org.junit.jupiter.api.AfterEach) CompletionStage(java.util.concurrent.CompletionStage) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) Header(org.apache.kafka.common.header.Header) AttributeKey(io.opentelemetry.api.common.AttributeKey) IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SpanData(io.opentelemetry.sdk.trace.data.SpanData) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) SpanContext(io.opentelemetry.api.trace.SpanContext) SpanData(io.opentelemetry.sdk.trace.data.SpanData) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Span(io.opentelemetry.api.trace.Span) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 14 with TracingMetadata

use of io.smallrye.reactive.messaging.TracingMetadata in project smallrye-reactive-messaging by smallrye.

the class TracingAmqpToAppToAmqpTest method testFromAmqpToAppToAmqp.

@Test
public void testFromAmqpToAppToAmqp() {
    List<Integer> payloads = new CopyOnWriteArrayList<>();
    List<Context> receivedContexts = new CopyOnWriteArrayList<>();
    usage.consumeIntegersWithTracing("result-topic", payloads::add, receivedContexts::add);
    weld.addBeanClass(MyAppProcessingData.class);
    new MapBasedConfig().put("mp.messaging.outgoing.result-topic.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.outgoing.result-topic.durable", false).put("mp.messaging.outgoing.result-topic.host", host).put("mp.messaging.outgoing.result-topic.port", port).put("mp.messaging.incoming.parent-topic.connector", AmqpConnector.CONNECTOR_NAME).put("mp.messaging.incoming.parent-topic.host", host).put("mp.messaging.incoming.parent-topic.port", port).put("amqp-username", username).put("amqp-password", password).write();
    container = weld.initialize();
    MyAppProcessingData bean = container.getBeanManager().createInstance().select(MyAppProcessingData.class).get();
    await().until(() -> isAmqpConnectorReady(container));
    AtomicInteger count = new AtomicInteger();
    List<SpanContext> producedSpanContexts = new CopyOnWriteArrayList<>();
    usage.produce("parent-topic", 10, () -> AmqpMessage.create().durable(false).ttl(10000).withIntegerAsBody(count.getAndIncrement()).applicationProperties(createTracingSpan(producedSpanContexts, "parent-topic")).build());
    await().atMost(Duration.ofMinutes(5)).until(() -> payloads.size() >= 10);
    assertThat(payloads).containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    List<String> producedTraceIds = producedSpanContexts.stream().map(SpanContext::getTraceId).collect(Collectors.toList());
    assertThat(producedTraceIds).hasSize(10);
    assertThat(receivedContexts).hasSize(10);
    assertThat(receivedContexts).doesNotContainNull().doesNotHaveDuplicates();
    List<String> receivedSpanIds = receivedContexts.stream().map(context -> Span.fromContextOrNull(context).getSpanContext().getSpanId()).collect(Collectors.toList());
    assertThat(receivedSpanIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
    List<String> receivedTraceIds = receivedContexts.stream().map(context -> Span.fromContextOrNull(context).getSpanContext().getTraceId()).collect(Collectors.toList());
    assertThat(receivedTraceIds).doesNotContainNull().doesNotHaveDuplicates().hasSize(10);
    assertThat(receivedTraceIds).containsExactlyInAnyOrderElementsOf(producedTraceIds);
    List<String> receivedParentSpanIds = new ArrayList<>();
    assertThat(bean.tracing()).hasSizeGreaterThanOrEqualTo(10);
    assertThat(bean.tracing()).doesNotContainNull().doesNotHaveDuplicates();
    List<String> spanIds = new ArrayList<>();
    for (TracingMetadata tracing : bean.tracing()) {
        Span span = Span.fromContext(tracing.getCurrentContext());
        spanIds.add(span.getSpanContext().getSpanId());
        assertThat(Span.fromContextOrNull(tracing.getPreviousContext())).isNotNull();
    }
    await().atMost(Duration.ofMinutes(2)).until(() -> testExporter.getFinishedSpanItems().size() >= 10);
    List<String> outgoingParentIds = new ArrayList<>();
    List<String> incomingParentIds = new ArrayList<>();
    for (SpanData data : testExporter.getFinishedSpanItems()) {
        if (data.getKind().equals(SpanKind.CONSUMER)) {
            incomingParentIds.add(data.getParentSpanId());
            // Need to skip the spans created during @Incoming processing
            continue;
        }
        assertThat(data.getSpanId()).isIn(receivedSpanIds);
        assertThat(data.getSpanId()).isNotEqualTo(data.getParentSpanId());
        assertThat(data.getTraceId()).isIn(producedTraceIds);
        assertThat(data.getKind()).isEqualByComparingTo(SpanKind.PRODUCER);
        outgoingParentIds.add(data.getParentSpanId());
    }
    // Assert span created on AMQP record is the parent of consumer span we create
    assertThat(producedSpanContexts.stream().map(SpanContext::getSpanId)).containsExactlyElementsOf(incomingParentIds);
    // Assert consumer span is the parent of the producer span we received in AMQP
    assertThat(spanIds.stream()).containsExactlyElementsOf(outgoingParentIds);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextPropagators(io.opentelemetry.context.propagation.ContextPropagators) SmallRyeConfigProviderResolver(io.smallrye.config.SmallRyeConfigProviderResolver) Duration(java.time.Duration) JsonObject(io.vertx.core.json.JsonObject) Weld(org.jboss.weld.environment.se.Weld) AmqpMessage(io.vertx.mutiny.amqp.AmqpMessage) Context(io.opentelemetry.context.Context) Awaitility.await(org.awaitility.Awaitility.await) Properties(java.util.Properties) Span(io.opentelemetry.api.trace.Span) SpanContext(io.opentelemetry.api.trace.SpanContext) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Collectors(java.util.stream.Collectors) SpanKind(io.opentelemetry.api.trace.SpanKind) StandardCharsets(java.nio.charset.StandardCharsets) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) Test(org.junit.jupiter.api.Test) List(java.util.List) Message(org.eclipse.microprofile.reactive.messaging.Message) AfterEach(org.junit.jupiter.api.AfterEach) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SpanData(io.opentelemetry.sdk.trace.data.SpanData) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) SpanContext(io.opentelemetry.api.trace.SpanContext) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Span(io.opentelemetry.api.trace.Span) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) MapBasedConfig(io.smallrye.reactive.messaging.test.common.config.MapBasedConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 15 with TracingMetadata

use of io.smallrye.reactive.messaging.TracingMetadata in project smallrye-reactive-messaging by smallrye.

the class AmqpCreditBasedSender method createOutgoingTrace.

private void createOutgoingTrace(Message<?> msg, io.vertx.mutiny.amqp.AmqpMessage amqp) {
    if (tracingEnabled) {
        Optional<TracingMetadata> tracingMetadata = TracingMetadata.fromMessage(msg);
        final SpanBuilder spanBuilder = AmqpConnector.TRACER.spanBuilder(amqp.address() + " send").setSpanKind(SpanKind.PRODUCER);
        if (tracingMetadata.isPresent()) {
            // Handle possible parent span
            final Context parentSpanContext = tracingMetadata.get().getCurrentContext();
            if (parentSpanContext != null) {
                spanBuilder.setParent(parentSpanContext);
            } else {
                spanBuilder.setNoParent();
            }
        } else {
            spanBuilder.setNoParent();
        }
        final Span span = spanBuilder.startSpan();
        Scope scope = span.makeCurrent();
        // Set Span attributes
        span.setAttribute(SemanticAttributes.MESSAGING_SYSTEM, "AMQP 1.0");
        span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION, amqp.address());
        span.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_KIND, "queue");
        span.setAttribute(SemanticAttributes.MESSAGING_PROTOCOL, "AMQP");
        span.setAttribute(SemanticAttributes.MESSAGING_PROTOCOL_VERSION, "1.0");
        // Set span onto headers
        GlobalOpenTelemetry.getPropagators().getTextMapPropagator().inject(Context.current(), amqp, HeaderInjectAdapter.SETTER);
        span.end();
        scope.close();
    }
}
Also used : Context(io.opentelemetry.context.Context) SpanBuilder(io.opentelemetry.api.trace.SpanBuilder) Scope(io.opentelemetry.context.Scope) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) Span(io.opentelemetry.api.trace.Span)

Aggregations

TracingMetadata (io.smallrye.reactive.messaging.TracingMetadata)15 Context (io.opentelemetry.context.Context)12 Span (io.opentelemetry.api.trace.Span)11 SpanData (io.opentelemetry.sdk.trace.data.SpanData)8 ArrayList (java.util.ArrayList)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)7 SpanKind (io.opentelemetry.api.trace.SpanKind)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Test (org.junit.jupiter.api.Test)7 SpanBuilder (io.opentelemetry.api.trace.SpanBuilder)6 Message (org.eclipse.microprofile.reactive.messaging.Message)6 SpanContext (io.opentelemetry.api.trace.SpanContext)5 W3CTraceContextPropagator (io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator)5 ContextPropagators (io.opentelemetry.context.propagation.ContextPropagators)5 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)5 InMemorySpanExporter (io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter)5 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)5 SpanProcessor (io.opentelemetry.sdk.trace.SpanProcessor)5