Record error metrics from Twilio Verify

This commit is contained in:
Jon Chambers 2021-08-26 11:43:40 -04:00 committed by Jon Chambers
parent aeb9f67266
commit 8a8a848fac
2 changed files with 17 additions and 4 deletions

View File

@ -55,9 +55,10 @@ public class TwilioSmsSender {
private final Meter voxMeter = metricRegistry.meter(name(getClass(), "vox", "delivered"));
private final Meter priceMeter = metricRegistry.meter(name(getClass(), "price"));
private static final String FAILED_REQUEST_COUNTER_NAME = name(TwilioSmsSender.class, "failedRequest");
private static final String STATUS_CODE_TAG_NAME = "statusCode";
private static final String ERROR_CODE_TAG_NAME = "errorCode";
static final String FAILED_REQUEST_COUNTER_NAME = name(TwilioSmsSender.class, "failedRequest");
static final String SERVICE_NAME_TAG = "service";
static final String STATUS_CODE_TAG_NAME = "statusCode";
static final String ERROR_CODE_TAG_NAME = "errorCode";
private final String accountId;
private final String accountToken;
@ -206,7 +207,12 @@ public class TwilioSmsSender {
return true;
} else if (response != null && response.isFailure()) {
logger.debug("Twilio request failed: " + response.failureResponse.status + "(code " + response.failureResponse.code + "), " + response.failureResponse.message);
Metrics.counter(FAILED_REQUEST_COUNTER_NAME, STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status), ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code)).increment();
Metrics.counter(FAILED_REQUEST_COUNTER_NAME,
SERVICE_NAME_TAG, "classic",
STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status),
ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code)).increment();
return false;
} else if (throwable != null) {
logger.info("Twilio request failed", throwable);

View File

@ -15,6 +15,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import javax.validation.constraints.NotEmpty;
import io.micrometer.core.instrument.Metrics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.configuration.TwilioConfiguration;
@ -137,10 +138,16 @@ class TwilioVerifySender {
private Optional<String> extractVerifySid(TwilioVerifyResponse twilioVerifyResponse, Throwable throwable) {
if (throwable != null) {
logger.warn("Failed to send Twilio request", throwable);
return Optional.empty();
}
if (twilioVerifyResponse.isFailure()) {
Metrics.counter(TwilioSmsSender.FAILED_REQUEST_COUNTER_NAME,
TwilioSmsSender.SERVICE_NAME_TAG, "verify",
TwilioSmsSender.STATUS_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.status),
TwilioSmsSender.ERROR_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.code)).increment();
return Optional.empty();
}