Search code examples
.netazure-cosmosdb

How to measure RUs when executing CreateItemStreamAsync()?


How to measure consumed RUs in Azure Cosmos DB when creating a new item using .Net SDK v3's CreateItemStreamAsync()?

Unlike available Microsoft documentation for non stream alternatives, this one does not return RequestCharge property.

Anyone has any idea?


Solution

  • Stream APIs return the raw service response, they expose the service headers in ResponseMessage.Headers.

    Request Charge is a response header: x-ms-request-charge.

    This is available as a promoted property in the Headers type.

    ResponseMessage response = await container.CreateItemStreamAsync(...);
    
    double ruCharge = response.Headers.RequestCharge;