diff --git a/src/Libraries/Microsoft.Extensions.Telemetry/Metering.Collectors.EventCounters/EventCountersListener.cs b/src/Libraries/Microsoft.Extensions.Telemetry/Metering.Collectors.EventCounters/EventCountersListener.cs index e472a2aa52a..c5ca35d91e7 100644 --- a/src/Libraries/Microsoft.Extensions.Telemetry/Metering.Collectors.EventCounters/EventCountersListener.cs +++ b/src/Libraries/Microsoft.Extensions.Telemetry/Metering.Collectors.EventCounters/EventCountersListener.cs @@ -231,7 +231,7 @@ private void EnableIfNeeded(EventSource eventSource) } _logger.EnablingEventSource(eventSource.Name); - EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, _eventSourceSettings); + EnableEvents(eventSource, EventLevel.Critical, EventKeywords.None, _eventSourceSettings); } private void RecordSumEvent(IDictionary eventPayload, string counterName) diff --git a/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Metering.Collectors.EventCounters/EventCountersListenerTest.cs b/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Metering.Collectors.EventCounters/EventCountersListenerTest.cs index db518de05b7..af2bbc24af2 100644 --- a/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Metering.Collectors.EventCounters/EventCountersListenerTest.cs +++ b/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Metering.Collectors.EventCounters/EventCountersListenerTest.cs @@ -330,16 +330,41 @@ public void EventCountersListener_Ignores_Empty_Counters_Maps() Assert.Equal(0, instrumentCounter.Count); } - [Fact] - public void EventCountersListener_Emits_WhenSumCounterMatches() + [Theory] + [InlineData(EventLevel.Verbose)] + [InlineData(EventLevel.Informational)] + [InlineData(EventLevel.Warning)] + [InlineData(EventLevel.Error)] + public void EventCountersListener_Ignores_LowEventLevels(EventLevel eventLevel) { using var meter = new Meter(); + using var instrumentCounter = new InstrumentCounter(meter); using var metricCollector = new MetricCollector(meter, $"{_eventSourceName}|{_counterName}"); using var eventSource = new EventSource(_eventSourceName); using var listener = new EventCountersListener(_options, meter); eventSource.Write(EventName, - new EventSourceOptions { Level = EventLevel.LogAlways }, + new EventSourceOptions { Level = eventLevel }, + new + { + payload = new { CounterType = "Sum", Name = _counterName, Increment = 1 } + }); + + Assert.Equal(0, instrumentCounter.Count); + } + + [Theory] + [InlineData(EventLevel.Critical)] + [InlineData(EventLevel.LogAlways)] + public void EventCountersListener_Emits_WhenSumCounterMatches(EventLevel eventLevel) + { + using var meter = new Meter(); + using var metricCollector = new MetricCollector(meter, $"{_eventSourceName}|{_counterName}"); + + using var eventSource = new EventSource(_eventSourceName); + using var listener = new EventCountersListener(_options, meter); + eventSource.Write(EventName, + new EventSourceOptions { Level = eventLevel }, new { payload = new { CounterType = "Sum", Name = _counterName, Increment = 1 }