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

[Instrumentation.EventCounters] Stabilize and Enable Testing #620

Merged
merged 36 commits into from
Oct 13, 2022
Merged

[Instrumentation.EventCounters] Stabilize and Enable Testing #620

merged 36 commits into from
Oct 13, 2022

Conversation

mic-max
Copy link
Contributor

@mic-max mic-max commented Sep 1, 2022

Towards #215 since spec is not stable

Changes

  • Cleans up code for EventCounters instrumentation
  • Fixes tests
  • Only create counters for EventCounters named events by default and that are from a configured EventSource name, which includes nothing by default.

Resources

Follow-up PR Plans

  • Multiple counters from the same source with different names
  • Multiple counters from the same source with the same name
  • Call meterProvider.AddEventCounterListener multiple times.
  • Verify stress testing the instrumentation does not incur memory leaks, or slowdowns.
  • Consider making a Meter for each of the EventSources listened to. (this might make any future wildcard functionality being added to AddEventSources more complicated...)
  • Add tests that ensure EventSource warning logs are created when expected. (use InMemoryEventListener vs. TestEventListener?)

For significant contributions please make sure you have completed the following items:

  • Appropriate CHANGELOG.md updated for non-trivial changes

@utpilla utpilla added the comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters label Sep 1, 2022
@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Merging #620 (65521ee) into main (7fb378d) will decrease coverage by 0.06%.
The diff coverage is 77.94%.

❗ Current head 65521ee differs from pull request most recent head a6bfef2. Consider uploading reports for the commit a6bfef2 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #620      +/-   ##
==========================================
- Coverage   77.76%   77.69%   -0.07%     
==========================================
  Files         175      175              
  Lines        5261     5249      -12     
==========================================
- Hits         4091     4078      -13     
- Misses       1170     1171       +1     
Impacted Files Coverage Δ
...ounters/EventCountersInstrumentationEventSource.cs 27.27% <16.66%> (+27.27%) ⬆️
...trumentation.EventCounters/EventCountersMetrics.cs 80.76% <80.76%> (ø)
...entCounters/EventCountersInstrumentationOptions.cs 100.00% <100.00%> (ø)
...on.EventCounters/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)

@mic-max mic-max marked this pull request as ready for review September 6, 2022 20:08
@mic-max mic-max requested a review from a team September 6, 2022 20:08
@mic-max mic-max changed the title Stabilize EventCounters Instrumentation [Instrumentation.EventCounters] Stabilize EventCounters Instrumentation and Enable Testing Sep 6, 2022
@mic-max mic-max changed the title [Instrumentation.EventCounters] Stabilize EventCounters Instrumentation and Enable Testing [Instrumentation.EventCounters] Stabilize and Enable Testing Sep 6, 2022
Copy link
Contributor

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

Thanks! I like this feature for OTel : ) I left some suggestions inline

@utpilla
Copy link
Contributor

utpilla commented Oct 10, 2022

The PR looks good. There are some duplicate checks with instrument names that should be avoided.


/// <inheritdoc />
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could eventData be null?

return;
}

var value = Convert.ToDouble(hasMean ? mean : increment);
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 move the try-catch block from UpdateInstrumentWithEvent to here to include the Convert.ToDouble method in the try block as that could also throw exceptions.

/// <inheritdoc />
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
if (this.options == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya, just dropping an event if the constructor hasn't finished setting the options field. I'll add comments as this is an obscure situation

Copy link
Contributor

Choose a reason for hiding this comment

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

We never enable events until the options are set, right? If options is null we just enqueue it and wait till the ctor has set options before proceeding to enable events for the enqueued EventSources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya this is to avoid creating instruments for event sources we don't care about.

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.

Left some suggestions. They are not blocking this PR. We would also have to enable Public API Analyzer for this project.

@utpilla utpilla merged commit a0aa56c into open-telemetry:main Oct 13, 2022
@mic-max mic-max deleted the eventcounters-stabilize branch October 14, 2022 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants