From 8d3c5b271dc60793ccea15d3f1f0a24d5418a3a3 Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Tue, 5 Nov 2024 12:59:16 +0200 Subject: [PATCH] Simplify OTEL integration to reduce deps Signed-off-by: Artur Ciocanu --- .../messaging/DaprMessagingTemplate.java | 49 ++++++------------- dapr-spring/pom.xml | 10 ---- 2 files changed, 16 insertions(+), 43 deletions(-) diff --git a/dapr-spring/dapr-spring-messaging/src/main/java/io/dapr/spring/messaging/DaprMessagingTemplate.java b/dapr-spring/dapr-spring-messaging/src/main/java/io/dapr/spring/messaging/DaprMessagingTemplate.java index 6e4140936..d8929704e 100644 --- a/dapr-spring/dapr-spring-messaging/src/main/java/io/dapr/spring/messaging/DaprMessagingTemplate.java +++ b/dapr-spring/dapr-spring-messaging/src/main/java/io/dapr/spring/messaging/DaprMessagingTemplate.java @@ -20,8 +20,6 @@ import io.dapr.spring.messaging.observation.DaprMessagingSenderContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.context.propagation.TextMapSetter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanNameAware; @@ -33,7 +31,6 @@ import javax.annotation.Nullable; -import java.util.HashMap; import java.util.Map; /** @@ -59,9 +56,6 @@ public class DaprMessagingTemplate implements DaprMessagingOperations, App @Nullable private String beanName; - @Nullable - private OpenTelemetry openTelemetry; - @Nullable private ObservationRegistry observationRegistry; @@ -109,8 +103,6 @@ public void afterSingletonsInstantiated() { observationRegistry = applicationContext.getBeanProvider(ObservationRegistry.class) .getIfUnique(() -> observationRegistry); - this.openTelemetry = this.applicationContext.getBeanProvider(OpenTelemetry.class) - .getIfUnique(() -> this.openTelemetry); observationConvention = applicationContext.getBeanProvider(DaprMessagingObservationConvention.class) .getIfUnique(() -> observationConvention); } @@ -140,10 +132,7 @@ private Mono doSendAsync(String topic, T message) { } private boolean canUseObservation() { - return observationEnabled - && observationRegistry != null - && openTelemetry != null - && beanName != null; + return observationEnabled && observationRegistry != null && beanName != null; } private Mono publishEvent(String pubsubName, String topic, T message) { @@ -154,31 +143,25 @@ private Mono publishEventWithObservation(String pubsubName, String topic, DaprMessagingSenderContext senderContext = DaprMessagingSenderContext.newContext(topic, this.beanName); Observation observation = createObservation(senderContext); - return observation.observe(() -> - publishEvent(pubsubName, topic, message) - .contextWrite(getReactorContext()) - .doOnError(err -> { - LOGGER.error("Failed to send msg to '{}' topic", topic, err); - - observation.error(err); - observation.stop(); - }) - .doOnSuccess(ignore -> { - LOGGER.trace("Sent msg to '{}' topic", topic); + observation.start(); - observation.stop(); - }) - ); - } + return publishEvent(pubsubName, topic, message) + .contextWrite(getReactorContext(senderContext)) + .doOnError(err -> { + LOGGER.error("Failed to send msg to '{}' topic", topic, err); - private Context getReactorContext() { - Map map = new HashMap<>(); - TextMapSetter> setter = (carrier, key, value) -> map.put(key, value); - io.opentelemetry.context.Context otelContext = io.opentelemetry.context.Context.current(); + observation.error(err); + observation.stop(); + }) + .doOnSuccess(ignore -> { + LOGGER.trace("Sent msg to '{}' topic", topic); - openTelemetry.getPropagators().getTextMapPropagator().inject(otelContext, map, setter); + observation.stop(); + }); + } - return Context.of(map); + private Context getReactorContext(DaprMessagingSenderContext senderContext) { + return Context.of(senderContext.properties()); } private Observation createObservation(DaprMessagingSenderContext senderContext) { diff --git a/dapr-spring/pom.xml b/dapr-spring/pom.xml index 9a67c459c..a7c9474f3 100644 --- a/dapr-spring/pom.xml +++ b/dapr-spring/pom.xml @@ -75,16 +75,6 @@ true - - - io.opentelemetry - opentelemetry-api - - - io.opentelemetry - opentelemetry-context - - org.springframework.boot