-
Notifications
You must be signed in to change notification settings - Fork 293
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
Create an EventCounter Listener that subscribes to all event counters #365
Create an EventCounter Listener that subscribes to all event counters #365
Conversation
aac78af
to
c87eef6
Compare
Codecov Report
@@ Coverage Diff @@
## main #365 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 163 167 +4
Lines 4996 5084 +88
=====================================
- Misses 4996 5084 +88
|
ea5cf17
to
7debc15
Compare
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
|
||
protected override void OnEventWritten(EventWrittenEventArgs eventData) | ||
{ | ||
if (!this.isInitialized || !eventData.EventName.Equals("EventCounters")) |
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.
Where does the "EventCounters" name come from?
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.
It is hardhoded in the implementation class: https://github.com/dotnet/runtime/blob/e026f392b2bb93bc9509ac5403d3e8cd7d3eee72/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventCounter.cs#L129
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.
nit: I think it might be better to swap the order of the conditions here.
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
this is definitely going to be useful.. waiting for this CR to be merged |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Would absolutely love to see this make it in! Let me know if I can help @cijothomas @hananiel |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
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.
Looks good for an initial PR. We can iterate on this.
### Step 1: Install Package | ||
|
||
Add a reference to the | ||
[`OpenTelemetry.Contrib.Instrumentation.EventCounters`](https://www.nuget.org/packages/OpenTelemetry.Contrib.Instrumentation.EventCounters) |
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.
Remove the word Contrib
.
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="OpenTelemetry.Api" Version="1.2.0-rc2" /> |
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.
You could use 1.3.0
.
case InstrumentType.ObservableCounter: | ||
if (!this.metricInstruments.ContainsKey(metricKey)) | ||
{ | ||
this.metricInstruments[metricKey] = this.meter.CreateObservableCounter(counterName, () => this.ObserveDouble(metricKey), description: description); |
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.
Use the TryAdd
method of the ConcurrentDictionary
for a thread-safe implementation.
@hananiel Thanks for creating this PR! Could you please follow the contributing doc to add additional files such as package workflow, issue template etc. You could also refer to any of the existing projects. The other comments could be addressed in a follow-up PR. |
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.
Approved with suggestions.
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.EventCounters/EventCounterListener.cs
Outdated
Show resolved
Hide resolved
Assert.True(metricItems.Count > 1); | ||
} | ||
|
||
[Fact(Skip = "Unstable")] |
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.
Consider using InMemoryExporter
that takes in a collection of MetricSnapshot
as we persist the metric values in that case.
} | ||
|
||
[Fact(Skip = "Unstable")] | ||
public async Task TestEventCounterMetricsAreCaptured() |
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.
These need not be async Task
. You could use Task.Delay(...).Wait()
instead.
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.
LGTM. Left some suggestions to improve the unit tests which could be done in a follow-up PR.
This feature is great @hananiel, just what I was looking for. Can I help with the additional work to select which event counters to listen to, or is this in progress already? |
I did some work on that here #620 |
Resolves Issue #215
Created a focussed PR that subscribes to all Event Counter Events.
The configuration to selectively listen to particular EventCounter Sources and/or Counters will be added as a separate PR.
This will replace PR #177