class_docstr: Worker extension for spans support
class_docstr_tok: ["Worker","extension","for","spans","support"]
docstr: Make a local copy of Worker.digests_total_since_heartbeat. We can't just
  parse it directly in heartbeat() as the event loop may be yielded between its
  call and `self.worker.digests_total_since_heartbeat.clear()`, causing the
  scheduler to become misaligned with the workers.
docstr_tok: ["Make","a","local","copy","of","Worker.digests_total_since_heartbeat",".","We","ca","n't","just","parse","it","directly","in","heartbeat","(",")","as","the","event","loop","may","be","yielded","between","its","call","and","`","self.worker.digests_total_since_heartbeat.clear","(",")","`",",","causing","the","scheduler","to","become","misaligned","with","the","workers","."]
code: def collect_digests(self) -> None:
      """Make a local copy of Worker.digests_total_since_heartbeat. We can't just
      parse it directly in heartbeat() as the event loop may be yielded between its
      call and `self.worker.digests_total_since_heartbeat.clear()`, causing the
      scheduler to become misaligned with the workers.
      """
      # Note: this method may be called spuriously by Worker._register_with_scheduler,
      # but when it does it's guaranteed not to find any metrics
      assert not self.digests_total_since_heartbeat
      self.digests_total_since_heartbeat = {
          k: v
          for k, v in self.worker.digests_total_since_heartbeat.items()
          if isinstance(k, tuple) and k[0] in CONTEXTS_WITH_SPAN_ID
      }
  
imports: from __future__ import annotations
  import uuid
  import weakref
  from collections import defaultdict
  from collections.abc import Hashable, Iterable, Iterator
  from contextlib import contextmanager
  from itertools import islice
  from typing import TYPE_CHECKING, Any
  import dask.config
  from dask.typing import Key
  from distributed.collections import sum_mappings
  from distributed.itertools import ffill
  from distributed.metrics import time
label_desc: Use image node_id 2 for calling the SpansWorkerExtension obj's underlying member method code with example usage: obj.collect_digests() without return types