feat: add experimental rust request logging masking extension#4030
Merged
feat: add experimental rust request logging masking extension#4030
Conversation
9bd2d15 to
de776fc
Compare
10 tasks
de776fc to
413a5fd
Compare
f9d014d to
7b2ca6b
Compare
Collaborator
|
Cache lifetime: The |
dima-zakharov
previously approved these changes
Apr 9, 2026
Collaborator
Author
|
@dima-zakharov I addressed the cache-lifetime point in the native extension. The key-sensitivity lookup now uses a bounded thread-local LRU cache, while keeping the existing per-request cache as the first lookup. That keeps repeated keys hot across calls without letting the cache grow unbounded. I also added the missing Python package shim so the extension loads through the intended Verification from this run:
|
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
Signed-off-by: lucarlig <luca.carlig@ibm.com>
1229d76 to
0a1cd59
Compare
Signed-off-by: lucarlig <luca.carlig@ibm.com>
dima-zakharov
previously approved these changes
Apr 13, 2026
claudia-gray
pushed a commit
that referenced
this pull request
Apr 13, 2026
* feat: add rust request logging masking sidecar Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: cache key sensitivity in rust masking sidecar Signed-off-by: lucarlig <luca.carlig@ibm.com> * feat: restore pyo3 request logging path Signed-off-by: lucarlig <luca.carlig@ibm.com> * refactor: rename request logging native extension Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: add native json request logging fast path Signed-off-by: lucarlig <luca.carlig@ibm.com> * test: cover request logging native fallback paths Signed-off-by: lucarlig <luca.carlig@ibm.com> * feat: generate stubs for request logging native extension Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: reuse request logging key sensitivity cache Signed-off-by: lucarlig <luca.carlig@ibm.com> * chore: normalize detect-secrets baseline after rebase Signed-off-by: lucarlig <luca.carlig@ibm.com> --------- Signed-off-by: lucarlig <luca.carlig@ibm.com>
gcgoncalves
pushed a commit
that referenced
this pull request
Apr 23, 2026
* feat: add rust request logging masking sidecar Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: cache key sensitivity in rust masking sidecar Signed-off-by: lucarlig <luca.carlig@ibm.com> * feat: restore pyo3 request logging path Signed-off-by: lucarlig <luca.carlig@ibm.com> * refactor: rename request logging native extension Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: add native json request logging fast path Signed-off-by: lucarlig <luca.carlig@ibm.com> * test: cover request logging native fallback paths Signed-off-by: lucarlig <luca.carlig@ibm.com> * feat: generate stubs for request logging native extension Signed-off-by: lucarlig <luca.carlig@ibm.com> * perf: reuse request logging key sensitivity cache Signed-off-by: lucarlig <luca.carlig@ibm.com> * chore: normalize detect-secrets baseline after rebase Signed-off-by: lucarlig <luca.carlig@ibm.com> --------- Signed-off-by: lucarlig <luca.carlig@ibm.com>
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.
Feature / Enhancement PR
Epic / Issue
#4036
Summary (1-2 sentences)
Adds an experimental opt-in PyO3-based Rust native extension for request logging sensitive-data masking in
mcpgateway/middleware/request_logging_middleware.py. Whenexperimental_rust_request_logging_masking_enabled=true, the request logging path uses the importedrequest_logging_masking_native_extensionmodule to accelerate header masking, recursive payload masking, and JSON-body logging.Implementation Details
tools_rust/request_logging_masking_native_extension/as a PyO3 native extension that exposesmask_sensitive_data()andmask_sensitive_headers()to Python.mask_sensitive_json_bytes()so the middleware can avoid Pythonorjson.loads(...) -> mask -> orjson.dumps(...)on JSON request bodies.request_logging_masking_native_extensionso editable installs resolve the exported native functions correctly.experimental_rust_request_logging_masking_enabledfeature flag inmcpgateway/config.py.mcpgateway/middleware/request_logging_middleware.pyso the public masking helpers lazily import and delegate to the PyO3 native extension when the flag is enabled.tests/performance/test_request_logging_masking_native_extension_benchmark.pyfocused on the public feature-flagged API path and direct-native comparison.Checks
make lintpassesmake testpassesNotes
Latest microbenchmark run
Validated on April 13, 2026 using the current branch code, the real middleware masking source, and the built PyO3 native extension. The benchmark values below are all from this latest run.
nested_payload_maskingheaders_maskingCold-start and warm-path visibility from the same run:
nested_payload_masking: public-path overhead vs direct native0.2%headers_masking: public-path overhead vs direct native0.0%JSON logging fast path benchmark
The latest build also includes a dedicated native JSON-body logging path in the middleware.
json_logging_pathPrior focused request-logging loadtest
Previously validated on April 7, 2026 in a Linux container using a focused Locust workload against a FastAPI app with
RequestLoggingMiddlewareenabled for detailed request logging. This run used a heavy nested JSON body and sensitive headers aligned with the request-logging benchmark payloads so the measured throughput reflects the code changed in this PR.50users,20s)50users,20s)200users,30s)200users,30s)Focused-loadtest takeaway from the April 7 run: when the workload is dominated by detailed request logging and masking, the Rust native extension shows a large end-to-end benefit, improving throughput by
9.53xin the stable scenario and6.93xin the stress scenario.