Skip to content

Commit

Permalink
Fix ClassCastException in ObservationRequestTracker.
Browse files Browse the repository at this point in the history
This fixes a ClassCastException for CassandraObservationContext when a NoopObservation is returned by the observation registry.

Closes #1541
  • Loading branch information
cfredri4 authored and mp911de committed Nov 29, 2024
1 parent 22138d5 commit 74fca38
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.cassandra.observability;

import io.micrometer.observation.Observation;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.Observation.Event;

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

Observation observation = ((CassandraObservationSupplier) request).getObservation();
Context context = observation.getContext();

((CassandraObservationContext) observation.getContext()).setNode(node);
if (context instanceof CassandraObservationContext) {

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

if (log.isDebugEnabled()) {
log.debug("Marking node error for [" + observation + "]");
observation.highCardinalityKeyValue(
String.format(HighCardinalityKeyNames.NODE_ERROR_TAG.asString(), node.getEndPoint()), error.toString());
observation.event(Event.of(Events.NODE_ERROR.getValue()));

if (log.isDebugEnabled()) {
log.debug("Marking node error for [" + observation + "]");
}
}
}
}
Expand All @@ -105,13 +110,17 @@ public void onNodeSuccess(Request request, long latencyNanos, DriverExecutionPro
if (request instanceof CassandraObservationSupplier) {

Observation observation = ((CassandraObservationSupplier) request).getObservation();
Context context = observation.getContext();

((CassandraObservationContext) observation.getContext()).setNode(node);
if (context instanceof CassandraObservationContext) {

observation.event(Event.of(Events.NODE_SUCCESS.getValue()));
((CassandraObservationContext) context).setNode(node);

if (log.isDebugEnabled()) {
log.debug("Marking node success for [" + observation + "]");
observation.event(Event.of(Events.NODE_SUCCESS.getValue()));

if (log.isDebugEnabled()) {
log.debug("Marking node success for [" + observation + "]");
}
}
}
}
Expand Down

0 comments on commit 74fca38

Please sign in to comment.