csainty / Glimpse.RavenDb

RavenDb Profiling plugin for Glimpse
http://csainty.github.com/Glimpse.RavenDb
MIT License
8 stars 9 forks source link

Issue with running IDocumentSessions in the background of an ASP.NET #7

Open brunomlopes opened 10 years ago

brunomlopes commented 10 years ago

I've been running this plugin on a web app which now runs some tasks in the background via Quartz.Net.

The tasks' dependencies are injected from our IoC container, and one the dependencies is a IDocumentSession. Since these tasks run in the background there is no http context, and opening a session crashes with the following stack trace:

System.NullReferenceException: Object reference not set to an instance of an object. at Glimpse.AspNet.AspNetFrameworkProvider.get_HttpRequestStore() at Glimpse.Core.Framework.Factory.<>cDisplayClass2.b1() at Glimpse.RavenDb.Profiler.PointOnTimeline(String message) in c:\Projects\Glimpse.RavenDb\Glimpse.RavenDb\Profiler.cs:line 107 at Glimpse.RavenDb.Profiler.TrackSession(InMemoryDocumentSessionOperations session) in c:\Projects\Glimpse.RavenDb\Glimpse.RavenDb\Profiler.cs:line 86 at Raven.Client.DocumentStoreBase.AfterSessionCreated(InMemoryDocumentSessionOperations session) at Raven.Client.Document.DocumentStore.AfterSessionCreated(InMemoryDocumentSessionOperations session) at Raven.Client.Document.DocumentStore.OpenSession(OpenSessionOptions options) at Raven.Client.Document.DocumentStore.OpenSession()

My expectation would be for glimpse to be "mute" when running outside of an http request, and I'd very much would like to avoid having to set another document store with no profiling just for the background tasks.

Is this a bug? Is there a way to avoid this and keep the profiler set up?

soledadtctvtn commented 9 years ago

I'm facing this issue on Glimpse.MVC4 too, but not good solution found yet. Below are my environment:

gregolsky commented 8 years ago

Due to this issue, I decided to initialize a separate DocumentStore object for my background jobs.