Getting Started
Using the Cosmos DB Profiler is easy. First, we need to make the application that we profile aware of the profiler. Then, just start the profiler.
Preparing an application to be profiled
Install CosmosDBProfiler NuGet package (or CosmosDBProfiler.Appender to install only the profiler's Appender):
Install-Package CosmosDBProfiler -IncludePrerelease
In the application startup (Application_Start
in web applications, Program.Main
in console applications, or the App constructor for WPF applications), make the following call:
HibernatingRhinos.Profiler.Appender.CosmosDB.CosmosDBProfiler.Initialize(cosmosClient); // cosmosClient is CosmosClient or DocumentClient instance
ASP.NET Core app
In ASP.NET Core application please use UseCosmosDBProfiler()
extension method available for .NET Core projects to initialize profiling (you'll find it in HibernatingRhinos.Profiler.Appender.CosmosDB
namespace):
using HibernatingRhinos.Profiler.Appender.CosmosDB;
public void ConfigureServices(IServiceCollection services)
{
services.UseCosmosDBProfiler(cosmosClient);
}
Under the covers, in addition to intializing the profiling by calling CosmosDBProfiler.Initialize(cosmosClient)
, it will also register a default implementation of IHttpContextAccessor
helper service by calling services.AddHttpContextAccessor()
. It provides access to the current HttpContext
in ASP.NET Core applications. This way the profiler is able to correlate outgoing requests to CosmosDB with a URL address of a controller method which sent it.