code: def log_call(
      telemetry_reporter: TelemetryReporter, module_name: str
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
      """Decorator to make it easier to log telemetry for function calls.
  
      Using module_name instead of introspection since it seems more robust.
  
      Example call:
  
      @log_call(telemetry_reporter=telemetry_reporter, module_name=__name__)
      def test_function() -> str:
          return "foo"
  
      """
  
      def decorator(func: Callable[P, R]) -> Callable[P, R]:
          @functools.wraps(func)
          def wrapped(*args: P.args, **kwargs: P.kwargs) -> R:
              # Not every Callable has a __name__
              function_name = getattr(func, "__name__", repr(func))
              invocation_id = f"call_{random_id()}"
              start_time = time.time()
              telemetry_reporter.log_function_start(
                  invocation_id=invocation_id,
                  module_name=module_name,
                  function_name=function_name,
              )
              exception_trace: Optional[str] = None
              try:
                  return func(*args, **kwargs)
              except Exception:
                  exception_trace = traceback.format_exc()
                  raise
              finally:
                  telemetry_reporter.log_function_end(
                      invocation_id=invocation_id,
                      module_name=module_name,
                      function_name=function_name,
                      runtime=time.time() - start_time,
                      exception_trace=exception_trace,
                  )
  
          return wrapped
  
      return decorator
  
imports: from __future__ import annotations
  import datetime
  import functools
  import logging
  import os
  import platform
  import sys
  import time
  import traceback
  import uuid
  from hashlib import sha256
  from typing import Callable, List, Optional, TypeVar
  from typing_extensions import ParamSpec
  from metricflow.random_id import random_id
  from metricflow.telemetry.handlers.handlers import TelemetryHandler, ToMemoryTelemetryHandler
  from metricflow.telemetry.handlers.python_log import PythonLoggerTelemetryHandler
  from metricflow.telemetry.models import FunctionEndEvent, FunctionStartEvent, TelemetryLevel
label_desc: Use image node_id 1 for calling a global function with example usage: log_call(telemetry_reporter, module_name) and returns: decorator, wrapped, func