Skip to content

Commit aa296fa

Browse files
salaboyyaron2javier-aliaga
authored
Adding sdk tracing capabilities on spring (#1713)
* adding sdk tracing capabilities on spring Signed-off-by: salaboy <Salaboy@gmail.com> * fix: guard highCardinalityKeyValue calls against null values in ObservationDaprClient Micrometer's highCardinalityKeyValue throws NPE when the value is null. Added a safe() helper that coalesces nulls to empty string, applied to all observation tag values in both Spring Boot 3 and Boot 4 modules. Signed-off-by: Javier Aliaga <javier@diagrid.io> * fix: add null validation in constructors and fix license header formatting Add Objects.requireNonNull for delegate and observationRegistry in ObservationDaprClient and ObservationDaprWorkflowClient constructors to fail fast on misconfiguration. Fix missing ' * ' prefix on the last line of license headers in all four new files. Signed-off-by: Javier Aliaga <javier@diagrid.io> * fix: defer observation start to subscription time in ObservationDaprClient Wrap observe() and observeFlux() helpers with Mono.defer/Flux.defer so that obs.start() runs on subscription, not on method call. This prevents leaked spans when a Mono is never subscribed and ensures span timing reflects actual execution, not the gap before subscription. Signed-off-by: Javier Aliaga <javier@diagrid.io> * fix: use proper Objects import, revert license header, add deferred-start test Replace fully-qualified java.util.Objects with import statement and fix alphabetical import order to satisfy checkstyle. Revert license header change since the project's checkstyle config expects the original format. Add test verifying that an unsubscribed Mono does not leak an observation. Signed-off-by: Javier Aliaga <javier@diagrid.io> --------- Signed-off-by: salaboy <Salaboy@gmail.com> Signed-off-by: Javier Aliaga <javier@diagrid.io> Co-authored-by: Yaron Schneider <schneider.yaron@live.com> Co-authored-by: Javier Aliaga <javier@diagrid.io>
1 parent 78cf7b4 commit aa296fa

11 files changed

Lines changed: 2941 additions & 6 deletions

File tree

dapr-spring/dapr-spring-boot-4-autoconfigure/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
<artifactId>spring-data-keyvalue</artifactId>
8585
<optional>true</optional>
8686
</dependency>
87+
<dependency>
88+
<groupId>io.micrometer</groupId>
89+
<artifactId>micrometer-observation</artifactId>
90+
<optional>true</optional>
91+
</dependency>
92+
<dependency>
93+
<groupId>io.micrometer</groupId>
94+
<artifactId>micrometer-observation-test</artifactId>
95+
<scope>test</scope>
96+
</dependency>
8797
<dependency>
8898
<groupId>org.springframework.boot</groupId>
8999
<artifactId>spring-boot-starter-web</artifactId>

dapr-spring/dapr-spring-boot-4-autoconfigure/src/main/java/io/dapr/spring/boot4/autoconfigure/client/DaprClientSB4AutoConfiguration.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.dapr.spring.boot.properties.client.DaprConnectionDetails;
2525
import io.dapr.workflows.client.DaprWorkflowClient;
2626
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
27+
import io.micrometer.observation.ObservationRegistry;
2728
import org.springframework.beans.factory.ObjectProvider;
2829
import org.springframework.boot.autoconfigure.AutoConfiguration;
2930
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -91,14 +92,25 @@ DaprClientBuilder daprClientBuilder(DaprConnectionDetails daprConnectionDetails,
9192

9293
@Bean
9394
@ConditionalOnMissingBean
94-
DaprClient daprClient(DaprClientBuilder daprClientBuilder) {
95-
return daprClientBuilder.build();
95+
DaprClient daprClient(DaprClientBuilder daprClientBuilder,
96+
ObjectProvider<ObservationRegistry> observationRegistryProvider) {
97+
DaprClient client = daprClientBuilder.build();
98+
ObservationRegistry registry = observationRegistryProvider.getIfAvailable();
99+
if (registry != null && !registry.isNoop()) {
100+
return new ObservationDaprClient(client, registry);
101+
}
102+
return client;
96103
}
97104

98105
@Bean
99106
@ConditionalOnMissingBean
100-
DaprWorkflowClient daprWorkflowClient(DaprConnectionDetails daprConnectionDetails) {
107+
DaprWorkflowClient daprWorkflowClient(DaprConnectionDetails daprConnectionDetails,
108+
ObjectProvider<ObservationRegistry> observationRegistryProvider) {
101109
Properties properties = createPropertiesFromConnectionDetails(daprConnectionDetails);
110+
ObservationRegistry registry = observationRegistryProvider.getIfAvailable();
111+
if (registry != null && !registry.isNoop()) {
112+
return new ObservationDaprWorkflowClient(properties, registry);
113+
}
102114
return new DaprWorkflowClient(properties);
103115
}
104116

0 commit comments

Comments
 (0)