We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TypeError: '_NamespacePath' object is not subscriptable
Looks like it was related to this change: https://github.com/scoutapp/scout_apm_python/pull/668/files

I'm not entirely sure what causes this. 
We're also using a custom integration, incase thats a factor.

The particular module it is trying to load (when we get the exception) is `repoze.who.middleware`

We've not made changes to our integration, and has been breaking since, 2.21, but is also happening on 2.23.2

Below is a stack trace, starting from when we run `.install()`

Please let me know if theres anything else I can provide, I'm not sure how to debug this further

```
scout_apm.api.install(config=scout_config)
File "/usr/local/lib/python3.7/site-packages/scout_apm/compat.py", line 142, in wrapper
 return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/__init__.py", line 45, in install
 launched = CoreAgentManager().launch()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 49, in launch
 self.download()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 58, in download
 self.downloader.download()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 161, in download
 downloaded = self.download_package()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py", line 209, in download_package
 "GET", full_url, preload_content=False, timeout=10.0, retries=3
File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 75, in request
 method, url, fields=fields, headers=headers, **urlopen_kw
File "/usr/local/lib/python3.7/site-packages/urllib3/request.py", line 96, in request_encode_url
 return self.urlopen(method, url, **extra_kw)
File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 375, in urlopen
 response = conn.urlopen(method, u.request_uri, **kw)
File "/usr/local/lib/python3.7/site-packages/scout_apm/instruments/urllib3.py", line 68, in wrapped_urlopen
 return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.7/contextlib.py", line 119, in __exit__
 next(self.gen)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 134, in span
 self.stop_span()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 122, in stop_span
 stopping_span.annotate()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 258, in annotate
 self.capture_backtrace()
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py", line 293, in capture_backtrace
 self.tag("stack", backtrace.capture_backtrace())
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 122, in capture_backtrace
 return list(itertools.islice(walker, LIMIT))
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 24, in filter_frames
 for frame in frames:
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 84, in backtrace_walker
 yield {"file": filepath(frame), "line": lineno, "function": name}
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 63, in filepath
 return module_filepath(module, filepath)
File "/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py", line 40, in module_filepath
 module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]
TypeError: '_NamespacePath' object is not subscriptable
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/scout_apm/core/backtrace.py`
Content:
```
1 # coding=utf-8
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 
4 import itertools
5 import os
6 import sys
7 import sysconfig
8 import traceback
9 import warnings
10 from logging import getLogger
11 
12 logger = getLogger(__name__)
13 
14 # Maximum non-Scout frames to target retrieving
15 LIMIT = 50
16 # How many upper frames from inside Scout to ignore
17 IGNORED = 1
18 
19 
20 def filter_frames(frames):
21     """Filter the stack trace frames down to non-library code."""
22     paths = sysconfig.get_paths()
23     library_paths = {paths["purelib"], paths["platlib"]}
24     for frame in frames:
25         if not any(frame["file"].startswith(exclusion) for exclusion in library_paths):
26             yield frame
27 
28 
29 def module_filepath(module, filepath):
30     """Get the filepath relative to the base module."""
31     root_module_name = module.split(".", 1)[0]
32     if root_module_name == module:
33         return os.path.basename(filepath)
34 
35     root_module = sys.modules[root_module_name]
36     if root_module.__file__:
37         module_dir = root_module.__file__.rsplit(os.sep, 2)[0]
38     elif root_module.__path__:
39         # Default to using the first path specified for the module.
40         module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]
41         if len(root_module.__path__) > 1:
42             logger.debug(
43                 "{} has {} paths. Use the first and ignore the rest.".format(
44                     root_module, len(root_module.__path__)
45                 )
46             )
47     else:
48         # If the file path don't exist, then return the full path.
49         return filepath
50     return filepath.split(module_dir, 1)[-1].lstrip(os.sep)
51 
52 
53 def filepath(frame):
54     """Get the filepath for frame."""
55     module = frame.f_globals.get("__name__", None)
56     filepath = frame.f_code.co_filename
57 
58     if filepath.endswith(".pyc"):
59         filepath = filepath[:-1]
60 
61     if not module:
62         return filepath
63     return module_filepath(module, filepath)
64 
65 
66 if sys.version_info >= (3, 5):
67 
68     def stacktrace_walker(tb):
69         """Iterate over each frame of the stack downards for exceptions."""
70         for frame, lineno in traceback.walk_tb(tb):
71             name = frame.f_code.co_name
72             yield {"file": filepath(frame), "line": lineno, "function": name}
73 
74     def backtrace_walker():
75         """Iterate over each frame of the stack upwards.
76 
77         Taken from python3/traceback.ExtractSummary.extract to support
78         iterating over the entire stack, but without creating a large
79         data structure.
80         """
81         start_frame = sys._getframe().f_back
82         for frame, lineno in traceback.walk_stack(start_frame):
83             name = frame.f_code.co_name
84             yield {"file": filepath(frame), "line": lineno, "function": name}
85 
86 
87 else:
88 
89     def stacktrace_walker(tb):
90         """Iterate over each frame of the stack downards for exceptions."""
91         while tb is not None:
92             lineno = tb.tb_lineno
93             name = tb.tb_frame.f_code.co_name
94             yield {
95                 "file": filepath(tb.tb_frame),
96                 "line": lineno,
97                 "function": name,
98             }
99             tb = tb.tb_next
100 
101     def backtrace_walker():
102         """Iterate over each frame of the stack upwards.
103 
104         Taken from python2.7/traceback.extract_stack to support iterating
105         over the entire stack, but without creating a large data structure.
106         """
107         try:
108             raise ZeroDivisionError
109         except ZeroDivisionError:
110             # Get the current frame
111             frame = sys.exc_info()[2].tb_frame.f_back
112 
113         while frame is not None:
114             lineno = frame.f_lineno
115             name = frame.f_code.co_name
116             yield {"file": filepath(frame), "line": lineno, "function": name}
117             frame = frame.f_back
118 
119 
120 def capture_backtrace():
121     walker = filter_frames(backtrace_walker())
122     return list(itertools.islice(walker, LIMIT))
123 
124 
125 def capture_stacktrace(tb):
126     walker = stacktrace_walker(tb)
127     return list(reversed(list(itertools.islice(walker, LIMIT))))
128 
129 
130 def capture():
131     warnings.warn(
132         "capture is deprecated, instead use capture_backtrace instead.",
133         DeprecationWarning,
134         2,
135     )
136     return capture_backtrace()
137
```
--- 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()

