code: def track_serve(
      svc: Service,
      *,
      production: bool = False,
      from_server_api: bool | None = None,
      serve_kind: str = "http",
      component: str = "standalone",
      metrics_client: PrometheusClient = Provide[
          BentoMLContainer.metrics_client
      ],
      serve_info: ServeInfo = Provide[BentoMLContainer.serve_info],
  ) -> t.Generator[None, None, None]:
      if do_not_track():
          yield
          return
  
      if from_server_api is None:
          from_server_api = _bentoml_serve_from_server_api()
  
      _track_serve_init(
          svc=svc,
          production=production,
          serve_kind=serve_kind,
          from_server_api=from_server_api,
      )
  
      if _usage_event_debugging():
          tracking_interval = 5
      else:
          tracking_interval = (
              SERVE_USAGE_TRACKING_INTERVAL_SECONDS  # pragma: no cover
          )
  
      stop_event = threading.Event()
  
      @silent
      def loop() -> t.NoReturn:  # type: ignore
          last_tracked_timestamp: datetime = (
              serve_info.serve_started_timestamp
          )
          while not stop_event.wait(
              tracking_interval
          ):  # pragma: no cover
              now = datetime.now(timezone.utc)
              event_properties = ServeUpdateEvent(
                  serve_id=serve_info.serve_id,
                  production=production,
                  # Note that we are currently only have two tracking jobs: http and grpc
                  serve_kind=serve_kind,
                  # Current accept components are "standalone", "api_server" and "runner"
                  component=component,
                  # check if serve is running from server API or just normal CLI
                  serve_from_server_api=from_server_api,
                  triggered_at=now,
                  duration_in_seconds=int(
                      (now - last_tracked_timestamp).total_seconds()
                  ),
                  metrics=get_metrics_report(
                      metrics_client, serve_kind=serve_kind
                  ),
              )
              last_tracked_timestamp = now
              track(event_properties)
  
      tracking_thread = threading.Thread(target=loop, daemon=True)
      try:
          tracking_thread.start()
          yield
      finally:
          stop_event.set()
          tracking_thread.join()
  
imports: from __future__ import annotations
  import contextlib
  import logging
  import os
  import secrets
  import threading
  import typing
  from datetime import datetime
  from datetime import timezone
  from functools import lru_cache
  from functools import wraps
  from typing import TYPE_CHECKING
  import attr
  import httpx
  from simple_di import Provide
  from simple_di import inject
  from ...configuration import get_debug_mode
  from ...configuration.containers import BentoMLContainer
  from ...utils import compose
  from .schemas import CommonProperties
  from .schemas import EventMeta
  from .schemas import ServeInitEvent
  from .schemas import ServeUpdateEvent
  from .schemas import TrackingPayload
label_desc: Use image node_id 11 for calling a global function with example usage: track_serve(svc) without return types