Skip to content

Commit

Permalink
Fix #4104 (#4109)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Balabaev <nbalabaev@microsoft.com>
  • Loading branch information
xakep139 and xakep139 authored Jun 24, 2023
1 parent 62ee57e commit 14917b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> eventPayload, string counterName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventCountersListener>();
using var instrumentCounter = new InstrumentCounter(meter);
using var metricCollector = new MetricCollector<long>(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<EventCountersListener>();
using var metricCollector = new MetricCollector<long>(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 }
Expand Down

0 comments on commit 14917b8

Please sign in to comment.