code: 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 = [
                  "slice_id",
                  "dashboard_id",
                  "dataset_id",
                  "execution_id",
                  "report_schedule_id",
              ]
              # set value from kwargs from
              # wrapper function if it exists
              # e.g. @logs_context()
              #      def my_func(slice_id=None, **kwargs)
              #
              #      my_func(slice_id=2)
              logs_context_data = {
                  key: val
                  for key, val in kwargs.items()
                  if key in available_logs_context_keys
                  if val is not None
              }
  
              try:
                  # if keys are passed in to decorator directly, add them to logs_context
                  # by overriding values from kwargs
                  # e.g. @logs_context(slice_id=1, dashboard_id=1)
                  logs_context_data.update(
                      {
                          key: ctx_kwargs.get(key)
                          for key in available_logs_context_keys
                          if ctx_kwargs.get(key) is not None
                      }
                  )
  
                  if context_func is not None:
                      # if a context function is passed in, call it and add the
                      # returned values to logs_context
                      # context_func=lambda *args, **kwargs: {
                      # "slice_id": 1, "dashboard_id": 1
                      # }
                      logs_context_data.update(
                          {
                              key: value
                              for key, value in context_func(
                                  *args, **kwargs
                              ).items()
                              if key in available_logs_context_keys
                              if value is not None
                          }
                      )
  
              except (TypeError, KeyError, AttributeError):
                  # do nothing if the key doesn't exist
                  # or context is not callable
                  logger.warning(
                      "Invalid data was passed to the logs context decorator"
                  )
  
              g.logs_context.update(logs_context_data)
              return f(*args, **kwargs)
  
          return wrapped
  
      return decorate
  
file_path: superset/superset/utils/decorators.py
imports: from __future__ import annotations
  import logging
  import time
  from collections.abc import Iterator
  from contextlib import contextmanager
  from typing import Any, Callable, TYPE_CHECKING
  from uuid import UUID
  from flask import current_app, g, Response
  from superset.utils import core
  from superset.utils.dates import now_as_float
label_desc: Use image node_id 2 for calling a global function with example usage: logs_context(context_func) and returns: decorate, wrapped, f