|
29 | 29 | */ |
30 | 30 | package com.google.api.gax.tracing; |
31 | 31 |
|
32 | | - |
33 | 32 | import com.google.common.annotations.VisibleForTesting; |
34 | 33 | import com.google.common.base.Stopwatch; |
35 | 34 | import com.google.common.base.Ticker; |
36 | 35 | import java.util.HashMap; |
37 | 36 | import java.util.Map; |
| 37 | +import java.util.concurrent.CancellationException; |
38 | 38 | import java.util.concurrent.TimeUnit; |
39 | 39 |
|
40 | 40 | /** |
@@ -82,17 +82,18 @@ public void operationSucceeded() { |
82 | 82 |
|
83 | 83 | @Override |
84 | 84 | public void operationCancelled() { |
85 | | - ObservabilityUtils.populateStatusAttributes( |
86 | | - attributes, new java.util.concurrent.CancellationException(), transport); |
87 | | - metricsRecorder.recordOperationLatency( |
88 | | - clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); |
| 85 | + recordError(new CancellationException()); |
89 | 86 | } |
90 | 87 |
|
91 | 88 | @Override |
92 | 89 | public void operationFailed(Throwable error) { |
| 90 | + recordError(error); |
| 91 | + } |
| 92 | + |
| 93 | + private void recordError(Throwable error) { |
| 94 | + ObservabilityUtils.populateStatusAttributes(attributes, error, transport); |
93 | 95 | attributes.put( |
94 | 96 | ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error)); |
95 | | - ObservabilityUtils.populateStatusAttributes(attributes, error, transport); |
96 | 97 | metricsRecorder.recordOperationLatency( |
97 | 98 | clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); |
98 | 99 | } |
|
0 commit comments