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

Restrict keywords and log levels enabled in EventCountersListener #4109

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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