Skip to content

Commit 3dc96d7

Browse files
Simplify OTEL integration to reduce deps (#1160)
1 parent be05a47 commit 3dc96d7

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

dapr-spring/dapr-spring-messaging/src/main/java/io/dapr/spring/messaging/DaprMessagingTemplate.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import io.dapr.spring.messaging.observation.DaprMessagingSenderContext;
2121
import io.micrometer.observation.Observation;
2222
import io.micrometer.observation.ObservationRegistry;
23-
import io.opentelemetry.api.OpenTelemetry;
24-
import io.opentelemetry.context.propagation.TextMapSetter;
2523
import org.slf4j.Logger;
2624
import org.slf4j.LoggerFactory;
2725
import org.springframework.beans.factory.BeanNameAware;
@@ -33,7 +31,6 @@
3331

3432
import javax.annotation.Nullable;
3533

36-
import java.util.HashMap;
3734
import java.util.Map;
3835

3936
/**
@@ -59,9 +56,6 @@ public class DaprMessagingTemplate<T> implements DaprMessagingOperations<T>, App
5956
@Nullable
6057
private String beanName;
6158

62-
@Nullable
63-
private OpenTelemetry openTelemetry;
64-
6559
@Nullable
6660
private ObservationRegistry observationRegistry;
6761

@@ -109,8 +103,6 @@ public void afterSingletonsInstantiated() {
109103

110104
observationRegistry = applicationContext.getBeanProvider(ObservationRegistry.class)
111105
.getIfUnique(() -> observationRegistry);
112-
this.openTelemetry = this.applicationContext.getBeanProvider(OpenTelemetry.class)
113-
.getIfUnique(() -> this.openTelemetry);
114106
observationConvention = applicationContext.getBeanProvider(DaprMessagingObservationConvention.class)
115107
.getIfUnique(() -> observationConvention);
116108
}
@@ -140,10 +132,7 @@ private Mono<Void> doSendAsync(String topic, T message) {
140132
}
141133

142134
private boolean canUseObservation() {
143-
return observationEnabled
144-
&& observationRegistry != null
145-
&& openTelemetry != null
146-
&& beanName != null;
135+
return observationEnabled && observationRegistry != null && beanName != null;
147136
}
148137

149138
private Mono<Void> publishEvent(String pubsubName, String topic, T message) {
@@ -154,31 +143,25 @@ private Mono<Void> publishEventWithObservation(String pubsubName, String topic,
154143
DaprMessagingSenderContext senderContext = DaprMessagingSenderContext.newContext(topic, this.beanName);
155144
Observation observation = createObservation(senderContext);
156145

157-
return observation.observe(() ->
158-
publishEvent(pubsubName, topic, message)
159-
.contextWrite(getReactorContext())
160-
.doOnError(err -> {
161-
LOGGER.error("Failed to send msg to '{}' topic", topic, err);
162-
163-
observation.error(err);
164-
observation.stop();
165-
})
166-
.doOnSuccess(ignore -> {
167-
LOGGER.trace("Sent msg to '{}' topic", topic);
146+
observation.start();
168147

169-
observation.stop();
170-
})
171-
);
172-
}
148+
return publishEvent(pubsubName, topic, message)
149+
.contextWrite(getReactorContext(senderContext))
150+
.doOnError(err -> {
151+
LOGGER.error("Failed to send msg to '{}' topic", topic, err);
173152

174-
private Context getReactorContext() {
175-
Map<String, String> map = new HashMap<>();
176-
TextMapSetter<Map<String, String>> setter = (carrier, key, value) -> map.put(key, value);
177-
io.opentelemetry.context.Context otelContext = io.opentelemetry.context.Context.current();
153+
observation.error(err);
154+
observation.stop();
155+
})
156+
.doOnSuccess(ignore -> {
157+
LOGGER.trace("Sent msg to '{}' topic", topic);
178158

179-
openTelemetry.getPropagators().getTextMapPropagator().inject(otelContext, map, setter);
159+
observation.stop();
160+
});
161+
}
180162

181-
return Context.of(map);
163+
private Context getReactorContext(DaprMessagingSenderContext senderContext) {
164+
return Context.of(senderContext.properties());
182165
}
183166

184167
private Observation createObservation(DaprMessagingSenderContext senderContext) {

dapr-spring/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@
7575
<optional>true</optional>
7676
</dependency>
7777

78-
<!-- OTEL dependencies -->
79-
<dependency>
80-
<groupId>io.opentelemetry</groupId>
81-
<artifactId>opentelemetry-api</artifactId>
82-
</dependency>
83-
<dependency>
84-
<groupId>io.opentelemetry</groupId>
85-
<artifactId>opentelemetry-context</artifactId>
86-
</dependency>
87-
8878
<!-- Test dependencies -->
8979
<dependency>
9080
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)