4040import com .google .common .base .Stopwatch ;
4141import com .google .common .math .IntMath ;
4242import io .grpc .Deadline ;
43+ import io .grpc .Status ;
4344import io .opentelemetry .api .common .Attributes ;
4445import io .opentelemetry .api .metrics .DoubleGauge ;
4546import io .opentelemetry .api .metrics .DoubleHistogram ;
@@ -336,9 +337,9 @@ public void disableFlowControl() {
336337 flowControlIsDisabled = true ;
337338 }
338339
339- private void recordOperationCompletion (@ Nullable Throwable status ) {
340+ private void recordOperationCompletion (@ Nullable Throwable throwable ) {
340341 if (operationFinishedEarly .get ()) {
341- status = null ; // force an ok
342+ throwable = null ; // force an ok
342343 }
343344
344345 if (!opFinished .compareAndSet (false , true )) {
@@ -347,7 +348,7 @@ private void recordOperationCompletion(@Nullable Throwable status) {
347348 long operationLatencyNano = operationTimer .elapsed (TimeUnit .NANOSECONDS );
348349
349350 boolean isStreaming = operationType == OperationType .ServerStreaming ;
350- String statusStr = extractStatus (status );
351+ Status . Code code = extractStatus (throwable );
351352
352353 // Publish metric data with all the attributes. The attributes get filtered in
353354 // BuiltinMetricsConstants when we construct the views.
@@ -359,7 +360,7 @@ private void recordOperationCompletion(@Nullable Throwable status) {
359360 .put (METHOD_KEY , spanName .toString ())
360361 .put (CLIENT_NAME_KEY , NAME )
361362 .put (STREAMING_KEY , isStreaming )
362- .put (STATUS_KEY , statusStr )
363+ .put (STATUS_KEY , code . name () )
363364 .build ();
364365
365366 // Only record when retry count is greater than 0 so the retry
@@ -381,9 +382,9 @@ private void recordOperationCompletion(@Nullable Throwable status) {
381382 }
382383 }
383384
384- private void recordAttemptCompletion (@ Nullable Throwable status ) {
385+ private void recordAttemptCompletion (@ Nullable Throwable throwable ) {
385386 if (operationFinishedEarly .get ()) {
386- status = null ; // force an ok
387+ throwable = null ; // force an ok
387388 }
388389 // If the attempt failed, the time spent in retry should be counted in application latency.
389390 // Stop the stopwatch and decrement requestLeft.
@@ -397,14 +398,14 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
397398
398399 boolean isStreaming = operationType == OperationType .ServerStreaming ;
399400
400- // Patch the status until it's fixed in gax. When an attempt failed,
401+ // Patch the throwable until it's fixed in gax. When an attempt failed,
401402 // it'll throw a ServerStreamingAttemptException. Unwrap the exception
402403 // so it could get processed by extractStatus
403- if (status instanceof ServerStreamingAttemptException ) {
404- status = status .getCause ();
404+ if (throwable instanceof ServerStreamingAttemptException ) {
405+ throwable = throwable .getCause ();
405406 }
406407
407- String statusStr = extractStatus (status );
408+ Status . Code code = extractStatus (throwable );
408409
409410 Attributes attributes =
410411 baseAttributes .toBuilder ()
@@ -414,7 +415,7 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
414415 .put (METHOD_KEY , spanName .toString ())
415416 .put (CLIENT_NAME_KEY , NAME )
416417 .put (STREAMING_KEY , isStreaming )
417- .put (STATUS_KEY , statusStr )
418+ .put (STATUS_KEY , code . name () )
418419 .build ();
419420
420421 totalClientBlockingTime .addAndGet (grpcMessageSentDelay .get ());
@@ -477,11 +478,11 @@ public void setBatchWriteFlowControlTargetQps(double targetQps) {
477478
478479 @ Override
479480 public void addBatchWriteFlowControlFactor (
480- double factor , @ Nullable Throwable status , boolean applied ) {
481+ double factor , @ Nullable Throwable throwable , boolean applied ) {
481482 Attributes attributes =
482483 baseAttributes .toBuilder ()
483484 .put (METHOD_KEY , spanName .toString ())
484- .put (STATUS_KEY , extractStatus (status ))
485+ .put (STATUS_KEY , extractStatus (throwable ). name ( ))
485486 .put (APPLIED_KEY , applied )
486487 .build ();
487488
0 commit comments