Home > OS >  Cosmos SDK v3 does not log document creation
Cosmos SDK v3 does not log document creation

Time:10-21

I have a .NET 6 application that uses the v3 Cosmos SDK to write data to a container.

When I set the application-wide default logging level to Information, I see GET requests from the Comsos SDK like the following:

[09:41:17 INF] Start processing HTTP request GET https://127.0.0.1:8081/dbs/requeststore/colls/orchestrationrequest
[09:41:17 INF] Sending HTTP request GET https://127.0.0.1:8081/dbs/requeststore/colls/orchestrationrequest
[09:41:17 INF] Received HTTP response headers after 33.8561ms - 200
[09:41:17 INF] End processing HTTP request after 44.5824ms - 200

I do not see any logging around document creation, even though I can see that my data was successfully persisted.

Edit: Could this be related to the RNTBD protocol that Cosmos uses? So the GET requests get the information required in order to send data to the container and than an RTNBD connection is established? It would be good to be able to have some logging around it.

Edit 2: I was able to get the trace listener to write the data to the console with the following code:

Type defaultTrace = Type.GetType("Microsoft.Azure.Cosmos.Core.Trace.DefaultTrace,Microsoft.Azure.Cosmos.Direct");
TraceSource traceSource = (TraceSource)defaultTrace.GetProperty("TraceSource").GetValue(null);
var consoleTrance = new ConsoleTraceListener();
traceSource.Listeners.Add(consoleTrance);

CodePudding user response:

If what you are using to log automatically detects and logs HTTP requests (like Application Insights), then yes, it makes sense that the Data Plane operations (such as creating an item) are not logged.

There are 2 Connection Modes, and V3 SDK defaults to Direct: https://docs.microsoft.com/azure/cosmos-db/sql-sdk-connection-modes

On Direct mode, it is expected to see some HTTP interactions (for routing https://learn.microsoft.com/azure/cosmos-db/nosql/sdk-connection-modes#routing).

The SDK exposes Diagnostics for each operation which includes information like the complete latency/time and are useful for troubleshooting: https://learn.microsoft.com/azure/cosmos-db/nosql/troubleshoot-dotnet-sdk#capture-diagnostics

The SDK also exposes Traces, so you can define a Trace Listener, but that will contain a lot of event information (not only establishing connections and sending requests).

  • Related