```

diff --git a/src/scout_apm/core/backtrace.py b/src/scout_apm/core/backtrace.py
--- a/src/scout_apm/core/backtrace.py
+++ b/src/scout_apm/core/backtrace.py
@@ -32,22 +32,27 @@
     if root_module_name == module:
         return os.path.basename(filepath)
 
+    module_dir = None
     root_module = sys.modules[root_module_name]
-    if root_module.__file__:
-        module_dir = root_module.__file__.rsplit(os.sep, 2)[0]
-    elif root_module.__path__:
-        # Default to using the first path specified for the module.
-        module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]
-        if len(root_module.__path__) > 1:
-            logger.debug(
-                "{} has {} paths. Use the first and ignore the rest.".format(
-                    root_module, len(root_module.__path__)
+    try:
+        if root_module.__file__:
+            module_dir = root_module.__file__.rsplit(os.sep, 2)[0]
+        elif root_module.__path__ and isinstance(root_module.__path__, (list, tuple)):
+            # Default to using the first path specified for the module.
+            module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]
+            if len(root_module.__path__) > 1:
+                logger.debug(
+                    "{} has {} paths. Use the first and ignore the rest.".format(
+                        root_module, len(root_module.__path__)
+                    )
                 )
-            )
-    else:
-        # If the file path don't exist, then return the full path.
-        return filepath
-    return filepath.split(module_dir, 1)[-1].lstrip(os.sep)
+    except Exception as exc:
+        logger.debug(
+            "Error processing module {} and filepath {}".format(root_module, filepath),
+            exc_info=exc,
+        )
+
+    return filepath.split(module_dir, 1)[-1].lstrip(os.sep) if module_dir else filepath
 
 
 def filepath(frame):

{"golden_diff": "diff --git a/src/scout_apm/core/backtrace.py b/src/scout_apm/core/backtrace.py\n--- a/src/scout_apm/core/backtrace.py\n+++ b/src/scout_apm/core/backtrace.py\n@@ -32,22 +32,27 @@\n     if root_module_name == module:\n         return os.path.basename(filepath)\n \n+    module_dir = None\n     root_module = sys.modules[root_module_name]\n-    if root_module.__file__:\n-        module_dir = root_module.__file__.rsplit(os.sep, 2)[0]\n-    elif root_module.__path__:\n-        # Default to using the first path specified for the module.\n-        module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]\n-        if len(root_module.__path__) > 1:\n-            logger.debug(\n-                \"{} has {} paths. Use the first and ignore the rest.\".format(\n-                    root_module, len(root_module.__path__)\n+    try:\n+        if root_module.__file__:\n+            module_dir = root_module.__file__.rsplit(os.sep, 2)[0]\n+        elif root_module.__path__ and isinstance(root_module.__path__, (list, tuple)):\n+            # Default to using the first path specified for the module.\n+            module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]\n+            if len(root_module.__path__) > 1:\n+                logger.debug(\n+                    \"{} has {} paths. Use the first and ignore the rest.\".format(\n+                        root_module, len(root_module.__path__)\n+                    )\n                 )\n-            )\n-    else:\n-        # If the file path don't exist, then return the full path.\n-        return filepath\n-    return filepath.split(module_dir, 1)[-1].lstrip(os.sep)\n+    except Exception as exc:\n+        logger.debug(\n+            \"Error processing module {} and filepath {}\".format(root_module, filepath),\n+            exc_info=exc,\n+        )\n+\n+    return filepath.split(module_dir, 1)[-1].lstrip(os.sep) if module_dir else filepath\n \n \n def filepath(frame):\n", "issue": "TypeError: '_NamespacePath' object is not subscriptable\nLooks like it was related to this change: https://github.com/scoutapp/scout_apm_python/pull/668/files\r\n\r\nI'm not entirely sure what causes this. \r\nWe're also using a custom integration, incase thats a factor.\r\n\r\nThe particular module it is trying to load (when we get the exception) is `repoze.who.middleware`\r\n\r\nWe've not made changes to our integration, and has been breaking since, 2.21, but is also happening on 2.23.2\r\n\r\nBelow is a stack trace, starting from when we run `.install()`\r\n\r\nPlease let me know if theres anything else I can provide, I'm not sure how to debug this further\r\n\r\n```\r\nscout_apm.api.install(config=scout_config)\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/compat.py\", line 142, in wrapper\r\n return func(*args, **kwargs)\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/__init__.py\", line 45, in install\r\n launched = CoreAgentManager().launch()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py\", line 49, in launch\r\n self.download()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py\", line 58, in download\r\n self.downloader.download()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py\", line 161, in download\r\n downloaded = self.download_package()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/agent/manager.py\", line 209, in download_package\r\n \"GET\", full_url, preload_content=False, timeout=10.0, retries=3\r\nFile \"/usr/local/lib/python3.7/site-packages/urllib3/request.py\", line 75, in request\r\n method, url, fields=fields, headers=headers, **urlopen_kw\r\nFile \"/usr/local/lib/python3.7/site-packages/urllib3/request.py\", line 96, in request_encode_url\r\n return self.urlopen(method, url, **extra_kw)\r\nFile \"/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py\", line 375, in urlopen\r\n response = conn.urlopen(method, u.request_uri, **kw)\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/instruments/urllib3.py\", line 68, in wrapped_urlopen\r\n return wrapped(*args, **kwargs)\r\nFile \"/usr/local/lib/python3.7/contextlib.py\", line 119, in __exit__\r\n next(self.gen)\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py\", line 134, in span\r\n self.stop_span()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py\", line 122, in stop_span\r\n stopping_span.annotate()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py\", line 258, in annotate\r\n self.capture_backtrace()\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/tracked_request.py\", line 293, in capture_backtrace\r\n self.tag(\"stack\", backtrace.capture_backtrace())\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py\", line 122, in capture_backtrace\r\n return list(itertools.islice(walker, LIMIT))\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py\", line 24, in filter_frames\r\n for frame in frames:\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py\", line 84, in backtrace_walker\r\n yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py\", line 63, in filepath\r\n return module_filepath(module, filepath)\r\nFile \"/usr/local/lib/python3.7/site-packages/scout_apm/core/backtrace.py\", line 40, in module_filepath\r\n module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]\r\nTypeError: '_NamespacePath' object is not subscriptable\r\n```\n", "before_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport itertools\nimport os\nimport sys\nimport sysconfig\nimport traceback\nimport warnings\nfrom logging import getLogger\n\nlogger = getLogger(__name__)\n\n# Maximum non-Scout frames to target retrieving\nLIMIT = 50\n# How many upper frames from inside Scout to ignore\nIGNORED = 1\n\n\ndef filter_frames(frames):\n    \"\"\"Filter the stack trace frames down to non-library code.\"\"\"\n    paths = sysconfig.get_paths()\n    library_paths = {paths[\"purelib\"], paths[\"platlib\"]}\n    for frame in frames:\n        if not any(frame[\"file\"].startswith(exclusion) for exclusion in library_paths):\n            yield frame\n\n\ndef module_filepath(module, filepath):\n    \"\"\"Get the filepath relative to the base module.\"\"\"\n    root_module_name = module.split(\".\", 1)[0]\n    if root_module_name == module:\n        return os.path.basename(filepath)\n\n    root_module = sys.modules[root_module_name]\n    if root_module.__file__:\n        module_dir = root_module.__file__.rsplit(os.sep, 2)[0]\n    elif root_module.__path__:\n        # Default to using the first path specified for the module.\n        module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]\n        if len(root_module.__path__) > 1:\n            logger.debug(\n                \"{} has {} paths. Use the first and ignore the rest.\".format(\n                    root_module, len(root_module.__path__)\n                )\n            )\n    else:\n        # If the file path don't exist, then return the full path.\n        return filepath\n    return filepath.split(module_dir, 1)[-1].lstrip(os.sep)\n\n\ndef filepath(frame):\n    \"\"\"Get the filepath for frame.\"\"\"\n    module = frame.f_globals.get(\"__name__\", None)\n    filepath = frame.f_code.co_filename\n\n    if filepath.endswith(\".pyc\"):\n        filepath = filepath[:-1]\n\n    if not module:\n        return filepath\n    return module_filepath(module, filepath)\n\n\nif sys.version_info >= (3, 5):\n\n    def stacktrace_walker(tb):\n        \"\"\"Iterate over each frame of the stack downards for exceptions.\"\"\"\n        for frame, lineno in traceback.walk_tb(tb):\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n\n    def backtrace_walker():\n        \"\"\"Iterate over each frame of the stack upwards.\n\n        Taken from python3/traceback.ExtractSummary.extract to support\n        iterating over the entire stack, but without creating a large\n        data structure.\n        \"\"\"\n        start_frame = sys._getframe().f_back\n        for frame, lineno in traceback.walk_stack(start_frame):\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n\n\nelse:\n\n    def stacktrace_walker(tb):\n        \"\"\"Iterate over each frame of the stack downards for exceptions.\"\"\"\n        while tb is not None:\n            lineno = tb.tb_lineno\n            name = tb.tb_frame.f_code.co_name\n            yield {\n                \"file\": filepath(tb.tb_frame),\n                \"line\": lineno,\n                \"function\": name,\n            }\n            tb = tb.tb_next\n\n    def backtrace_walker():\n        \"\"\"Iterate over each frame of the stack upwards.\n\n        Taken from python2.7/traceback.extract_stack to support iterating\n        over the entire stack, but without creating a large data structure.\n        \"\"\"\n        try:\n            raise ZeroDivisionError\n        except ZeroDivisionError:\n            # Get the current frame\n            frame = sys.exc_info()[2].tb_frame.f_back\n\n        while frame is not None:\n            lineno = frame.f_lineno\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n            frame = frame.f_back\n\n\ndef capture_backtrace():\n    walker = filter_frames(backtrace_walker())\n    return list(itertools.islice(walker, LIMIT))\n\n\ndef capture_stacktrace(tb):\n    walker = stacktrace_walker(tb)\n    return list(reversed(list(itertools.islice(walker, LIMIT))))\n\n\ndef capture():\n    warnings.warn(\n        \"capture is deprecated, instead use capture_backtrace instead.\",\n        DeprecationWarning,\n        2,\n    )\n    return capture_backtrace()\n", "path": "src/scout_apm/core/backtrace.py"}], "after_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport itertools\nimport os\nimport sys\nimport sysconfig\nimport traceback\nimport warnings\nfrom logging import getLogger\n\nlogger = getLogger(__name__)\n\n# Maximum non-Scout frames to target retrieving\nLIMIT = 50\n# How many upper frames from inside Scout to ignore\nIGNORED = 1\n\n\ndef filter_frames(frames):\n    \"\"\"Filter the stack trace frames down to non-library code.\"\"\"\n    paths = sysconfig.get_paths()\n    library_paths = {paths[\"purelib\"], paths[\"platlib\"]}\n    for frame in frames:\n        if not any(frame[\"file\"].startswith(exclusion) for exclusion in library_paths):\n            yield frame\n\n\ndef module_filepath(module, filepath):\n    \"\"\"Get the filepath relative to the base module.\"\"\"\n    root_module_name = module.split(\".\", 1)[0]\n    if root_module_name == module:\n        return os.path.basename(filepath)\n\n    module_dir = None\n    root_module = sys.modules[root_module_name]\n    try:\n        if root_module.__file__:\n            module_dir = root_module.__file__.rsplit(os.sep, 2)[0]\n        elif root_module.__path__ and isinstance(root_module.__path__, (list, tuple)):\n            # Default to using the first path specified for the module.\n            module_dir = root_module.__path__[0].rsplit(os.sep, 1)[0]\n            if len(root_module.__path__) > 1:\n                logger.debug(\n                    \"{} has {} paths. Use the first and ignore the rest.\".format(\n                        root_module, len(root_module.__path__)\n                    )\n                )\n    except Exception as exc:\n        logger.debug(\n            \"Error processing module {} and filepath {}\".format(root_module, filepath),\n            exc_info=exc,\n        )\n\n    return filepath.split(module_dir, 1)[-1].lstrip(os.sep) if module_dir else filepath\n\n\ndef filepath(frame):\n    \"\"\"Get the filepath for frame.\"\"\"\n    module = frame.f_globals.get(\"__name__\", None)\n    filepath = frame.f_code.co_filename\n\n    if filepath.endswith(\".pyc\"):\n        filepath = filepath[:-1]\n\n    if not module:\n        return filepath\n    return module_filepath(module, filepath)\n\n\nif sys.version_info >= (3, 5):\n\n    def stacktrace_walker(tb):\n        \"\"\"Iterate over each frame of the stack downards for exceptions.\"\"\"\n        for frame, lineno in traceback.walk_tb(tb):\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n\n    def backtrace_walker():\n        \"\"\"Iterate over each frame of the stack upwards.\n\n        Taken from python3/traceback.ExtractSummary.extract to support\n        iterating over the entire stack, but without creating a large\n        data structure.\n        \"\"\"\n        start_frame = sys._getframe().f_back\n        for frame, lineno in traceback.walk_stack(start_frame):\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n\n\nelse:\n\n    def stacktrace_walker(tb):\n        \"\"\"Iterate over each frame of the stack downards for exceptions.\"\"\"\n        while tb is not None:\n            lineno = tb.tb_lineno\n            name = tb.tb_frame.f_code.co_name\n            yield {\n                \"file\": filepath(tb.tb_frame),\n                \"line\": lineno,\n                \"function\": name,\n            }\n            tb = tb.tb_next\n\n    def backtrace_walker():\n        \"\"\"Iterate over each frame of the stack upwards.\n\n        Taken from python2.7/traceback.extract_stack to support iterating\n        over the entire stack, but without creating a large data structure.\n        \"\"\"\n        try:\n            raise ZeroDivisionError\n        except ZeroDivisionError:\n            # Get the current frame\n            frame = sys.exc_info()[2].tb_frame.f_back\n\n        while frame is not None:\n            lineno = frame.f_lineno\n            name = frame.f_code.co_name\n            yield {\"file\": filepath(frame), \"line\": lineno, \"function\": name}\n            frame = frame.f_back\n\n\ndef capture_backtrace():\n    walker = filter_frames(backtrace_walker())\n    return list(itertools.islice(walker, LIMIT))\n\n\ndef capture_stacktrace(tb):\n    walker = stacktrace_walker(tb)\n    return list(reversed(list(itertools.islice(walker, LIMIT))))\n\n\ndef capture():\n    warnings.warn(\n        \"capture is deprecated, instead use capture_backtrace instead.\",\n        DeprecationWarning,\n        2,\n    )\n    return capture_backtrace()\n", "path": "src/scout_apm/core/backtrace.py"}]}