public void EndRequest(Object source, EventArgs e)
{
var application = (HttpApplication) source;
var httpContext = application.Context;
if (!httpContext.Items.Contains(ContextItemKey))
{
Logger(GraphdatLogType.ErrorMessage, null, "Graphdat API not found in HttpContext.");
return;
}
var graphdat = httpContext.Items[ContextItemKey] as API;
if (graphdat == null)
{
Logger(GraphdatLogType.ErrorMessage, null, "Graphdat API not found (incorrect type) in HttpContext.");
return;
}
API.Timer rootTimer;
if(!graphdat.Context.Validate())
{
if (!Properties.Settings.Default.Suppress_ContextPopAutomatic) Logger(GraphdatLogType.WarningMessage, null, "Popping context automatically, you have not ended each context you created, this might be an error (you can suppress this warning: Suppress_ContextPopAutomatic).");
rootTimer = graphdat.Context.Exit();
}
else
{
rootTimer = graphdat.Context.Done();
}
// Complete the timing
var context = graphdat.Context.Flatten(build);
// Send the sample
var contexts = context.Select((dynamic obj) => new Context {
Name = obj.Name,
Timestamp = obj.Timestamp,
ResponseTime = obj.ResponseTime,
CpuTime = obj.CpuTime,
CallCount = GetCallCount(context, obj.Name)
});
var sample = new Sample {
Method = httpContext.Request.HttpMethod,
Uri = httpContext.Request.Url.AbsoluteUri,
Host = httpContext.Request.Url.Host,
Timestamp = rootTimer.Timestamp,
ResponseTime = rootTimer.Milliseconds,
CpuTime = 0,
Context = contexts.ToArray()
};
_agentConnect.Store(sample, Logger);
}