Let the middleware skip paths or log them only on failure - #5
Merged
Merged
Conversation
Every inbound exchange was logged, which made probes and periodic internal calls the bulk of a service's log. Measured on one fleet over a day, health checks were two thirds of every byte logged and scheduled sweeps another sixth, while saying nothing their callers do not already see. The builder gains two options, both matching the request path exactly. withIgnoredPaths never logs the listed paths. withFailureOnlyPaths logs the listed paths only when the response is an error, and then writes the request and response entries with the same context as any other path. Every other path is logged as before, and build(clock:, logger:) keeps working unchanged.
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.
Summary
Every inbound exchange was logged, which made probes and periodic internal calls the bulk of a service's log. Measured
on one fleet over 24 hours: health checks were 67.8% of every byte logged and scheduled sweeps another 15.6%, both
billed per ingested gigabyte, while a failing probe or sweep is already visible to whoever calls it.
The builder gains two options, both matching
$request->getUri()->getPath()by exact string equality:withIgnoredPathsnever logs the listed paths, neither therequestnor theresponseentry, whatever the status.withFailureOnlyPathslogs the listed paths only when the response is an error (4xx or 5xx). On failure it writesthe
requestandresponseentries after the handler returns, with the same context as on any other path. A pathin both lists is never logged.
LogMiddleware::build(clock:, logger:)keeps working unchanged,with the two lists as optional trailing parameters.
One behaviour to know: a handler that throws on a failure-only path produces no entry, because there is no response
to judge. An error middleware running inside this one turns the exception into a 5xx response, which is then logged.
The README says so.
Related issue
None. The need came from measuring a consumer's log volume.
Checklist
failure-only paths silent on 200, 201, 204 and 302 and logged on 400, 404, 422, 500 and 503; unlisted paths
unchanged; exact matching against prefix, suffix, trailing slash, extra segment and case; correlation id on a
failure-only failure; backward compatibility of the builder and of
build(); a path in both lists.make reviewpasses.make testspasses: 50 tests, 89 assertions, 52 mutants, all killed, MSI 100%.