code: def test_delayed_metrics_ledger_keyed():
      l1 = metrics.DelayedMetricsLedger()
      l2 = metrics.DelayedMetricsLedger()
      l3 = metrics.DelayedMetricsLedger()
  
      with l1.record(key="x"), l2.record(key="y"):
          metrics.context_meter.digest_metric("l1", 1, "u")
          with l3.record(key="x"):
              metrics.context_meter.digest_metric("l2", 2, "u")
          metrics.context_meter.digest_metric("l3", 3, "u")
  
      assert l1.metrics == [("l1", 1, "u"), ("l3", 3, "u")]
      assert l2.metrics == [
          ("l1", 1, "u"),
          ("l2", 2, "u"),
          ("l3", 3, "u"),
      ]
      assert l3.metrics == [("l2", 2, "u")]
  
imports: from __future__ import annotations
  import math
  import pickle
  import threading
  import time
  import pytest
  from distributed import metrics
  from distributed.compatibility import WINDOWS
  from distributed.utils import offload
  from distributed.utils_test import gen_test
label_desc: Use image node_id 16 for calling a global function with example usage: test_delayed_metrics_ledger_keyed() without return types