I have thought about the problem some and have some very concrete suggestions on various design issues that I will outline here. We should meet on Monday to go over them. I am getting pretty happy with the design I am outlining below. THere is working code in my fork under the Work.1-2 branch
https://github.com/vancem/correlation/tree/Work.1-2
which I have submitted as a pull request in case that is more convenient.
#6
Short term long term: First I will describe the design I want if we can modify everything wherever it lives. There are work-arounds (along the lines of your use of DiagnosticSource to hook System.Net.Http) that I will describe last, but don't let that perturb the better design.
General Architecture: First there is a general mismatch between OpenTracing (which does both logging and correlation, and assumes only one kind of tracing API), and what we need (which is a generic correlation mechanism that can be used for several (three) logging libraries we have. My general resolution for this is
- Make believe we only are instrumenting library code with DiagnosticSource and design Activities to be first and foremost good for that case. Basically make DiagnosticSource + Activities have the functionality of OpenTracing. Note that this works well because I believe we can keep the coupling low, AND all other loggers can be built 'on top'.
1A) Thus at places where we do diagnosticSource.Write("XXXStart", args), we also (right before it) start the activity ActivityStart("XXX"), and similarly call ActivityStop("XXX") right after the Write("XXXStop"). I have helpers that do this that should go into DiagnosicSource.
2) Since DiagnosticSource is always in-proc, when people need the information they can get it from Activity.Current. This makes things reasonably decoupled.
3) The general dependency is that loggers can depend on Activity but not the other way around. Thus DiagnosticSource can depend on Activity.
4) I think Activity can simply live in the Microsoft.Diagnostic.DiagnosticSource.dll, and the class will live in the System.Diagnostic namespace. We may wish to rename it 'DiagnosticActivity' but I could live with either (I note that things like Process, and Thread are not called 'DiagnosticProcess' or 'DiagnosticThread', so there is precedent for calling it just 'Activity'.
5) What is nice about this is that filtering 'falls out' in the sense that DiagnosticSource has a filtering mechanism and we just piggy-back on that. Thus when "XXXStart" events are on, you get the activity tracking as well, but otherwise not (thus it is fine-grained).
6) Because we generally will be logging a DiagnosticSource event on starts and stops, we may not need the C# events on Activity. We also don't in theory need start time duration or tags, but I am thinking we will keep those (to encourage uniformity).
ILogger things will be built completely on TOP of the DiagnosticSource events (thus ILogger depends on DiagnosticSource.dll. My expectation is that we would create two NEW ILogger that will log start and stop events with ILogger at HTTP incomming and Outgoing events, using DiagnosticSource to get the hooks. For incomming HTTP, this code can go into Microsoft.AspNetCore.Http since they already probably have a dependency on ILogger, but for System.Net.Http, it can't go there. It will go into its own DLL probably. (however I really want this to be on by default so I would prefer to 'attach' to a DLL that is already likely to be used in most cases).
As always, this probably brings up more questions than answers. We can talk on Tuesday.