Add PROFILER_EXCLUDE_PATHS to skip paths in profiler sampling#242
Merged
Conversation
Config: - PROFILER_EXCLUDE_PATHS: comma-separated glob patterns whose matching request paths are kept out of PROFILER_SAMPLE_RATE sampling, so framework self-traffic (Symfony's /_profiler and /_wdt toolbar requests, Laravel Debugbar/Telescope) no longer pollutes captured profiles. Compiled into an Option<Arc<GlobSet>> on ProfilerConfig, parsed unconditionally so a malformed glob fails fast at startup. Exclusion gates the sample_rate branch only: an explicit trigger (x-oxphp-profile header, OXPROF cookie, __oxprof query) still profiles an excluded path. Matching runs on the raw request path at RequestReceived (before routing), so no percent-decoding or dot-segment normalization — only the glob syntax is shared with PHP_DENY_PATHS, not the matched input. Refactor: - Extract config::compile_glob_csv(raw, label) — the split/trim/leading-slash-strip and literal_separator(true) GlobSet build shared verbatim by PHP_DENY_PATHS and PROFILER_EXCLUDE_PATHS, so their glob semantics cannot drift apart. php_deny routes through it; its now-unused normalize_pattern helper and inline builder are removed. API: - /config reports the profiler's exclude_paths (configured patterns) next to enabled/sample_rate/auth_token_configured, so an operator can confirm the exclusion compiled. Docs: - Add a "5.5 Excluding paths from sampling" subsection and config-table row to the en/ru/zh profiler guides, with the Symfony/Laravel recipe and a prominent note that exclusion affects automatic sampling only. Add a changelog entry under Unreleased. Misc: - path_excluded uses unwrap_or instead of unwrap_or_else — uri.path() is a cheap borrow with nothing to defer. 9 tests (9 unit).
827ac87 to
d24d157
Compare
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
Adds
PROFILER_EXCLUDE_PATHS— comma-separated glob patterns whose matching request paths are kept out ofPROFILER_SAMPLE_RATEsampling. This stops framework self-traffic (Symfony's/_profilerand/_wdttoolbar requests, Laravel Debugbar/Telescope) from polluting captured profiles when sampling is enabled in production.Behavior
sample_ratebranch. An explicit trigger (x-oxphp-profileheader,OXPROFcookie,__oxprofquery) still profiles an excluded path — so you can deliberately profile/_profileritself while keeping it out of background sampling.PHP_DENY_PATHS:*does not cross/,**does, leading/optional. Cover a bare path and its subtree by listing both, e.g.PROFILER_EXCLUDE_PATHS=/_profiler,/_profiler/**,/_wdt/**.RequestReceived(before routing) — no percent-decoding or..normalization. The pattern syntax is shared withPHP_DENY_PATHS, not the matched input; this is documented and intentional (exclusion only suppresses sampling overhead, it is not a security boundary).Changes
PROFILER_EXCLUDE_PATHS, compiled toOption<Arc<GlobSet>>onProfilerConfig.config::compile_glob_csv(raw, label)shared verbatim byPHP_DENY_PATHSandPROFILER_EXCLUDE_PATHSso their glob semantics can't drift; removesphp_deny's now-unusednormalize_pattern/inline builder./configreports the profiler'sexclude_paths(configured patterns) so an operator can confirm the exclusion compiled.Tests
9 new unit tests (parse semantics, sampling gate, explicit-trigger bypass, raw-path behavior, bare-vs-subtree). Full suite green;
php_denyrefactor verified against its existing test suite.