Skip to content

HttpRequestLatencyListener.OnEventWritten throws KeyNotFoundException for unknown event sources #6822

@ssmelov

Description

@ssmelov

Description

The current implementation of HttpRequestLatencyListener.OnEventWritten always expects that eventSourceName should be available in the _eventToTokenMap dictionary.
Certain events (e.g., EventCounters) bypass the enabled events check, which results in OnEventWritten throwing a KeyNotFoundException.

Example

The "EventCounters" event from the source "System.Runtime" is sent to all listeners and skips the enabled event check since its eventId is -1.

https://github.com/dotnet/runtime/blob/ac8354e3e94f04fae2d6d942427d025395197f76/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L2187

Impact

KeyNotFoundExceptions from HttpRequestLatencyListener cause each HTTP request to be 2-3 times slower.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions