16
16
package org .springframework .data .cassandra .observability ;
17
17
18
18
import io .micrometer .observation .Observation ;
19
+ import io .micrometer .observation .Observation .Context ;
19
20
import io .micrometer .observation .Observation .Event ;
20
21
21
22
import org .apache .commons .logging .Log ;
@@ -85,15 +86,19 @@ public void onNodeError(Request request, Throwable error, long latencyNanos, Dri
85
86
if (request instanceof CassandraObservationSupplier ) {
86
87
87
88
Observation observation = ((CassandraObservationSupplier ) request ).getObservation ();
89
+ Context context = observation .getContext ();
88
90
89
- (( CassandraObservationContext ) observation . getContext ()). setNode ( node );
91
+ if ( context instanceof CassandraObservationContext ) {
90
92
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 );
94
94
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
+ }
97
102
}
98
103
}
99
104
}
@@ -105,13 +110,17 @@ public void onNodeSuccess(Request request, long latencyNanos, DriverExecutionPro
105
110
if (request instanceof CassandraObservationSupplier ) {
106
111
107
112
Observation observation = ((CassandraObservationSupplier ) request ).getObservation ();
113
+ Context context = observation .getContext ();
108
114
109
- (( CassandraObservationContext ) observation . getContext ()). setNode ( node );
115
+ if ( context instanceof CassandraObservationContext ) {
110
116
111
- observation . event ( Event . of ( Events . NODE_SUCCESS . getValue ()) );
117
+ (( CassandraObservationContext ) context ). setNode ( node );
112
118
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
+ }
115
124
}
116
125
}
117
126
}
0 commit comments