Navid Molavi
Navid Molavi

Reputation: 93

How to access a query "Query Execution Metrics" in Cosmos db .NET Core SDK V3

I am running a query against an Azure Cosmos db and I need to know the total number of retrieved documents regardless of the pagination. Running a Count query against the actual query without the pagination could be very heavy if the number retrieved documents are huge.

In the bellow link it is described how to access to a query "Query Execution Metrics" in Cosmos db .NET SDK V2, I appreciated if someone guide me how to do it using the SDK V3.

https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-query-metrics

Upvotes: 1

Views: 2357

Answers (1)

PerfectlyPanda
PerfectlyPanda

Reputation: 3466

Version 3.2.0 of the SDK that was released yesterday addresses this issue. Instead of asking for the metrics, they are included in every query. You can access them through ResponseMessage.Diagnostics.

The usage is probably easiest to see by looking at the SDK's tests:

((QueryOperationStatistics)responseMessage.Diagnostics)
   .queryMetrics
   .Values
   .First()
   .RetrievedDocumentCount

You can see the full list of properties in the QueryMetrics definition: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/2cdcde1b747db59721ede152fc9b5aa87fc62dd4/Microsoft.Azure.Cosmos/src/Query/Core/QueryMetrics/QueryMetrics.cs

Upvotes: 8

Related Questions