Traces are emitted with DocDBTrace source. Below sample app.config configuration captures the traces to a text listener
<system.diagnostics>
<switches>
<add name="ClientSwitch" value="Verbose"/>
</switches>
<sources>
<source name="DocDBTrace" switchName="ClientSwitch" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<add name="MyTextListener" type="System.Diagnostics.TextWriterTraceListener" traceOutputOptions="DateTime,ProcessId,ThreadId" initializeData="CosmosDBTrace.txt"></add>
< /listeners>
</source>
</sources>
</system.diagnostics>
Please note that tracing everything will impact the application performance. Be selective and is possible collect them only when required.
The Azure Cosmos DB .NET SDK (from version 1.11.0) support capturing trace in ETL trace log file. The trace is emitted and captured using Windows ETW with very little overhead.
- Download Perfview tool at https://www.microsoft.com/en-us/download/details.aspx?id=28567
- In Windows command prompt:
perfview.exe /onlyproviders=B30ABF1C-6A50-4F2B-85C4-61823ED6CF24:*:0 collect
- When it is done, click “Stop Collection” button. “PerviewData.etl.zip” will be generated in the current directory.
- To view the trace, double Click the PerviewData.etl.zip, go to Events, and look for "Providers/B30ABF1C-6A50-4F2B-85C4-61823ED6CF24"
- In Windows command prompt:
perfview.exe UserCommand Listen B30ABF1C-6A50-4F2B-85C4-61823ED6CF24:*:0
- In Windows command prompt:
logman create trace cosmosdbclienttrace -rt -nb 500 500 -bs 40 -p {B30ABF1C-6A50-4F2B-85C4-61823ED6CF24} -o cosmosdbclient.etl -ft 10
- When you are ready to collect trace:
logman start cosmosdbclienttrace
- When finish collecting:
logman stop cosmosdbclienttrace
- You should see cosmosdbclientxxx.etl in current directory.
- Download the svcperf at https://svcperf.codeplex.com/
- Open svcperf.exe.
- In "Manifests|Add", add the ClientEvents.man found in this folder with this
- Open the etl file you have captured, you might need to hit F5 to refresh it.
By default DefaultTraceListener is included and also not threadsafe (more overhead). To remove DefaultTraceListener please use below configurationo on app.config
<configuration>
<system.diagnostics>
<sources>
<source name="DocDBTrace" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
<listeners>
<clear/>
</listeners>
</source>
</sources>
</system.diagnostics>
<configuration>