|
22 | 22 | package com.azure.monitor.opentelemetry.exporter.implementation.logging; |
23 | 23 |
|
24 | 24 | import static com.azure.monitor.opentelemetry.exporter.implementation.utils.AzureMonitorMsgId.INGESTION_ERROR; |
| 25 | +import static java.util.Collections.singleton; |
25 | 26 |
|
26 | 27 | import com.azure.monitor.opentelemetry.exporter.implementation.pipeline.TelemetryPipeline; |
27 | 28 | import com.azure.monitor.opentelemetry.exporter.implementation.pipeline.TelemetryPipelineListener; |
@@ -66,13 +67,12 @@ public void onResponse(TelemetryPipelineRequest request, TelemetryPipelineRespon |
66 | 67 | break; |
67 | 68 | case 206: // PARTIAL CONTENT, Breeze-specific: PARTIAL SUCCESS |
68 | 69 | case 400: // breeze returns if json content is bad (e.g. missing required field) |
69 | | - operationLogger.recordFailure( |
70 | | - "Received response code " |
71 | | - + responseCode |
72 | | - + " (" |
73 | | - + getErrorMessageFromPartialSuccessResponse(response.getBody()) |
74 | | - + ")", |
75 | | - INGESTION_ERROR); |
| 70 | + Set<String> errors = getErrors(response.getBody()); |
| 71 | + if (!errors.isEmpty()) { |
| 72 | + operationLogger.recordFailure( |
| 73 | + "Received response code " + responseCode + " (" + String.join(", ", errors) + ")", |
| 74 | + INGESTION_ERROR); |
| 75 | + } |
76 | 76 | break; |
77 | 77 | case 307: |
78 | 78 | case 308: |
@@ -126,21 +126,20 @@ public CompletableResultCode shutdown() { |
126 | 126 | return CompletableResultCode.ofSuccess(); |
127 | 127 | } |
128 | 128 |
|
129 | | - private static String getErrorMessageFromPartialSuccessResponse(String body) { |
| 129 | + private static Set<String> getErrors(String body) { |
130 | 130 | JsonNode jsonNode; |
131 | 131 | try { |
132 | 132 | jsonNode = new ObjectMapper().readTree(body); |
133 | 133 | } catch (JsonProcessingException e) { |
134 | 134 | // fallback to generic message |
135 | | - return "Could not parse response"; |
| 135 | + return singleton("Could not parse response"); |
136 | 136 | } |
137 | 137 | List<JsonNode> errorNodes = new ArrayList<>(); |
138 | 138 | jsonNode.get("errors").forEach(errorNodes::add); |
139 | | - Set<String> errors = |
140 | | - errorNodes.stream() |
141 | | - .map(errorNode -> errorNode.get("message").asText()) |
142 | | - .collect(Collectors.toSet()); |
143 | | - return String.join(", ", errors); |
| 139 | + return errorNodes.stream() |
| 140 | + .map(errorNode -> errorNode.get("message").asText()) |
| 141 | + .filter(s -> !s.equals("Telemetry sampled out.")) |
| 142 | + .collect(Collectors.toSet()); |
144 | 143 | } |
145 | 144 |
|
146 | 145 | private static String getErrorMessageFromCredentialRelatedResponse( |
|
0 commit comments