prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Exception raised with sizeof of some spans
  With `master`:
  
  ```
  Exception in thread AgentWriter:
  Traceback (most recent call last):
    File "/opt/dogweb/pyenv/versions/2.7.12/lib/python2.7/threading.py", line 801, in __bootstrap_inner
      self.run()
    File "/opt/dogweb/pyenv/versions/2.7.12/lib/python2.7/threading.py", line 754, in run
      self.__target(*self.__args, **self.__kwargs)
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/_worker.py", line 67, in _target
      self.run_periodic()
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/internal/writer.py", line 65, in flush_queue
      traces_queue_size = sum(map(sizeof.sizeof, traces))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 31, in sizeof
      return _sizeof(o)
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 29, in _sizeof
      return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 29, in _sizeof
      return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 29, in _sizeof
      return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 29, in _sizeof
      return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 29, in _sizeof
      return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
    File "/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py", line 8, in <genexpr>
      return (getattr(o, slot) for slot in o.__slots__)
  AttributeError: rate_limit
  ```
  
  Might be an issue where the attribute is declared in `__slots__` but not set.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ddtrace/utils/sizeof.py`
  Content:
  ```
  1 import collections
  2 import sys
  3 from itertools import chain
  4 
  5 
  6 def iter_object(o):
  7     if hasattr(o, '__slots__'):
  8         return (getattr(o, slot) for slot in o.__slots__)
  9     elif hasattr(o, '__dict__'):
  10         return list(o.__dict__.items())
  11     elif isinstance(o, dict):
  12         # Make a copy to avoid corruption
  13         return chain.from_iterable(list(o.items()))
  14     elif isinstance(o, (list, set, frozenset, tuple, collections.deque)):
  15         # Make a copy to avoid corruption
  16         return iter(list(o))
  17     return []
  18 
  19 
  20 def sizeof(o):
  21     """Returns the approximate memory footprint an object and all of its contents."""
  22     seen = set()
  23 
  24     def _sizeof(o):
  25         # do not double count the same object
  26         if id(o) in seen:
  27             return 0
  28         seen.add(id(o))
  29         return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))
  30 
  31     return _sizeof(o)
  32
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ddtrace/utils/sizeof.py b/ddtrace/utils/sizeof.py
  --- a/ddtrace/utils/sizeof.py
  +++ b/ddtrace/utils/sizeof.py
  @@ -2,10 +2,16 @@
   import sys
   from itertools import chain
   
  +_UNSET = object()
  +
   
   def iter_object(o):
       if hasattr(o, '__slots__'):
  -        return (getattr(o, slot) for slot in o.__slots__)
  +        return (
  +            s
  +            for s in (getattr(o, slot, _UNSET) for slot in o.__slots__)
  +            if s != _UNSET
  +        )
       elif hasattr(o, '__dict__'):
           return list(o.__dict__.items())
       elif isinstance(o, dict):
  
verification_info: {"golden_diff": "diff --git a/ddtrace/utils/sizeof.py b/ddtrace/utils/sizeof.py\n--- a/ddtrace/utils/sizeof.py\n+++ b/ddtrace/utils/sizeof.py\n@@ -2,10 +2,16 @@\n import sys\n from itertools import chain\n \n+_UNSET = object()\n+\n \n def iter_object(o):\n     if hasattr(o, '__slots__'):\n-        return (getattr(o, slot) for slot in o.__slots__)\n+        return (\n+            s\n+            for s in (getattr(o, slot, _UNSET) for slot in o.__slots__)\n+            if s != _UNSET\n+        )\n     elif hasattr(o, '__dict__'):\n         return list(o.__dict__.items())\n     elif isinstance(o, dict):\n", "issue": "Exception raised with sizeof of some spans\nWith `master`:\r\n\r\n```\r\nException in thread AgentWriter:\r\nTraceback (most recent call last):\r\n  File \"/opt/dogweb/pyenv/versions/2.7.12/lib/python2.7/threading.py\", line 801, in __bootstrap_inner\r\n    self.run()\r\n  File \"/opt/dogweb/pyenv/versions/2.7.12/lib/python2.7/threading.py\", line 754, in run\r\n    self.__target(*self.__args, **self.__kwargs)\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/_worker.py\", line 67, in _target\r\n    self.run_periodic()\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/internal/writer.py\", line 65, in flush_queue\r\n    traces_queue_size = sum(map(sizeof.sizeof, traces))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 31, in sizeof\r\n    return _sizeof(o)\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 29, in _sizeof\r\n    return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 29, in _sizeof\r\n    return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 29, in _sizeof\r\n    return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 29, in _sizeof\r\n    return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 29, in _sizeof\r\n    return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\r\n  File \"/opt/dogweb/lib/python2.7/site-packages/ddtrace/utils/sizeof.py\", line 8, in <genexpr>\r\n    return (getattr(o, slot) for slot in o.__slots__)\r\nAttributeError: rate_limit\r\n```\r\n\r\nMight be an issue where the attribute is declared in `__slots__` but not set.\n", "before_files": [{"content": "import collections\nimport sys\nfrom itertools import chain\n\n\ndef iter_object(o):\n    if hasattr(o, '__slots__'):\n        return (getattr(o, slot) for slot in o.__slots__)\n    elif hasattr(o, '__dict__'):\n        return list(o.__dict__.items())\n    elif isinstance(o, dict):\n        # Make a copy to avoid corruption\n        return chain.from_iterable(list(o.items()))\n    elif isinstance(o, (list, set, frozenset, tuple, collections.deque)):\n        # Make a copy to avoid corruption\n        return iter(list(o))\n    return []\n\n\ndef sizeof(o):\n    \"\"\"Returns the approximate memory footprint an object and all of its contents.\"\"\"\n    seen = set()\n\n    def _sizeof(o):\n        # do not double count the same object\n        if id(o) in seen:\n            return 0\n        seen.add(id(o))\n        return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\n\n    return _sizeof(o)\n", "path": "ddtrace/utils/sizeof.py"}], "after_files": [{"content": "import collections\nimport sys\nfrom itertools import chain\n\n_UNSET = object()\n\n\ndef iter_object(o):\n    if hasattr(o, '__slots__'):\n        return (\n            s\n            for s in (getattr(o, slot, _UNSET) for slot in o.__slots__)\n            if s != _UNSET\n        )\n    elif hasattr(o, '__dict__'):\n        return list(o.__dict__.items())\n    elif isinstance(o, dict):\n        # Make a copy to avoid corruption\n        return chain.from_iterable(list(o.items()))\n    elif isinstance(o, (list, set, frozenset, tuple, collections.deque)):\n        # Make a copy to avoid corruption\n        return iter(list(o))\n    return []\n\n\ndef sizeof(o):\n    \"\"\"Returns the approximate memory footprint an object and all of its contents.\"\"\"\n    seen = set()\n\n    def _sizeof(o):\n        # do not double count the same object\n        if id(o) in seen:\n            return 0\n        seen.add(id(o))\n        return sys.getsizeof(o) + sum(map(_sizeof, iter_object(o)))\n\n    return _sizeof(o)\n", "path": "ddtrace/utils/sizeof.py"}]}