Superset API function write logs but not for FAB API #36731
Replies: 1 comment
-
|
Superset API endpoints write logs because they use explicit logging decorators like FAB API endpoints (such as
Here’s a concrete example for a custom FAB API endpoint: from flask import g, request
from superset.extensions import event_logger
from flask_appbuilder.security.views import UserDBModelView
class CustomUserDBModelView(UserDBModelView):
def after_model_create(self, model):
actor = getattr(g, "user", None)
ip_address = request.headers.get("X-Forwarded-For", request.remote_addr)
event_logger.log(
user_id=actor.id if actor else None,
action="user_create",
records=[{
"actor_username": getattr(actor, "username", None),
"target_username": getattr(model, "username", None),
"ip_address": ip_address,
"details": "User created",
}],
referrer=ip_address,
)
# Repeat for after_model_change and after_model_deleteOr, for an API method: from superset.extensions import event_logger
class CustomUserRestApi(UserRestApi):
@event_logger.log_this_with_context(action="user_create", log_to_statsd=False)
def post(self):
response = super().post()
# Optionally add extra audit details here
return responseThis will ensure your FAB API actions are logged in the Superset action log UI. Let me know if you want more details or help with a specific endpoint! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I use a superset API function, log is written
But when I use a FAB API function, log is not written :


Beta Was this translation helpful? Give feedback.
All reactions