Probles with Activity Sampling in Semmantic Logging

Topics: Semantic Logging Application Block
Apr 29, 2014 at 6:02 PM
Hello,

I am trying to both understand and make it work the example related with activity logging showed in this post https://slab.codeplex.com/wikipage?title=ActivityTracingAndSampling

I am developing an WebApi application where I have created a filter where I set the current thread activity Id with the request correlation id which gives me a relation between the current request and all the traces generated by all sources in my application.

This is kind of working for me (any issues with this?) but when I start generating async code mainly because of the use of EF6 then I loose track of the request. I read then the post and it seems to be what I was looking for.

If I enable the System.Threading.Tasks.TplEventSource it trully generates thousands of messages all the time so I wanted to do the sampling thing described in the post.

I execute on the Application Start the exact code you described in the post with the exception that I am using 1 instead of the value TransfersOnly (which I concluded from here http://referencesource.microsoft.com/#mscorlib/system/threading/Tasks/TPLETWProvider.cs) because of compilation error. But sampling does not seem to be working and I get in the database (I am using a database sink all messages in every request and even when I am not doing requests???)

My idea, if I am able, is to create a filter in ASP.NET that if the request has a query string like debug=true activate the sampling, but I am pretty lost on how to achieve that and I was not lucky in my searches.

Any help would be highly appreciated. Thanks for your time and your effort.
public static void Start()
        {            
            var connectionString = @"Data Source=(LocalDB)\v11.0;Integrated Security=SSPI;Initial Catalog=xxxxx-db";
            var sqlDatabaseListener = SqlDatabaseLog.CreateListener
            (
                instanceName: "Xxxxx",
                connectionString: connectionString,
                tableName: "Traces",
                bufferingCount: 1 //this is clearly for developments options only...
            );

            EventSourceAnalyzer.InspectAll(SeedworkEventSource.Log);
            EventSourceAnalyzer.InspectAll(CoreEventSource.Log);
            EventSourceAnalyzer.InspectAll(LogisticsEventSource.Log);

            sqlDatabaseListener.EnableEvents(SeedworkEventSource.Log, EventLevel.LogAlways, Keywords.All);
            sqlDatabaseListener.EnableEvents(CoreEventSource.Log, EventLevel.LogAlways, Keywords.All);
            sqlDatabaseListener.EnableEvents(LogisticsEventSource.Log, EventLevel.LogAlways, Keywords.All);

            sqlDatabaseListener.EnableEvents
            (
                "Microsoft-Windows-ASPNET",
                EventLevel.Informational,
                EventKeywords.None,
                new Dictionary<string, string> 
                { 
                    { "ActivitySamplingStartEvent", "RequestStarted:10" } 
                }
            );

            sqlDatabaseListener.EnableEvents
            (
                "System.Threading.Tasks.TplEventSource", 
                EventLevel.Informational, 
                (EventKeywords)1,
                new Dictionary<string, string> 
                { 
                    { "ActivitySampling", "true" } 
                }
            );
        }