-
Notifications
You must be signed in to change notification settings - Fork 19
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
AddContextToPrincipalMiddleware updates #111
base: master
Are you sure you want to change the base?
AddContextToPrincipalMiddleware updates #111
Conversation
…cated. Don't assume there is alwasys a non-null activity. Use the header dictionary for searching header values.
WalkthroughThe changes in the Changes
Possibly related issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/Arc4u.Standard.OAuth2.AspNetCore/Middleware/AddContextToPrincipalMiddleware.cs (2 hunks)
Additional comments not posted (5)
src/Arc4u.Standard.OAuth2.AspNetCore/Middleware/AddContextToPrincipalMiddleware.cs (5)
31-31
: Comment addition improves code clarity.The comment helps clarify the conceptual relationship between setting a traceparent and adding context to the principal.
33-47
: Ensuringtraceparent
header improves telemetry.The changes ensure that a
traceparent
header is always set, improving telemetry regardless of authentication status.
49-56
: Streamlined culture header extraction.The use of
TryGetValue
improves efficiency and readability. Exception handling maintains robustness.
Line range hint
56-60
: Exception handling ensures robustness.Logging exceptions during culture setting is a good practice, ensuring issues are captured.
Line range hint
62-62
: Appropriate use ofConfigureAwait(false)
.Using
ConfigureAwait(false)
in library code is a best practice to avoid capturing the context and potential deadlocks.
This PR contains the following changes for
AddContextToPrincipalMiddleware
:The setting of a
traceparent
header is always useful for telemetry, independently of the fact that we are authenticated. Previously,AddContextToPrincipalMiddleware
would only have atraceparent
if we were authenticated. Now,traceparent
is always present.Activity.Current
can be null, becauseactivity
can be null if (1)_activitySource
is null, or (2) the activity has no active listeners (source: documentation). The code has been modified to take this into account.When searching for headers, it's much more efficient to use the
IHeaderDictionary
than to useFirstOrDefault
with a string comparator: theIHeaderDictionary
has the correct comparison for the name built-in.The action of setting a traceparent and adding context to the principal are conceptually separate, but they are viewed as one "activity" in this middleware: this is unexpected but is now explicitly documented.
Summary by CodeRabbit
New Features
traceparent
header for improved request tracing.Bug Fixes