Skip to content

Request line names the caller: User and UserAgent - #38

Merged
MusaMisto merged 1 commit into
mainfrom
muhannad/request-line-caller
Oct 30, 2026
Merged

MusaMisto merged 1 commit into
mainfrom
muhannad/request-line-caller

Conversation

@mmalkhatib

Copy link
Copy Markdown
Contributor

Why

The per-request line has route, status and duration, but not who called. UseRequestContextLogEnricher pushes User onto the log context, but UseSerilogRequestLogging writes its line after the inner pipeline has returned, outside that scope, so the user never reaches it. Without a caller on the request line there's no way to count calls per client, or to know when an old route has stopped being used.

What

RequestLogging.Configure's EnrichDiagnosticContext now also sets:

  • User: RequestContext.GetNameIdentifier() when the context is valid, else the NameIdentifier claim on HttpContext.User; omitted for anonymous requests.
  • UserAgent: the header, cut to 200 characters; omitted when absent.

README updated under LogRequests.

Tests

  • Request_line_carries_the_caller (end to end through TestServer): fails without the change, passes with it.
  • Anonymous_request_line_has_no_user, plus unit tests for truncation and the null cases.
  • 29/29 pass locally.

The request line is written after the rest of the pipeline has finished,
outside the scope UseRequestContextLogEnricher pushes User into, so it never
carried the user. Read it again in EnrichDiagnosticContext (RequestContext,
else the NameIdentifier claim) and add the User-Agent, cut to 200 characters.
Calls can now be counted per caller from the request lines alone.
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c24c73b2-c3d7-45ca-8edd-10314c73ea1e
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MusaMisto
MusaMisto merged commit 6a017f9 into main Oct 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants