thrzn41/WebexTeamsAPIClient

Guid(Transaction Id) per request even there are retries

thrzn41 opened this issue · 1 comments

For logging in apps,
it is better that there are consistent Guid per request even there are retries.

Code snippet for this enhancement:

// RetryExecutor.One requests with 1 time retry at most.
var result = await RetryExecutor.One.ListAsync(
  () =>
  {
      // This function will be executed again if needed.
      return teams.ListSpacesAsync();
  },

  (r, retryCount) =>
  {
      // This function will be executed before evry retry request.

      // You can output logs or other things at this point.
      Log.Info("Retry is required: delta = {0}, counter = {1}, guid = {2}", r.RetryAfter.Delta, retryCount, r.Guid);

      // Return 'true' when you want to proceed retry.
      return true;
  }
);
  
  // the Guid is the same as logging on a retry.
  Log.Info("guid = {0}",result.Guid);

Released at 1.6.1( #27 ).

result.TransactionId for any result and result.ListTransactionId for list result.

Code snippet(TransactionId):

// Creates API Client instance with retry option and it's notification func.
var teams = TeamsAPI.CreateVersion1Client(protectedToken, 
        new TeamsRetryHandler(4), 
        (r, retryCount) =>
        {
            // This function will be executed before evry retry request.

            // You can output logs or other things at this point.
           Log.Info("Retry is required: delay = {0}, counter = {1}, guid = {2}", r.TimeToRetry, retryCount, r.TransactionId);

            // Return 'true' when you want to proceed retry.
            return true;
        }
    );


var r = await teams.ListSpacesAsync();

// the TransactionId is the same as logging on a retry.
Log.Info("TransactionId = {0}", r.TransactionId);

Code snippet(ListTransactionId):

var e = (await teams.ListSpaceAsync()).GetListResultEnumerator();

while(await e.MoveNextAsync())
{
    var r = e.CurrentResult;

    // Each ListTransactionIds are the same.
    Log.Info("ListTransactionId = {0}", r.ListTransactionId);
}