|
33 | 33 | import static com.google.common.truth.Truth.assertThat; |
34 | 34 |
|
35 | 35 | import com.google.api.gax.rpc.ApiException; |
| 36 | +import com.google.api.gax.rpc.LibraryMetadata; |
36 | 37 | import com.google.api.gax.rpc.StatusCode; |
37 | 38 | import com.google.api.gax.rpc.testing.FakeStatusCode; |
38 | 39 | import com.google.common.testing.FakeTicker; |
@@ -68,7 +69,12 @@ void setUp() { |
68 | 69 | ticker = new FakeTicker(); |
69 | 70 | tracer = |
70 | 71 | new GoldenSignalsMetricsTracer( |
71 | | - new GoldenSignalsMetricsRecorder(openTelemetry, ARTIFACT_NAME), |
| 72 | + GoldenSignalsMetricsRecorder.create( |
| 73 | + openTelemetry, |
| 74 | + LibraryMetadata.newBuilder() |
| 75 | + .setArtifactName(ARTIFACT_NAME) |
| 76 | + .setVersion("1.2.3") |
| 77 | + .build()), |
72 | 78 | ApiTracerContext.empty(), |
73 | 79 | ticker); |
74 | 80 | } |
@@ -129,6 +135,8 @@ void operationCancelled_shouldRecordsOKStatus() { |
129 | 135 | assertThat(metricData.getHistogramData().getPoints().iterator().next().getAttributes()) |
130 | 136 | .isEqualTo( |
131 | 137 | Attributes.of( |
| 138 | + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), |
| 139 | + "CancellationException", |
132 | 140 | AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), |
133 | 141 | StatusCode.Code.CANCELLED.toString())); |
134 | 142 | } |
@@ -163,7 +171,67 @@ void operationFailed_shouldRecordsOKStatus() { |
163 | 171 | assertThat(metricData.getHistogramData().getPoints().iterator().next().getAttributes()) |
164 | 172 | .isEqualTo( |
165 | 173 | Attributes.of( |
| 174 | + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), |
| 175 | + "INTERNAL", |
166 | 176 | AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), |
167 | 177 | StatusCode.Code.INTERNAL.toString())); |
168 | 178 | } |
| 179 | + |
| 180 | + @Test |
| 181 | + void operationFailed_shouldRecordCancellationException() { |
| 182 | + java.util.concurrent.CancellationException error = |
| 183 | + new java.util.concurrent.CancellationException("test cancellation"); |
| 184 | + tracer.operationFailed(error); |
| 185 | + |
| 186 | + Collection<MetricData> metrics = metricReader.collectAllMetrics(); |
| 187 | + assertThat(metrics).hasSize(1); |
| 188 | + MetricData metricData = metrics.iterator().next(); |
| 189 | + |
| 190 | + assertThat(metricData.getHistogramData().getPoints()).hasSize(1); |
| 191 | + assertThat(metricData.getHistogramData().getPoints().iterator().next().getAttributes()) |
| 192 | + .isEqualTo( |
| 193 | + Attributes.of( |
| 194 | + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), |
| 195 | + "CancellationException", |
| 196 | + AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), |
| 197 | + StatusCode.Code.CANCELLED.toString())); |
| 198 | + } |
| 199 | + |
| 200 | + @Test |
| 201 | + void operationFailed_shouldRecordClientTimeout() { |
| 202 | + java.net.SocketTimeoutException error = new java.net.SocketTimeoutException("test timeout"); |
| 203 | + tracer.operationFailed(error); |
| 204 | + |
| 205 | + Collection<MetricData> metrics = metricReader.collectAllMetrics(); |
| 206 | + assertThat(metrics).hasSize(1); |
| 207 | + MetricData metricData = metrics.iterator().next(); |
| 208 | + |
| 209 | + assertThat(metricData.getHistogramData().getPoints()).hasSize(1); |
| 210 | + assertThat(metricData.getHistogramData().getPoints().iterator().next().getAttributes()) |
| 211 | + .isEqualTo( |
| 212 | + Attributes.of( |
| 213 | + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), |
| 214 | + "CLIENT_TIMEOUT", |
| 215 | + AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), |
| 216 | + StatusCode.Code.UNKNOWN.toString())); |
| 217 | + } |
| 218 | + |
| 219 | + @Test |
| 220 | + void operationFailed_shouldRecordClientRequestError() { |
| 221 | + IllegalArgumentException error = new IllegalArgumentException("test illegal argument"); |
| 222 | + tracer.operationFailed(error); |
| 223 | + |
| 224 | + Collection<MetricData> metrics = metricReader.collectAllMetrics(); |
| 225 | + assertThat(metrics).hasSize(1); |
| 226 | + MetricData metricData = metrics.iterator().next(); |
| 227 | + |
| 228 | + assertThat(metricData.getHistogramData().getPoints()).hasSize(1); |
| 229 | + assertThat(metricData.getHistogramData().getPoints().iterator().next().getAttributes()) |
| 230 | + .isEqualTo( |
| 231 | + Attributes.of( |
| 232 | + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), |
| 233 | + "CLIENT_REQUEST_ERROR", |
| 234 | + AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), |
| 235 | + StatusCode.Code.UNKNOWN.toString())); |
| 236 | + } |
169 | 237 | } |
0 commit comments