Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify OTEL integration to reduce deps #1160

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +31,6 @@

import javax.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;

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

@Nullable
private OpenTelemetry openTelemetry;

@Nullable
private ObservationRegistry observationRegistry;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -140,10 +132,7 @@ private Mono<Void> doSendAsync(String topic, T message) {
}

private boolean canUseObservation() {
return observationEnabled
&& observationRegistry != null
&& openTelemetry != null
&& beanName != null;
return observationEnabled && observationRegistry != null && beanName != null;
}

private Mono<Void> publishEvent(String pubsubName, String topic, T message) {
Expand All @@ -154,31 +143,25 @@ private Mono<Void> 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<String, String> map = new HashMap<>();
TextMapSetter<Map<String, String>> 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) {
Expand Down
10 changes: 0 additions & 10 deletions dapr-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@
<optional>true</optional>
</dependency>

<!-- OTEL dependencies -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Loading