ravendb/ravendb — Issue #449: RavenProfiler is not capturing session data
Author: ArnoldZokas
Created: 2012-01-24 16:15:39+00:00
State: open

I am trying to integrate RavenProfiler into an existing ASP.NET MVC3 project, but for some reason I am not seeing any information. The profiler simply shows: "*0 ms waiting for server in 0 request(s) for 0 sessions(s)*".

I considered the possibility that there is some conflicting code in my project, so I carried out a basic test:

* I have created a new project using ASP.NET MVC3 Empty Application template
* Added package 1.0.606-Unstable via NuGet
* Using [RacoonBlog](https://github.com/ayende/RaccoonBlog/blob/master/RaccoonBlog.Web/Global.asax.cs) as an example, I added the following code to `Global.asax.cs`:

```c#
public class MvcApplication : HttpApplication
{
public MvcApplication()
{
BeginRequest += (sender, args) =>
{
HttpContext.Current.Items["CurrentRequestRavenSession"] = DocumentStore.OpenSession();
};
EndRequest += (sender, args) =>
{
using (var session = (IDocumentSession)HttpContext.Current.Items["CurrentRequestRavenSession"])
{
if (session == null)
return;

if (Server.GetLastError() != null)
return;

session.SaveChanges();
}
};
}

public static EmbeddableDocumentStore DocumentStore { get; set; }

protected void Application_Start()
{
// other initialisation code, etc...

DocumentStore = new EmbeddableDocumentStore
{
DataDirectory = "App_Data/RavenDb"
};
DocumentStore.Initialize();

RavenProfiler.InitializeFor(DocumentStore);
}
}
```
* Added RavenProfiler method call to `

` section:

```c#

@Raven.Client.MvcIntegration.RavenProfiler.CurrentRequestSessions()

```

* Added test code to MVC action:

```c#
public ActionResult Index()
{
var session = (IDocumentSession)HttpContext.Items["CurrentRequestRavenSession"];
session.Store(new Test { Name = "Text 1" });

HttpContext.Response.Write("
" + session.Query().Count());

return View();
}
```

The profiler is still showing "*0 ms waiting for server in 0 request(s) for 0 sessions(s)*".

Does the profiler rely on some architectural pattern? Am I missing some initialisation code somewhere?