Add country tag to twilio failures

This commit is contained in:
Ravi Khadiwala 2022-09-29 10:13:40 -05:00 committed by ravi-signal
parent 6e595a0959
commit c82c2c0ba4
2 changed files with 16 additions and 4 deletions

View File

@ -60,6 +60,8 @@ public class TwilioSmsSender {
static final String SERVICE_NAME_TAG = "service"; static final String SERVICE_NAME_TAG = "service";
static final String STATUS_CODE_TAG_NAME = "statusCode"; static final String STATUS_CODE_TAG_NAME = "statusCode";
static final String ERROR_CODE_TAG_NAME = "errorCode"; static final String ERROR_CODE_TAG_NAME = "errorCode";
static final String COUNTRY_CODE_TAG_NAME = "countryCode";
static final String REGION_TAG_NAME = "region";
private final String accountId; private final String accountId;
private final String accountToken; private final String accountToken;
@ -213,14 +215,19 @@ public class TwilioSmsSender {
return true; return true;
} else if (response != null && response.isFailure()) { } else if (response != null && response.isFailure()) {
String countryCode = Util.getCountryCode(destination);
String region = Util.getRegion(destination);
Metrics.counter(FAILED_REQUEST_COUNTER_NAME, Metrics.counter(FAILED_REQUEST_COUNTER_NAME,
SERVICE_NAME_TAG, "classic", SERVICE_NAME_TAG, "classic",
STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status), STATUS_CODE_TAG_NAME, String.valueOf(response.failureResponse.status),
ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code)).increment(); ERROR_CODE_TAG_NAME, String.valueOf(response.failureResponse.code),
COUNTRY_CODE_TAG_NAME, countryCode,
REGION_TAG_NAME, region).increment();
logger.info("Failed with code={}, country={}", logger.info("Failed with code={}, country={}",
response.failureResponse.code, response.failureResponse.code,
Util.getCountryCode(destination)); countryCode);
return false; return false;
} else if (throwable != null) { } else if (throwable != null) {

View File

@ -157,14 +157,19 @@ class TwilioVerifySender {
} }
if (twilioVerifyResponse.isFailure()) { if (twilioVerifyResponse.isFailure()) {
String countryCode = Util.getCountryCode(destination);
String region = Util.getRegion(destination);
Metrics.counter(TwilioSmsSender.FAILED_REQUEST_COUNTER_NAME, Metrics.counter(TwilioSmsSender.FAILED_REQUEST_COUNTER_NAME,
TwilioSmsSender.SERVICE_NAME_TAG, "verify", TwilioSmsSender.SERVICE_NAME_TAG, "verify",
TwilioSmsSender.STATUS_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.status), TwilioSmsSender.STATUS_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.status),
TwilioSmsSender.ERROR_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.code)).increment(); TwilioSmsSender.ERROR_CODE_TAG_NAME, String.valueOf(twilioVerifyResponse.failureResponse.code),
TwilioSmsSender.COUNTRY_CODE_TAG_NAME, countryCode,
TwilioSmsSender.REGION_TAG_NAME, region).increment();
logger.info("Failed with code={}, country={}", logger.info("Failed with code={}, country={}",
twilioVerifyResponse.failureResponse.code, twilioVerifyResponse.failureResponse.code,
Util.getCountryCode(destination)); countryCode);
return Optional.empty(); return Optional.empty();
} }