- Notifications
You must be signed in to change notification settings - Fork845
Fix KeyNotFoundException on HttpRequestLatencyListener.OnEventWritten for uknown event sources#6821
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
… for unknown event sources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR fixes a KeyNotFoundException that occurs in HttpRequestLatencyListener.OnEventWritten when handling unknown event sources. The issue arises when events like EventCounters bypass the enabled events check, causing the method to attempt dictionary access with a non-existent key.
- Adds safe dictionary access to prevent KeyNotFoundException when unknown event sources are encountered
- Includes test coverage to verify the fix handles unknown events correctly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| HttpRequestLatencyListener.cs | Implements safe dictionary access using TryGetValue to prevent KeyNotFoundException |
| HttpRequestLatencyListenerTest.cs | Adds test to verify unknown events don't cause exceptions or add checkpoints |
Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.
...crosoft.Extensions.Http.Diagnostics.Tests/Latency/Internal/HttpRequestLatencyListenerTest.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
…ency/Internal/HttpRequestLatencyListenerTest.csCo-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…n_for_unknown_events
ssmelov commentedSep 23, 2025
@dotnet-policy-service agree company="Microsoft" |
e5b7f5d intodotnet:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
https://github.com/dotnet/runtime/blob/ac8354e3e94f04fae2d6d942427d025395197f76/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L2187
Microsoft Reviewers:Open in CodeFlow
Fixes#6822