Skip to content

Commit

Permalink
Suppress ingestion sampling warnings (#2473)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Aug 30, 2022
1 parent f8137a7 commit a1fd5df
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> errors = getErrors(response.getBody());
if (!errors.isEmpty()) {
operationLogger.recordFailure(
"Received response code " + responseCode + " (" + String.join(", ", errors) + ")",
INGESTION_ERROR);
}
break;
case 307:
case 308:
Expand Down Expand Up @@ -126,21 +126,20 @@ public CompletableResultCode shutdown() {
return CompletableResultCode.ofSuccess();
}

private static String getErrorMessageFromPartialSuccessResponse(String body) {
private static Set<String> 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<JsonNode> errorNodes = new ArrayList<>();
jsonNode.get("errors").forEach(errorNodes::add);
Set<String> 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(
Expand Down

0 comments on commit a1fd5df

Please sign in to comment.