0

I am using MiniProfiler to monitor request to external APIs using CustomTimings :

var externalApiClient = new ExternalApiClient();
using(MiniProfiler.Current.CustomTiming("ExternalAPI","ExternalAPI.Method"))
{
    externalApiClient.Method();
}

This works well, but I would like to add more data like status codes, result counts... I haven't found anything built-in that would allow me to do this.

Have I missed something? What would be the best way? I could create a new class inheriting from CustomTiming, but looking at the code, I fear this would not be reliable in the long run (with things like [DataMember(Order = 8)]).

Damien Chaib
  • 401
  • 3
  • 14

1 Answers1

0

One place that you can add information to is a command string itself:

using (CustomTiming ct = MiniProfiler.Current.CustomTiming("http", "GET http://foo.bar"))
{
    var response = await http.GetAsync("http://foo.bar");
    var bytes = (await response.Content.ReadAsByteArrayAsync()).Length;

    // Command string will look like "GET http://foo.bar OK 50301[B]"
    ct.CommandString = string.Format("{0} {1} {2}[B]", ct.CommandString, 
                                     response.StatusCode, bytes);
}
Leonid Vasilev
  • 11,910
  • 4
  • 36
  • 50