question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Am I still able to intercept exceptions on retry to emit client side metrics?

See original GitHub issue

Describe the issue

In v1 I was able to add a lambda to intercept exceptions in client and emit metrics if desired, I’m struggling to do the same with v2.

import com.amazonaws.retry.PredefinedRetryPolicies;
import com.amazonaws.retry.RetryPolicy;

  private RetryPolicy buildRetryPolicy() {
    return new RetryPolicy(
        (originalRequest, exception, retriesAttempted) -> {
          LOGGER.info("AWS failed with exception {}", exception.getClass());
          if (exception instanceof ProvisionedThroughputExceededException) {
            metrics.getCounter(PROVIDER_EXCEPTION,Map.of("exception", "ProvisionedThroughputExceededException")).inc();
          }
          return PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(
              originalRequest, exception, retriesAttempted);
        },
        PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY,
        PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY,
        false);
  }

Your Environment

  • AWS Java SDK version used: ‘2.15.26’
  • JDK version used: 11
  • Operating System and version: N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
debora-itocommented, Nov 18, 2020
return RetryCondition.defaultRetryCondition().shouldRetry(RetryPolicyContext.builder().build());

Let us know if this would help.

0reactions
kevinrobaynacommented, Nov 19, 2020

Thanks! that worked. For anyone who reads this in the future.

            RetryPolicy.defaultRetryPolicy().toBuilder()
                .retryCondition(
                    retryPolicyContext -> {
                      LOGGER.info("AWS failed with exception {}", retryPolicyContext.getClass());
                      // send metrics
                      return RetryCondition.defaultRetryCondition().shouldRetry(retryPolicyContext);
                    })
                .build())
Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing Retry Throttling | AWS Developer Tools Blog
Client side retries are used to avoid surfacing unnecessary exceptions back to the caller in the case of transient network or service issues ......
Read more >
Azure Application Insights for JavaScript web apps
As a result, distributed tracing is incomplete until the SDK fully initializes. To remedy this problem, you can include dynamic JavaScript on ...
Read more >
Node.js Best Practice Exception Handling - Stack Overflow
This gotcha is very easy to do as your code becomes more complex. As such, it is best to either use domains or...
Read more >
Error Handling in Large .NET Projects - Best Practices
Hiding errors silently is only appropriate in very specific scenarios, for example to catch exceptions thrown when attempting to log an error in ......
Read more >
Let's Rebuild AWS EC2 (Part 1). Looking deeper into some of the ...
This is not possible if retries do not return the same reservation id. ... fails with a ConditionalCheckFailedException (only catch this specific exception, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found