Skip to content

Commit 74fca38

Browse files
cfredri4mp911de
authored andcommitted
Fix ClassCastException in ObservationRequestTracker.
This fixes a ClassCastException for CassandraObservationContext when a NoopObservation is returned by the observation registry. Closes #1541
1 parent 22138d5 commit 74fca38

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/ObservationRequestTracker.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.cassandra.observability;
1717

1818
import io.micrometer.observation.Observation;
19+
import io.micrometer.observation.Observation.Context;
1920
import io.micrometer.observation.Observation.Event;
2021

2122
import org.apache.commons.logging.Log;
@@ -85,15 +86,19 @@ public void onNodeError(Request request, Throwable error, long latencyNanos, Dri
8586
if (request instanceof CassandraObservationSupplier) {
8687

8788
Observation observation = ((CassandraObservationSupplier) request).getObservation();
89+
Context context = observation.getContext();
8890

89-
((CassandraObservationContext) observation.getContext()).setNode(node);
91+
if (context instanceof CassandraObservationContext) {
9092

91-
observation.highCardinalityKeyValue(
92-
String.format(HighCardinalityKeyNames.NODE_ERROR_TAG.asString(), node.getEndPoint()), error.toString());
93-
observation.event(Event.of(Events.NODE_ERROR.getValue()));
93+
((CassandraObservationContext) context).setNode(node);
9494

95-
if (log.isDebugEnabled()) {
96-
log.debug("Marking node error for [" + observation + "]");
95+
observation.highCardinalityKeyValue(
96+
String.format(HighCardinalityKeyNames.NODE_ERROR_TAG.asString(), node.getEndPoint()), error.toString());
97+
observation.event(Event.of(Events.NODE_ERROR.getValue()));
98+
99+
if (log.isDebugEnabled()) {
100+
log.debug("Marking node error for [" + observation + "]");
101+
}
97102
}
98103
}
99104
}
@@ -105,13 +110,17 @@ public void onNodeSuccess(Request request, long latencyNanos, DriverExecutionPro
105110
if (request instanceof CassandraObservationSupplier) {
106111

107112
Observation observation = ((CassandraObservationSupplier) request).getObservation();
113+
Context context = observation.getContext();
108114

109-
((CassandraObservationContext) observation.getContext()).setNode(node);
115+
if (context instanceof CassandraObservationContext) {
110116

111-
observation.event(Event.of(Events.NODE_SUCCESS.getValue()));
117+
((CassandraObservationContext) context).setNode(node);
112118

113-
if (log.isDebugEnabled()) {
114-
log.debug("Marking node success for [" + observation + "]");
119+
observation.event(Event.of(Events.NODE_SUCCESS.getValue()));
120+
121+
if (log.isDebugEnabled()) {
122+
log.debug("Marking node success for [" + observation + "]");
123+
}
115124
}
116125
}
117126
}

0 commit comments

Comments
 (0)