diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/ObservationRequestTracker.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/ObservationRequestTracker.java index a3d040097..79e2c4846 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/ObservationRequestTracker.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/ObservationRequestTracker.java @@ -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; @@ -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 + "]"); + } } } } @@ -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 + "]"); + } } } }