Recently I had been assigned the task of implementing MiniProfiler to our .Net application.

My team was particularly interested in profiling database queries to be able to provide historical analysis for some of our database-heavy pages.

Of course, Miniprofiler is great at what it does, but for storing information about the profiled data in sql, the “built-in” sql storage class was a bit lacking for us. It can be found on Github here. It expects a couple of tables to exist on the [dbo] schema in the database, and rights some SELECT and INSERT statements from the results that the miniprofiler timing events provide.

So, I had the controversial idea to create our own custom version of this class, that also inherited from the base DatabaseStorage class, but we altered our methods to run on a new [Profile] schema, and even modified the functions to insert ADDITIONAL data in a new column. This is great for when you want to incorporate database storage, but you want to store additional user data, page data, or anything else, in a unique column, we’re going to go with json format for this.

You can basically copy all of the code form sql storage, and then modify the inserts to include the new data into a new column in the table, or add the schema before the table names for putting the tables in a separate schema like we did.

All in all it was good fun, and we will then be scooping this data on a nightly ETL run to put into something like Elasticsearch for building a dashboard out of with Kibana.