-
-
Notifications
You must be signed in to change notification settings - Fork 937
Introduce EventSource #3539
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
base: master
Are you sure you want to change the base?
Introduce EventSource #3539
Conversation
@Shane32 I think |
Also by design it's 100% internal thing, so we can change everything. |
I need to review this PR in more detail and read up on EventSource, etc. |
For me, this is a new topic as well, I postponed the reading for a long time. The first thing to do - think about those events that we want to emit. |
At the moment, I'm not sure I want ANY events written to my Windows Event Log, which I believe would be the default behavior. I have not tested it yet. |
I think Windows Event Log does not work without some additional settings. Quick search results - https://stackoverflow.com/questions/53791076/eventsource-doesnt-write-logs-in-windows-event-viewer |
Yes.
My intent here is not general purpose logging but something more focused on metrics/counters. Moreover I see that MS/others use |
I updated PR, making it closer to real needs. |
/// <summary> | ||
/// EventSource events emitted from the project. | ||
/// </summary> | ||
[EventSource(Name = "GraphQL-NET")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GraphQL-NET
naming is from here https://learn.microsoft.com/en-us/dotnet/core/diagnostics/eventsource-instrumentation#best-practices
{ | ||
if (IsEnabled(EventLevel.Error, EventKeywords.All)) | ||
{ | ||
RequestFilterException(ex.ToInvariantString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call IsEnabled() before performing any resource intensive work related to firing an event, such as computing an expensive event argument that won't be needed if the event is disabled.
ex.ToInvariantString()
is considered as intensive work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See OpenTelemetry.Instrumentation.AspNetCore.Implementation.AspNetCoreInstrumentationEventSource
if (!_telemetryOptions.Filter(options)) | ||
try | ||
{ | ||
if (_telemetryOptions.Filter?.Invoke(options) == false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick thought: I think we have to consider the fact that the current implementation within MS's libraries are based on older technology simply because their library is older. This does not necessarily mean it is currently recommended. Secondly: I think we should try to prevent overlap if possible. No need to write to every historical logger / metric codebase solely because it exists, especially if the code is on-by-default. Let's consider what would be desired for a modern library today and go from that angle. Note: these are just some initial thoughts; I still need to read up on this stuff. |
How so? All it tracks are schema created and initialized events, which typically only occur once per application lifecycle! So far this PR seems pointless.
Those events are certainly not metrics. |
Also this is not configurable as designed. Within #3467 we implemented it as opt-in so it can be configured or left disabled. Here it's built-in. Why the difference? |
Did you see filtering events? |
I'm fine either way. In case of modern lib it will cost us one additional conditional dependency. In case of "old" EventSource it costs nothing. |
I don't get it. Perhaps in the PR description you should state what this PR's intent is and/or what it does. I certainly would not add |
I'm so pressed for time I may not have read this PR fully. |
Yes. I look at I would like GraphQL.NET to provide event counters out of the box. For example, see how it was done here rabbitmq/rabbitmq-dotnet-client#1027 . To implement counters I found
I would say that I don't look at EventSource/EventCounters as an "old" API that should be avoided. It just works and it costs nothing in terms of performance.
Yep. Not just to log exceptions. It so happened that I presented not the main application of this tool. Its main application for me is counters. I can continue working on counters in this PR or in new one - I'm fine either way. So the questions so far are:
|
@Shane32 Just googled it, see this https://github.com/dotnet/runtime/search?q=PollingCounter for reference. These are examples of counters/events in .NET runtime. |
@Shane32 I enabled this setting |
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #3539 +/- ##
==========================================
+ Coverage 83.91% 83.97% +0.05%
==========================================
Files 381 382 +1
Lines 16876 16935 +59
Branches 2715 2720 +5
==========================================
+ Hits 14162 14221 +59
Misses 2068 2068
Partials 646 646
|
If we want built-in counters and etc, perhaps we should consider adding a dependency on System.Diagnostics.DiagnosticSource for v8 and using the most modern framework rather than using an outdated pattern. |
Helps with #3467
fixes #3540
https://learn.microsoft.com/en-us/dotnet/core/diagnostics/eventsource-getting-started
No ifdefs, no additional dependencies. Supported by all TFMs. Lightweight and cross-platform.
Trace (actually events) captured by
dotnet-trace collect --providers GraphQL -p 22316
: