eschutho commented on code in PR #26443:
URL: https://github.com/apache/superset/pull/26443#discussion_r1454160051
##########
superset/utils/decorators.py:
##########
@@ -61,6 +65,82 @@ def wrapped(*args: Any, **kwargs: Any) -> Any:
return decorate
+def logs_context(
+ context_func: Callable[..., dict[Any, Any]] | None = None,
+ **ctx_kwargs: int | str | UUID | None,
+) -> Callable[..., Any]:
+ """
+ Takes arguments and adds them to the global logs_context.
+ This is for logging purposes only and values should not be relied on or
mutated
+ """
+
+ def decorate(f: Callable[..., Any]) -> Callable[..., Any]:
+ def wrapped(*args: Any, **kwargs: Any) -> Any:
+ if not hasattr(g, "logs_context"):
+ g.logs_context = {}
+
+ # limit data that can be saved to logs_context
+ # in order to prevent antipatterns
+ available_logs_context_keys = [
Review Comment:
Yeah, that's a good question. In the SIP review we talked about trying to
limit antipatterns of people putting random data into global context so the
intention here is to use this list to limit what data can be passed in with the
decorator, but there are definitely a lot of other use cases. I have three
others on my todo list. I would suggest that if you think there's more data
that should be considered for logging, then add it to the list in a PR and
we'll see if it fits. That way we're still limiting the data that the decorator
can accept, but we're not completely limited to just the set that is here now.
How does that sound?
--
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]