Skip to content
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

Merged

Conversation

hananiel
Copy link

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

@hananiel hananiel requested a review from a team May 18, 2022 15:07
@hananiel hananiel force-pushed the EventCounterListenerWithoutConfig branch from aac78af to c87eef6 Compare May 18, 2022 16:05
@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #365 (362558a) into main (f27d824) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #365   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        163     167    +4     
  Lines       4996    5084   +88     
=====================================
- Misses      4996    5084   +88     
Impacted Files Coverage Δ
...trumentation.EventCounters/EventCounterListener.cs 0.00% <0.00%> (ø)
...tation.EventCounters/EventCounterMetricsOptions.cs 0.00% <0.00%> (ø)
...ounters/EventCountersInstrumentationEventSource.cs 0.00% <0.00%> (ø)
...on.EventCounters/MeterProviderBuilderExtensions.cs 0.00% <0.00%> (ø)

@hananiel hananiel changed the title Create a EventCounter Listener that subscribes to all event counters Create an EventCounter Listener that subscribes to all event counters May 18, 2022
@hananiel hananiel force-pushed the EventCounterListenerWithoutConfig branch from ea5cf17 to 7debc15 Compare May 18, 2022 16:57
@hananiel hananiel requested a review from cijothomas May 26, 2022 22:35

protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
if (!this.isInitialized || !eventData.EventName.Equals("EventCounters"))
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

@hananiel hananiel mentioned this pull request May 31, 2022
@birojnayak
Copy link
Contributor

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

this is definitely going to be useful.. waiting for this CR to be merged

@hananiel hananiel requested a review from cijothomas June 10, 2022 19:50
@github-actions
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jun 18, 2022
@stebet
Copy link
Contributor

stebet commented Jun 23, 2022

Would absolutely love to see this make it in! Let me know if I can help @cijothomas @hananiel

@github-actions github-actions bot removed the Stale label Jun 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2022

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jul 1, 2022
@cijothomas cijothomas removed the Stale label Jul 7, 2022
Copy link
Member

@cijothomas cijothomas left a 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)
Copy link
Contributor

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" />
Copy link
Contributor

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);
Copy link
Contributor

@utpilla utpilla Jul 8, 2022

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.

@utpilla
Copy link
Contributor

utpilla commented Jul 8, 2022

@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.

Copy link
Contributor

@utpilla utpilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestions.

Assert.True(metricItems.Count > 1);
}

[Fact(Skip = "Unstable")]
Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor

@utpilla utpilla left a 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.

@utpilla utpilla merged commit 9418c08 into open-telemetry:main Jul 12, 2022
@magoogli
Copy link

magoogli commented Aug 1, 2022

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?

@mic-max
Copy link
Contributor

mic-max commented Sep 6, 2022

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
There could be additional need to listen to an eventName from a specific eventSource though. The options I configured only listen to the listed event sources and listed event names, not a particular event from a specific event source if that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants