-
Notifications
You must be signed in to change notification settings - Fork 447
Correlation ID for Unified Request Tracking #1443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
d0712be to
a17e408
Compare
dd94c98 to
cb9e60a
Compare
7552ba9 to
95be3a2
Compare
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
- Fix Alembic migration to chain after main branch head (356a2d4eed6f) - Fix is_active/enabled attribute access in services (server, prompt, resource, export) - Update export_service to use getattr with fallback for backwards compatibility - Add db.refresh before return in tool_service.register_tool to handle session expiry after audit/logging commits - Add SessionLocal patches in conftest.py for audit_trail_service and log_aggregator - Update test assertions for expected db.refresh call count - Apply isort import ordering fixes across service files Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
8a69950 to
4821f0a
Compare
crivetimihai
approved these changes
Dec 12, 2025
β¦g fuzz test
- Use sa.false() instead of string literals for Boolean server_defaults
in migration (SQLite uses 0/1, not "false"/"true")
- Use sa.text("'{}'") for JSON server_defaults to ensure proper quoting
- Update fuzz test to expect dict tags format {id, label} instead of strings
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
crivetimihai
added a commit
that referenced
this pull request
Dec 12, 2025
* mTLS support Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * feat: added mTLS support to plugin mcp servers. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: added streamable http support to runtime_mtls.py Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: updated plugin server runtime.py to support mTLS. removed chuck-mcp-runtime Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: switched chuk-mcp-runtime with mcp python sdk to support mTLS. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: updated llmguard and opa plugins to install the mcp official sdk. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added health check to plugin server runtimes. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: added health check for mtls plugin server Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: removed chuk-mcp-runtime, replaced with official mcp library. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: runtime tests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: initial revision of configurable plugin builds. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: added mtls plugin documentation. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: linting issues. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: install templates with cli, fix error messages. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: mtls and stdio test cases. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: remove commented code. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: and examples Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: docstring issues Signed-off-by: Teryl Taylor <terylt@ibm.com> * tests: added unit tests and more commenting. Signed-off-by: Teryl Taylor <terylt@ibm.com> * tests: add tests. Fix doc tests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: change to make python the default. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: bandit issue. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: updated key length to 4096 Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: utility function for verifying certificates. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: added utility class for ssl certificate verification. Signed-off-by: Teryl Taylor <terylt@ibm.com> * test: added certificate validation tests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added support for cert-manager in k8s. Signed-off-by: Teryl Taylor <terylt@ibm.com> * tests: skipped tls doctest. Signed-off-by: Teryl Taylor <terylt@ibm.com> * test: fix doctests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: added example cert-manager issuer file. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: updated mtls documentation to point to plugins mtls documentation. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: forgot to add deploy-k8s-cert-manager.yaml Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: add registry pushing support. clean up pydantics. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: fixes to support Openshift, and support enabling plugins in k8s. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added openshift route file for installing route to mcpgateway admin site. Signed-off-by: Teryl Taylor <terylt@ibm.com> * chore: fix vulture issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: fix yamlint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * test: add unit tests Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: doctests coverage Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * tests: add doctests Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * docs: simplified docs and added an example configuration at the top. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: doctest issue. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: added more doctests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: added more doctests. Signed-off-by: Teryl Taylor <terylt@ibm.com> * docs: omit builder classes from doctest coverage analysis. Signed-off-by: Teryl Taylor <terylt@ibm.com> * Roadmap update Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * lint: fix flake8 issues. Signed-off-by: Teryl Taylor <terylt@ibm.com> * Minor fix to OAuth token expiry logic (#1579) * minor fix to oauth token expiry logic Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Fix tests in test_prompt_service Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Fix doctest Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * Fix failing test Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> --------- Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix uuid migration for postgresql (#1584) Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * Enabling HTTPS with Encrypted SSL Keys via Passphrase Support (#1578) * added ssl key manager Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * update gunicorn config to support ssl cert passphrase Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * update dockercompose with passphrase varaible Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * targets supporitng certs with passphrase Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * check passphrase Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * fix location Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * update test cases Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * linting Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> --------- Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * added test resource functionality (#1575) * added test resource functionality removed content part from edit & view screens of resource updated message displayed on UI when edit/view/test buttons are clicked for inactive resource Signed-off-by: Satya <tsp.0713@gmail.com> * updated ResourceTemplate id datatype to str updated isActive for resource in admin.js based out of enable allaignment correction made code for sse connection under transport.py Signed-off-by: Satya <tsp.0713@gmail.com> * fixing tests Signed-off-by: Satya <tsp.0713@gmail.com> * rebase, conflicts resolved Signed-off-by: Satya <tsp.0713@gmail.com> --------- Signed-off-by: Satya <tsp.0713@gmail.com> * Fix in toolops tab UI code to call admin tools endpoint to get list of tools. (#1573) * fixed page refresh issue when added mcp server from server list page. * Minor update to toolops read me --------- Co-authored-by: Neelamadhav Gantayat <neelamadhav@in.ibm.com> * Correlation ID for Unified Request Tracking (#1443) * Add correlation ID system for unified request tracking Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * replace undefined bearer_scheme with security Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * lint & test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fixes for lint Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * pylint fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * Bandit fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix for test Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * addiitonal changes for UI & middleware Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix bug Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * dropdown mismatch fix Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fixes for UI Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * UI fixes for adding user details Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * admin ui fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * test fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * lint fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix for doctest Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * auth issue fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * update for failing tests Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * flake8 issue Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * prevent SQLite rollback error on validation failures Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * false positive issues Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix lint issue Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * update alembic file Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * updated alembic revision Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * changes in table schema Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * gateway service fixes Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * updated tests Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix doctest coverage Signed-off-by: Shoumi <shoumimukherjee@gmail.com> * fix: resolve rebase conflicts and fix test issues for correlation ID PR - Fix Alembic migration to chain after main branch head (356a2d4eed6f) - Fix is_active/enabled attribute access in services (server, prompt, resource, export) - Update export_service to use getattr with fallback for backwards compatibility - Add db.refresh before return in tool_service.register_tool to handle session expiry after audit/logging commits - Add SessionLocal patches in conftest.py for audit_trail_service and log_aggregator - Update test assertions for expected db.refresh call count - Apply isort import ordering fixes across service files Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * Linting Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: ensure cross-database compatibility for migrations and update tag fuzz test - Use sa.false() instead of string literals for Boolean server_defaults in migration (SQLite uses 0/1, not "false"/"true") - Use sa.text("'{}'") for JSON server_defaults to ensure proper quoting - Update fuzz test to expect dict tags format {id, label} instead of strings Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> * Enable vault token (#1585) Signed-off-by: Chris PC <chrispc@li-4dc2bf4c-325d-11b2-a85c-b68e8b1fc307.ibm.com> Co-authored-by: Chris PC <chrispc@li-4dc2bf4c-325d-11b2-a85c-b68e8b1fc307.ibm.com> * [Security Feature]: RBAC Plugin using Cedar (#1499) * Prompt and tool hooks implementation for cedar plugin Signed-off-by: Shriti Priya <shritip@ibm.com> * Adding hook implementation and test cases for resource hooks Signed-off-by: Shriti Priya <shritip@ibm.com> * test cases for all hooks in cedar and custom_dsl policy langauge modes Signed-off-by: Shriti Priya <shritip@ibm.com> * Adding documentation in code Signed-off-by: Shriti Priya <shritip@ibm.com> * Files for external server Signed-off-by: Shriti Priya <shritip@ibm.com> * Adding documentation Signed-off-by: Shriti Priya <shritip@ibm.com> * Documentation update Signed-off-by: Shriti Priya <shritip@ibm.com> * update documentation Signed-off-by: Shriti Priya <shritip@ibm.com> * Updating documentation Signed-off-by: Shriti Priya <shritip@ibm.com> * Adding env variables for transport and host in env.template Signed-off-by: Shriti Priya <shritip@ibm.com> * Solving yaml lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * reverting changes in opa Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing pylint and flake8 issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing flake8 issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * manifest update and flake8 issues resolved Signed-off-by: Shriti Priya <shritip@ibm.com> * init in test update Signed-off-by: Shriti Priya <shritip@ibm.com> * Adding new line Signed-off-by: Shriti Priya <shritip@ibm.com> * documentation update and error handling Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing lint issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fixing flake8 issues Signed-off-by: Shriti Priya <shritip@ibm.com> * fix(cedar-plugin): improve code quality and formatting - Fix import order (move urllib.parse to standard library section) - Replace unnecessary elif after return with if statements - Apply black and isort formatting to plugin and tests Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * Linting Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Shriti Priya <shritip@ibm.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> * fix: add nosec comments for subprocess calls in builder module Add bandit nosec comments to suppress B404, B603, and B607 warnings for legitimate subprocess calls in the deployment builder module. These subprocess calls are used for git operations and container/ kubernetes commands which are necessary for the deployment tool. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * Rebase and lint Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> Signed-off-by: Satya <tsp.0713@gmail.com> Signed-off-by: Shoumi <shoumimukherjee@gmail.com> Signed-off-by: Chris PC <chrispc@li-4dc2bf4c-325d-11b2-a85c-b68e8b1fc307.ibm.com> Signed-off-by: Shriti Priya <shritip@ibm.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: Madhav Kandukuri <madhav165@users.noreply.github.com> Co-authored-by: Keval Mahajan <65884586+kevalmahajan@users.noreply.github.com> Co-authored-by: Satya <tsp.0713@gmail.com> Co-authored-by: Jay Bandlamudi <jay_bandlamudi@in.ibm.com> Co-authored-by: Neelamadhav Gantayat <neelamadhav@in.ibm.com> Co-authored-by: Shoumi M <55126549+shoummu1@users.noreply.github.com> Co-authored-by: ChrisPC-39 <60066382+ChrisPC-39@users.noreply.github.com> Co-authored-by: Chris PC <chrispc@li-4dc2bf4c-325d-11b2-a85c-b68e8b1fc307.ibm.com> Co-authored-by: Shriti Priya <shritip@ibm.com>
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
This PR delivers a comprehensive structured JSON logging pipeline that captures correlation IDs end-to-end (ingress middleware β services β persistence) while maintaining backward compatibility with legacy console/file logs. It introduces:
π Related Issues
#300
π§ Changes Made
Core Implementation
Correlation ID Infrastructure
mcpgateway/utils/correlation_id.py): ContextVar-based correlation ID storage for async-safe request tracking across the entire request lifecyclemcpgateway/middleware/correlation_id.py): HTTP middleware for X-Correlation-ID header extraction, validation, generation, and injection into responsesmcpgateway/services/logging_service.py): CorrelationIdJsonFormatter for automatic correlation ID injection into JSON logs with OpenTelemetry trace contextStructured Logging & Observability
mcpgateway/services/structured_logger.py): Central logging facade that persists to database (StructuredLogEntry) with enriched metadata (user, component, operation type, duration)mcpgateway/services/log_aggregator.py): Aggregates structured logs into PerformanceMetric windows with percentiles (p50/p95/p99) and error ratesmcpgateway/services/security_logger.py): Specialized logger for authentication attempts, suspicious activity, and threat scoringmcpgateway/services/audit_trail_service.py): CRUD operation tracking with change sets, data classification, and review flagsAPI & Admin UI
mcpgateway/routers/log_search.py): RESTful endpoints for log search, correlation tracing, security events, audit trails, and performance metricsmcpgateway/static/admin.js,mcpgateway/templates/admin.html): System Logs tab rebuilt with quick actions, correlation trace modal, unified timeline view, and dynamic filtersDatabase Schema
mcpgateway/alembic/versions/k5e6f7g8h9i0_add_structured_logging_tables.py): Creates 4 new tables:structured_log_entries: Comprehensive log storage with correlation IDs, user context, performance data, security indicatorsperformance_metrics: Time-windowed aggregations with percentile calculationssecurity_events: Threat analysis, failed attempt tracking, alert managementaudit_trails: CRUD tracking with change detection and compliance metadataβοΈ Configuration
New Settings in
config.py:Correlation ID Settings (4 new fields):
correlation_id_enabled: Enable/disable correlation ID tracking (default:True)correlation_id_header: Configurable header name (default:X-Correlation-ID)correlation_id_preserve: Preserve client-provided IDs (default:True)correlation_id_response_header: Echo correlation ID in responses (default:True)Structured Logging Settings (3 new fields):
structured_logging_enabled: Enable JSON logging with DB persistence (default:True)structured_logging_database_enabled: Persist logs to database (default:True)structured_logging_external_enabled: Send to external systems (default:False)Performance Tracking Settings (6 new fields):
performance_tracking_enabled: Enable performance metrics (default:True)performance_threshold_*_ms: Alert thresholds for database queries, tool invocations, resource reads, HTTP requestsperformance_degradation_multiplier: Alert threshold vs baseline (default:1.5)Security Logging Settings (4 new fields):
security_logging_enabled: Enable security event logging (default:True)security_failed_auth_threshold: Failed attempts before high severity (default:5)security_threat_score_alert: Threat score alert threshold (default:0.7)security_rate_limit_window_minutes: Rate limit check window (default:5)Metrics Aggregation Settings (4 new fields):
metrics_aggregation_enabled: Enable automatic log aggregation (default:True)metrics_aggregation_backfill_hours: Historical data to backfill on startup (default:6)metrics_aggregation_window_minutes: Aggregation window size (default:5)metrics_aggregation_auto_start: Auto-run aggregation loop (default:False)Log Search Settings (2 new fields):
log_search_max_results: Maximum results per query (default:1000)log_retention_days: Days to retain logs in database (default:30)Updated
.env.example:π Integration Points
Middleware Stack (
main.py):metrics_aggregation_auto_start=Truestructured_logging_enabled=TrueAuthentication & Security:
auth.py: Enhanced JWT validation with correlation ID contextmiddleware/auth_middleware.py: AuthContextMiddleware now logs successful/failed authentication attempts via SecurityLoggermiddleware/http_auth_middleware.py: Unified correlation ID usage across plugin auth hooksService Layer:
services/tool_service.py: Integrated correlation ID fallback chain and structured logging for tool invocationsservices/resource_service.py: Added user context and audit logging for resource operationsservices/prompt_service.py: Enhanced with structured logging and performance trackingservices/server_service.py: Integrated audit trails for server lifecycle eventsservices/gateway_service.py: Added correlation ID propagation for federated requestsservices/a2a_service.py: Added correlation ID and user context to agent invocationsObservability:
observability.py: Auto-inject correlation_id into OpenTelemetry spans asrequest.idattributemiddleware/request_logging_middleware.py: Gateway boundary logging (request_started/completed) with correlation IDs, user resolution, and duration trackingadmin.py: Plugin marketplace endpoints emit structured logs + audit trails for complianceπ New Files
mcpgateway/middleware/correlation_id.pyβ FastAPI middleware that extracts/preserves correlation IDs and injects them into responsesmcpgateway/utils/correlation_id.pyβ ContextVar utilities for generating, validating, and retrieving correlation IDs across async scopesmcpgateway/services/structured_logger.pyβ Central structured logging facade that writes to JSON, DB, and optional external sinksmcpgateway/services/log_aggregator.pyβ Aggregates StructuredLogEntry rows into PerformanceMetric windows and exposes helper APIsmcpgateway/services/security_logger.pyβ Specialized logger for auth/suspicious events, computing threat scores and security audit entriesmcpgateway/services/audit_trail_service.pyβ Shared audit trail writer that records CRUD/data-access operations with change trackingmcpgateway/routers/log_search.pyβ FastAPI router exposing/api/logs/search,/trace,/security-events,/audit-trails,/performance-metricsendpointsmcpgateway/alembic/versions/k5e6f7g8h9i0_add_structured_logging_tables.pyβ Migration that createsstructured_log_entries,performance_metrics,security_events, andaudit_trailstables plus supporting indexesExample Usage
Full Response:
x-correlation-id: 6930e1f1a8b84beb904e18594bbf15dd{"request_id": "6930e1f1a8b84beb904e18594bbf15dd", ...}Correlation trace in Admin UI: