code: def monitor(
      *,
      name: Optional[str] = None,
      documentation: Optional[str] = None,
  ):
      """
      Decorator and context manager that allows monitoring of an Executor.
  
      You can access these metrics by enabling
      monitoring on your Executor. It will track the time spent calling the function and the number of times it has been
      called. Under the hood it will create a prometheus Summary : https://prometheus.io/docs/practices/histograms/.
  
      EXAMPLE USAGE
  
          As decorator
  
          .. code-block:: python
  
              from jina import Executor, monitor
  
  
              class MyExecutor(Executor):
                  @requests  # `@requests` are monitored automatically
                  def foo(self, docs, *args, **kwargs):
                      ...
                      self.my_method()
                      ...
  
                  # custom metric for `my_method`
                  @monitor(name='metric_name', documentation='useful information goes here')
                  def my_method(self):
                      ...
  
          As context manager
  
          .. code-block:: python
  
              from jina import Executor, requests
  
  
              class MyExecutor(Executor):
                  @requests  # `@requests` are monitored automatically
                  def foo(self, docs, *args, **kwargs):
                      ...
                      # custom metric for code block
                      with self.monitor('metric_name', 'useful information goes here'):
                          docs = process(docs)
  
          To enable the defined :meth:`monitor` blocks, enable monitoring on the Flow level
  
          .. code-block:: python
  
              from jina import Flow
  
              f = Flow(monitoring=True, port_monitoring=9090).add(
                  uses=MyExecutor, port_monitoring=9091
              )
              with f:
                  ...
  
      :warning: Don't use this decorator in combination with the @request decorator. @request's are already monitored.
  
      :param name: the name of the metrics, by default it is based on the name of the method it decorates
      :param documentation:  the description of the metrics, by default it is based on the name of the method it decorates
  
      :return: decorator which takes as an input a single callable
      """
  
      def _decorator(func: Callable):
          name_ = name if name else f"{func.__name__}_seconds"
          documentation_ = (
              documentation
              if documentation
              else f"Time spent calling method {func.__name__}"
          )
  
          @functools.wraps(func)
          def _f(self, *args, **kwargs):
              with self.monitor(name_, documentation_):
                  return func(self, *args, **kwargs)
  
          return _f
  
      return _decorator
  
file_path: jina/jina/serve/executors/decorators.py
imports: import functools
  import inspect
  import os
  from pathlib import Path
  from typing import Callable, Dict, List, Optional, Sequence, Type, Union
  from jina._docarray import Document, DocumentArray, docarray_v2
  from jina.constants import __cache_path__
  from jina.helper import is_generator, iscoroutinefunction
  from jina.importer import ImportExtensions
label_desc: Use image node_id 7 for calling a global function with example usage: monitor() and returns: _decorator, _f, func