How to replace OperationContext in new V12 SDK Azure.Storage.Blobs

Becker, W 66 Reputation points
2024-06-04T11:18:12.8033333+00:00

I'm switching from Microsoft.WindowsAzure.Storage to Azure.Storage.Blobs. In the former versions I could log retries, this seems to be missing in the new SDK. I used OperationContext for this:

 var context = new OperationContext();
        context.ClientRequestID = myid; //"some request id";
        context.Retrying += (sender, args) =>
        {
            int retryCnt = context.RequestResults.Count;               
            ErrorMessage("Upload failed. Start Retry " + retryCnt + " for BLOB: " + blobName, myid);
        };

        // define action when request is completed -> the request is also completed when the upload failed
        context.RequestCompleted += (sender, args) =>
        {
            /* Collect operation completion information */
            if (args.Response != null)
            {
                DebugMessage("Upload completed for BLOB " + blobName, myid);
            }
            else
            {
                int retryCnt = context.RequestResults.Count - 1;
                ErrorMessage("Upload failed (Retry " + retryCnt + ") for BLOB " + blobName, myid);
            }
        };

What is the equivalent in Azure.Storage.Blobs? How can I log my retries?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,869 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,874 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,578 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,579 questions
0 comments No comments
{count} votes

Accepted answer
  1. Nehruji R 4,216 Reputation points Microsoft Vendor
    2024-06-05T06:20:57.0433333+00:00

    Hello Becker, W,

    Greetings! Welcome to Microsoft Q&A Platform.

    The Microsoft.WindowsAzure.Storage package is deprecated, and although it still works, it’s recommended to move to the newer Azure.Storage.Blobs package. The newer package offers better performance, updates, feature releases, and continued support. In the newer Azure.Storage.Blobs SDK (v12), the concept of OperationContext has been removed. However, you can still achieve similar retry logging functionality without using OperationContext.

    Instead of OperationContext, you can set up a custom retry policy for your blob operations. Retry policies define how your application handles failed requests. The SDK provides built-in retry policies, but you can create your own custom policy to log retries.

    For example, you can set the maximum number of retries and the delay between retries.

    refer similar thread for reference - https://stackoverflow.com/questions/77584911/log-retries-in-azure-storage-blob

    To correlate request IDs and log retries, use the Context and PipelineCallContext. The Context is thread-safe and can be passed to API calls that accept it. The PipelineCallContext provides additional context information during retries.

    Hope this answer helps! Please let us know if you have any further queries. I’m happy to assist you further.


    Please "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful