Document how to add context to every log line of a request - #68
Merged
Merged
Conversation
The example project's README only showed around_action, which cannot reach the request and response lines logged by the HTTPEvents middleware. Describe UserContext.custom_user_hash and a custom middleware inserted before HTTPEvents, and state around_action's limit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PetrHeinz
marked this pull request as ready for review
October 2, 2026 11:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The example project's README only showed
around_actionfor adding context to a request's logs, so readers of #28 could not get the user onto theStarted GET …andCompleted 200 OK …lines: those are logged by theHTTPEventsRack middleware before the controller runs. The gem has always had the right hook for this,Logtail::Integrations::Rack::UserContext.custom_user_hash, but no README mentioned it.The "Context" section of
example-project/README.mdnow explains:custom_user_hash: a lambda that finds the user in the Rack env and returns a hash, logged ascontext.useron every line of the request, including the request and response lines;Logtail.with_contextfor any other per-request context, inserted beforeLogtail::Integrations::Rack::HTTPEventsfrom an initializer;around_actionstays, as the option when the user is only known inside the controller, with its limit stated.README.mdlinks to that section.Both snippets were run as written on the example project (Rails 8.1.4, Ruby 3.3.4, logtail-rails 0.2.14, logtail-rack 0.2.8, logtail 0.1.20) against a local sink: the lambda's hash and the middleware's
tenantkey arrive on theStarted,Processing, in-action,RenderedandCompletedrows; thearound_actioncontext arrives on the in-action andRenderedrows only.🤖 Generated with Claude Code