1616package org .springframework .data .cassandra .observability ;
1717
1818import io .micrometer .observation .Observation ;
19+ import io .micrometer .observation .Observation .Context ;
1920import io .micrometer .observation .Observation .Event ;
2021
2122import 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