Search code examples
c#azure-cosmosdb

How to verify which region current Cosmos client is connected to?


https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/tutorial-global-distribution?tabs=dotnetv3%2Capi-async#net-sdk

The current write and read endpoints are available in DocumentClient.WriteEndpoint and DocumentClient.ReadEndpoint respectively.

How to check from the CosmosClient instead? As giving in the example. I assume the DocumentClient is outdated in V3


Solution

  • Each operation you perform with the CosmosClient returns a response that contains a Diagnostics property. The Diagnostics contains a GetContactedRegions() method that returns the regions were involved in this operation: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/ebd1b91a26547721ef232ef597d878144889b80b/Microsoft.Azure.Cosmos/src/Diagnostics/CosmosDiagnostics.cs#L83

    Each operation for different reasons might contact one or more regions.