code: def _build_metrics(func_name, namespace):
      """
      Build metrics dict from function args.
  
      It assumes that function arguments is from airflow.bin.cli module's function
      and has Namespace instance where it optionally contains "dag_id", "task_id",
      and "execution_date".
  
      :param func_name: name of function
      :param namespace: Namespace instance from argparse
      :return: dict with metrics
      """
      sub_commands_to_check = {"users", "connections"}
      sensitive_fields = {"-p", "--password", "--conn-password"}
      full_command = list(sys.argv)
      sub_command = full_command[1] if len(full_command) > 1 else None
      if sub_command in sub_commands_to_check:
          for idx, command in enumerate(full_command):
              if command in sensitive_fields:
                  # For cases when password is passed as "--password xyz" (with space between key and value)
                  full_command[idx + 1] = "*" * 8
              else:
                  # For cases when password is passed as "--password=xyz" (with '=' between key and value)
                  for sensitive_field in sensitive_fields:
                      if command.startswith(f"{sensitive_field}="):
                          full_command[
                              idx
                          ] = f'{sensitive_field}={"*" * 8}'
  
      metrics = {
          "sub_command": func_name,
          "start_datetime": datetime.utcnow(),
          "full_command": f"{full_command}",
          "user": getuser(),
      }
  
      if not isinstance(namespace, Namespace):
          raise ValueError(
              f"namespace argument should be argparse.Namespace instance, but is {type(namespace)}"
          )
      tmp_dic = vars(namespace)
      metrics["dag_id"] = tmp_dic.get("dag_id")
      metrics["task_id"] = tmp_dic.get("task_id")
      metrics["execution_date"] = tmp_dic.get("execution_date")
      metrics["host_name"] = socket.gethostname()
  
      return metrics
  
imports: from __future__ import annotations
  import functools
  import logging
  import os
  import socket
  import sys
  import threading
  import traceback
  import warnings
  from argparse import Namespace
  from datetime import datetime
  from pathlib import Path
  from typing import TYPE_CHECKING, Callable, TypeVar, cast
  import re2
  from sqlalchemy import select
  from airflow import settings
  from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
  from airflow.utils import cli_action_loggers
  from airflow.utils.log.non_caching_file_handler import NonCachingFileHandler
  from airflow.utils.platform import getuser, is_terminal_support_colors
  from airflow.utils.session import NEW_SESSION, provide_session
label_desc: Use image node_id 3 for calling a global function with example usage: _build_metrics(func_name, namespace) and returns: metrics