aminghadersohi commented on code in PR #41921:
URL: https://github.com/apache/superset/pull/41921#discussion_r3649029864
##########
superset/mcp_service/middleware.py:
##########
@@ -132,6 +138,29 @@ def _sanitize_error_for_logging(error: Exception) -> str:
return error_str
+def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
+ """Invoke the operator-configured ``MCP_ERROR_HOOK``, if any.
+
+ Kept vendor-neutral (no ``sentry_sdk`` import here) so the OSS repo has
+ no hard dependency on any particular error tracker — operators wire
+ their own hook (e.g. calling ``sentry_sdk.capture_exception``) via
+ ``MCP_ERROR_HOOK`` in ``superset_config.py``. Hook failures are logged
+ and swallowed; they must never affect the MCP response.
+ """
+ try:
+ from superset.mcp_service.flask_singleton import get_flask_app
+
+ hook = get_flask_app().config.get("MCP_ERROR_HOOK")
+ except Exception: # noqa: BLE001
+ return
+ if hook is None:
+ return
+ try:
+ hook(error, hook_context)
Review Comment:
Declining this one as a documented, intentional contract rather than a bug.
The synchronous execution is deliberate and already called out explicitly in
both the config docstring (`mcp_config.py`) and `PRODUCTION.md`: "The hook runs
synchronously on the asyncio event loop, so a blocking hook stalls all
in-flight tool handling — hand events to a background transport rather than
doing network I/O inline." The reference Sentry wiring uses
`capture_exception`, which already enqueues to a background worker.
The hook is operator-provided config (the operator owns deployment-time
choices per the threat model), and this behavior was reviewed and accepted by
@rebenitez1802 in the round-2 pass. Offloading it ourselves — e.g.
`run_in_executor` — would be a net negative here: it fires-and-forgets, so hook
exceptions could no longer be caught by our surrounding try/except and logged,
we'd lose the ContextVar/Flask-context the hook may read, and it changes
ordering guarantees. The clean contract is "keep the hook fast; if it must do
I/O, hand off to your own background transport," which is exactly what's
documented. No code change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]