@@ -59,6 +59,7 @@ public class MetricsTracer implements ApiTracer {
5959 public static final String DEFAULT_LANGUAGE = "Java" ;
6060 private static final String OPERATION_FINISHED_STATUS_MESSAGE =
6161 "Operation has already been completed" ;
62+ private static final double NANOS_PER_MILLISECOND = 1_000_000.0 ;
6263 private Stopwatch attemptTimer ;
6364 private final Ticker ticker ;
6465 private final Stopwatch operationTimer ;
@@ -94,7 +95,8 @@ public void operationSucceeded() {
9495 throw new IllegalStateException (OPERATION_FINISHED_STATUS_MESSAGE );
9596 }
9697 attributes .put (STATUS_ATTRIBUTE , StatusCode .Code .OK .toString ());
97- metricsRecorder .recordOperationLatency (operationTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
98+ metricsRecorder .recordOperationLatency (
99+ operationTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
98100 metricsRecorder .recordOperationCount (1 , attributes );
99101 }
100102
@@ -111,7 +113,8 @@ public void operationCancelled() {
111113 throw new IllegalStateException (OPERATION_FINISHED_STATUS_MESSAGE );
112114 }
113115 attributes .put (STATUS_ATTRIBUTE , StatusCode .Code .CANCELLED .toString ());
114- metricsRecorder .recordOperationLatency (operationTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
116+ metricsRecorder .recordOperationLatency (
117+ operationTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
115118 metricsRecorder .recordOperationCount (1 , attributes );
116119 }
117120
@@ -129,7 +132,8 @@ public void operationFailed(Throwable error) {
129132 }
130133 // Uses the GRPC status code representation.
131134 attributes .put (STATUS_ATTRIBUTE , ObservabilityUtils .extractStatus (error ).toString ());
132- metricsRecorder .recordOperationLatency (operationTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
135+ metricsRecorder .recordOperationLatency (
136+ operationTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
133137 metricsRecorder .recordOperationCount (1 , attributes );
134138 }
135139
@@ -154,7 +158,8 @@ public void attemptStarted(Object request, int attemptNumber) {
154158 @ Override
155159 public void attemptSucceeded () {
156160 attributes .put (STATUS_ATTRIBUTE , StatusCode .Code .OK .toString ());
157- metricsRecorder .recordAttemptLatency (attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
161+ metricsRecorder .recordAttemptLatency (
162+ attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
158163 metricsRecorder .recordAttemptCount (1 , attributes );
159164 }
160165
@@ -165,7 +170,8 @@ public void attemptSucceeded() {
165170 @ Override
166171 public void attemptCancelled () {
167172 attributes .put (STATUS_ATTRIBUTE , StatusCode .Code .CANCELLED .toString ());
168- metricsRecorder .recordAttemptLatency (attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
173+ metricsRecorder .recordAttemptLatency (
174+ attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
169175 metricsRecorder .recordAttemptCount (1 , attributes );
170176 }
171177
@@ -180,7 +186,8 @@ public void attemptCancelled() {
180186 @ Override
181187 public void attemptFailedDuration (Throwable error , java .time .Duration delay ) {
182188 attributes .put (STATUS_ATTRIBUTE , ObservabilityUtils .extractStatus (error ).toString ());
183- metricsRecorder .recordAttemptLatency (attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
189+ metricsRecorder .recordAttemptLatency (
190+ attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
184191 metricsRecorder .recordAttemptCount (1 , attributes );
185192 }
186193
@@ -204,7 +211,8 @@ public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
204211 @ Override
205212 public void attemptFailedRetriesExhausted (Throwable error ) {
206213 attributes .put (STATUS_ATTRIBUTE , ObservabilityUtils .extractStatus (error ).toString ());
207- metricsRecorder .recordAttemptLatency (attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
214+ metricsRecorder .recordAttemptLatency (
215+ attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
208216 metricsRecorder .recordAttemptCount (1 , attributes );
209217 }
210218
@@ -218,7 +226,8 @@ public void attemptFailedRetriesExhausted(Throwable error) {
218226 @ Override
219227 public void attemptPermanentFailure (Throwable error ) {
220228 attributes .put (STATUS_ATTRIBUTE , ObservabilityUtils .extractStatus (error ).toString ());
221- metricsRecorder .recordAttemptLatency (attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / 1_000_000.0 , attributes );
229+ metricsRecorder .recordAttemptLatency (
230+ attemptTimer .elapsed (TimeUnit .NANOSECONDS ) / NANOS_PER_MILLISECOND , attributes );
222231 metricsRecorder .recordAttemptCount (1 , attributes );
223232 }
224233
@@ -242,7 +251,6 @@ public void addAttributes(Map<String, String> attributes) {
242251 }
243252 ;
244253
245-
246254 @ VisibleForTesting
247255 Map <String , String > getAttributes () {
248256 return attributes ;
0 commit comments