1

I have many collections in Cosmos DB (SQL API) and many services using the same database. 100s of query executing every minute, Sometimes I can see RU exceeding warning. I know all query is not optimized in all the application.

Is there any way to get all queries and execution time (like SQL server Profiler Trace)?

I tried to enable Cosmos DB Diagnostic Settings, but didn't get any way to trace queries

1

1 Answer 1

1

The way you would have to go about it is enabling PopulateQueryMetrics in the SDK.

Ones enabled your queries will have the x-ms-documentdb-query-metrics header populated. The value looks like this:

totalExecutionTimeInMs=33.67;queryCompileTimeInMs=0.06;queryLogicalPlanBuildTimeInMs=0.02;queryPhysicalPlanBuildTimeInMs=0.10;queryOptimizationTimeInMs=0.00;VMExecutionTimeInMs=32.56;indexLookupTimeInMs=0.36;documentLoadTimeInMs=9.58;systemFunctionExecuteTimeInMs=0.00;userFunctionExecuteTimeInMs=0.00;retrievedDocumentCount=2000;retrievedDocumentSize=1125600;outputDocumentCount=2000;writeOutputTimeInMs=18.10;indexUtilizationRatio=1.00

As you can see this needs be to split and parsed but it has a lot of useful info which you can log and query to see a lot of stuff about your queries and their performance.

You can read more about query metrics here: https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-query-metrics

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, I'm aware of these details. Currently, We have 10+ Microservices and by going this approach I have to change all application data access layer and write custom code to log query and execution metrics.
Well this is the only option that you really have. If you really need them you need to add them. It is highly recommended to have have dependency logging anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.