diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/logging/DiagnosticTelemetryPipelineListener.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/logging/DiagnosticTelemetryPipelineListener.java index 7902099565a..675552a4003 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/logging/DiagnosticTelemetryPipelineListener.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/logging/DiagnosticTelemetryPipelineListener.java @@ -22,6 +22,7 @@ package com.azure.monitor.opentelemetry.exporter.implementation.logging; import static com.azure.monitor.opentelemetry.exporter.implementation.utils.AzureMonitorMsgId.INGESTION_ERROR; +import static java.util.Collections.singleton; import com.azure.monitor.opentelemetry.exporter.implementation.pipeline.TelemetryPipeline; import com.azure.monitor.opentelemetry.exporter.implementation.pipeline.TelemetryPipelineListener; @@ -66,13 +67,12 @@ public void onResponse(TelemetryPipelineRequest request, TelemetryPipelineRespon break; case 206: // PARTIAL CONTENT, Breeze-specific: PARTIAL SUCCESS case 400: // breeze returns if json content is bad (e.g. missing required field) - operationLogger.recordFailure( - "Received response code " - + responseCode - + " (" - + getErrorMessageFromPartialSuccessResponse(response.getBody()) - + ")", - INGESTION_ERROR); + Set errors = getErrors(response.getBody()); + if (!errors.isEmpty()) { + operationLogger.recordFailure( + "Received response code " + responseCode + " (" + String.join(", ", errors) + ")", + INGESTION_ERROR); + } break; case 307: case 308: @@ -126,21 +126,20 @@ public CompletableResultCode shutdown() { return CompletableResultCode.ofSuccess(); } - private static String getErrorMessageFromPartialSuccessResponse(String body) { + private static Set getErrors(String body) { JsonNode jsonNode; try { jsonNode = new ObjectMapper().readTree(body); } catch (JsonProcessingException e) { // fallback to generic message - return "Could not parse response"; + return singleton("Could not parse response"); } List errorNodes = new ArrayList<>(); jsonNode.get("errors").forEach(errorNodes::add); - Set errors = - errorNodes.stream() - .map(errorNode -> errorNode.get("message").asText()) - .collect(Collectors.toSet()); - return String.join(", ", errors); + return errorNodes.stream() + .map(errorNode -> errorNode.get("message").asText()) + .filter(s -> !s.equals("Telemetry sampled out.")) + .collect(Collectors.toSet()); } private static String getErrorMessageFromCredentialRelatedResponse(