-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the intended use pattern of RelationalDiagnosticSource* messages? #7939
Comments
As an example of why private static SomeType _type = new SomeType
{
Foo = nameof(SomeType.Foo),
Foo2 = nameof(SomeType.Foo2),
Conn = new DbConn
{
Name = "Test",
ConnectionString = "MyServer"
}
};
private static object _passed = _type;
public string Casting()
{
var t = ((SomeType)_passed);
return t.Conn.ConnectionString;
}
public string Dynamic()
{
dynamic t = _passed;
return t.Conn.ConnectionString;
} Results: BenchmarkDotNet=v0.10.3.0, OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-6900K CPU 3.20GHz, ProcessorCount=16
Frequency=3123189 Hz, Resolution=320.1856 ns, Timer=TSC
[Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1590.0
DefaultJob : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1590.0
|
You can use https://github.com/aspnet/eventnotification and |
Sample usage in ApllicationInsights MVC diagnostic listener: https://github.com/Microsoft/ApplicationInsights-aspnetcore/blob/develop/src/Microsoft.ApplicationInsights.AspNetCore/DiagnosticListeners/Implementation/MvcDiagnosticsListener.cs |
Thanks @pakrym! @NickCraver please let us know if the suggested approach works for MiniProfiler. Otherwise we can keep looking into it (and also discuss #774 if if really necessary). |
@pakrym @divega Thanks a lot for the info and example, there's a lot there but everything seems sane. While I'm not as concerned with the perf given the proxy IL generation in play, I am concerned about the overall interface. Is there documentation for the parameters available to the listener methods? While I can see from reading source the parameter names on the interface or anonymous type must be matched (unless I'm reading the proxy generation wrong - please correct me if so). How are users supposed to find these parameters or know this? By digging through source code?...or is there a doc somewhere? I'd feel a lot more at ease that this interface wouldn't break if it was documented/supported somewhere - without that I'm a little uncomfortable. Hopefully there's a doc that Google just isn't finding for me? The only reference I see outside the code that the parameter names need to match was one unofficial blog post...and to find that I was searching with information I gleaned from code. A concrete example of this would be I searched for |
Assigning to @divega since work involved here is currently to make sure we are doing the right thing. |
Opened #8007 for another issue I hit actually trying to hook up here - happy to PR it if someone will take a peek there. |
@NickCraver, sorry for the late answer (I am catching up with issues assigned to me). I got this response from @vancem a while ago:
His answer seems relevant to the discussion you started on https://github.com/dotnet/corefx/issues/18114. Note for triage: Here what I believe the follow up action items should be on the EF Core side:
|
@NickCraver BTW @ajcvickers is working on a bunch of changes in this area for 2.0 which will likely include breaking changes. It would be great if we can devise a way to help you track this work closely, e.g. we can mention you in any PRs. |
@ajcvickers to look at what MVC is doing. |
There are two basic solutions to reading values out of objects passed with DiagnosticSource.
Standard reflection of course works, as does using the 'dynamic' feature of C#. For a class that does this. Bascially you could do
Then to fetch the ExecuteMethod field from 'obj' you can do
Which should be pretty fast. However it won't beat casting to a particular type. If you have need for that the recommendation is that the DiagnosticSource should expose the payload type explicitly (under the a namespace that ends in DiagnosticSource) We are thinking about exposing the PropertySpec as a public class. We just need to nail down details of exactly what its name is and some details about how it is used. If you are interested in this create an issue in the corefx repo and we can track it. In the very short term, using dynamic is pretty good, you can convert to other things at will as the need arises. |
We did some investigation and thinking on this today and we have decided to create nominal types for all our payloads. This will mean:
We talked to @rynowak about the anonymous types/proxies approach that MVC uses and he indicated that based on what they have learned using nominal types is probably better. As of yet they haven't had anybody really pushing them to change to nominal types, but they would at least consider doing so if there was such a push. |
I think having explicit types is very reasonable. My recommendation is that they call get put into a namespace that ends with 'DiagnosticSource' Thus namespace System.Data.YYY.DiagnosticSource { |
Issue #7939 Also adds nominal types for all events other than those in the relational design assemblies. (Since these assemblies are currently being refactored.) Each event payload now contains all the information needed to create and log the message for the event, including overridden ToString that creates the message.
Issue #7939 Also adds nominal types for all events other than those in the relational design assemblies. (Since these assemblies are currently being refactored.) Each event payload now contains all the information needed to create and log the message for the event, including overridden ToString that creates the message.
This means if the message is in "Scaffolding", then it is tested to not generate DiagnosticSource events. All other events are tested to be doing DiagnosticSource messages using nominal types. Issue #7939
This means if the message is in "Scaffolding", then it is tested to not generate DiagnosticSource events. All other events are tested to be doing DiagnosticSource messages using nominal types. Issue #7939
I'm trying to hook MiniProfiler up to Entity Framework Core, but I'm not really understanding what the intended interface is. My understanding is that my best (supported) route is DiagnosticSource, called via
RelationalDiagnostics
. That's the only path I see to get my hands on theDbCommand
,DbConnection
, etc. needed for various scenarios.But the
.Write()
call for DiagnosticSource is:The way RelationalDiagnostics uses this passes in a typed object (good), example here:
...but those types passed are internal, for example here's RelationalDiagnosticSourceBeforeMessage:
...and some other calls are anonymous objects, for example:
WriteConnectionOpening()
. So the usage pattern is inconsistent.How am I supposed to get at the members in an inexpensive way? I'm hoping it's hot intended that everyone use reflection here to get the members, and I can't cast because they're
internal
. The TODO scares me because that means we have to use the DLR in what should be a code path as cheap as possible. Note: the #4672 issue has since been closed.Currently I see as far as creating a DiagnosticSource for MiniProfiler and hooking up to logging that way, but not how to use the object passed to the write methods, since I'm unable to access those types. I sincerely hope I'm being an idiot - is there a way to go about this that's not "reflect everything"?
The text was updated successfully, but these errors were encountered: