We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error with the scout add-on in Heroku
With version 2.14.1 of this package, I encounter the following error:
`  File "/code/nluproxy/__init__.py", line 3, in <module>

    from .celery import app as celery_app

  File "/code/nluproxy/celery.py", line 12, in <module>

    scout_apm.celery.install(app)

  File "/usr/local/lib/python3.7/site-packages/scout_apm/celery.py", line 58, in install

    installed = scout_apm.core.install()

  File "/usr/local/lib/python3.7/site-packages/scout_apm/compat.py", line 132, in wrapper

    return func(*args, **kwargs)

  File "/usr/local/lib/python3.7/site-packages/scout_apm/core/__init__.py", line 46, in install

    report_app_metadata()

  File "/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py", line 17, in report_app_metadata

    event_value=get_metadata(),

  File "/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py", line 37, in get_metadata

    "libraries": get_python_packages_versions(),

  File "/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py", line 60, in get_python_packages_versions

    for distribution in distributions()

TypeError: '<' not supported between instances of 'NoneType' and 'str'

`

--- 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/metadata.py`
Content:
```
1 # coding=utf-8
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 
4 import datetime as dt
5 import sys
6 from os import getpid
7 
8 from scout_apm.core.commands import ApplicationEvent
9 from scout_apm.core.config import scout_config
10 from scout_apm.core.socket import CoreAgentSocketThread
11 
12 
13 def report_app_metadata():
14     CoreAgentSocketThread.send(
15         ApplicationEvent(
16             event_type="scout.metadata",
17             event_value=get_metadata(),
18             source="Pid: " + str(getpid()),
19             timestamp=dt.datetime.utcnow(),
20         )
21     )
22 
23 
24 def get_metadata():
25     data = {
26         "language": "python",
27         "language_version": "{}.{}.{}".format(*sys.version_info[:3]),
28         "server_time": dt.datetime.utcnow().isoformat() + "Z",
29         "framework": scout_config.value("framework"),
30         "framework_version": scout_config.value("framework_version"),
31         "environment": "",
32         "app_server": scout_config.value("app_server"),
33         "hostname": scout_config.value("hostname"),
34         "database_engine": "",
35         "database_adapter": "",
36         "application_name": "",
37         "libraries": get_python_packages_versions(),
38         "paas": "",
39         "application_root": scout_config.value("application_root"),
40         "scm_subdirectory": scout_config.value("scm_subdirectory"),
41         "git_sha": scout_config.value("revision_sha"),
42     }
43     # Deprecated - see #327:
44     data["version"] = data["language_version"]
45     return data
46 
47 
48 def get_python_packages_versions():
49     try:
50         if sys.version_info >= (3, 8):
51             from importlib.metadata import distributions
52         else:
53             from importlib_metadata import distributions
54     except ImportError:
55         # For some reason it is unavailable
56         return []
57 
58     return sorted(
59         (distribution.metadata["Name"], distribution.metadata["Version"])
60         for distribution in distributions()
61     )
62
```
--- 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/metadata.py b/src/scout_apm/core/metadata.py
--- a/src/scout_apm/core/metadata.py
+++ b/src/scout_apm/core/metadata.py
@@ -56,6 +56,15 @@
         return []
 
     return sorted(
-        (distribution.metadata["Name"], distribution.metadata["Version"])
+        (
+            distribution.metadata["Name"],
+            (distribution.metadata["Version"] or "Unknown"),
+        )
         for distribution in distributions()
+        # Filter out distributions wtih None for name or value. This can be the
+        # case for packages without a METADATA or PKG-INFO file in their relevant
+        # distribution directory. According to comments in importlib.metadata
+        # internals this is possible for certain old packages, but I could only
+        # recreate it by deliberately deleting said files.
+        if distribution.metadata["Name"]
     )

{"golden_diff": "diff --git a/src/scout_apm/core/metadata.py b/src/scout_apm/core/metadata.py\n--- a/src/scout_apm/core/metadata.py\n+++ b/src/scout_apm/core/metadata.py\n@@ -56,6 +56,15 @@\n         return []\n \n     return sorted(\n-        (distribution.metadata[\"Name\"], distribution.metadata[\"Version\"])\n+        (\n+            distribution.metadata[\"Name\"],\n+            (distribution.metadata[\"Version\"] or \"Unknown\"),\n+        )\n         for distribution in distributions()\n+        # Filter out distributions wtih None for name or value. This can be the\n+        # case for packages without a METADATA or PKG-INFO file in their relevant\n+        # distribution directory. According to comments in importlib.metadata\n+        # internals this is possible for certain old packages, but I could only\n+        # recreate it by deliberately deleting said files.\n+        if distribution.metadata[\"Name\"]\n     )\n", "issue": "Error with the scout add-on in Heroku\nWith version 2.14.1 of this package, I encounter the following error:\r\n`  File \"/code/nluproxy/__init__.py\", line 3, in <module>\r\n\r\n    from .celery import app as celery_app\r\n\r\n  File \"/code/nluproxy/celery.py\", line 12, in <module>\r\n\r\n    scout_apm.celery.install(app)\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/celery.py\", line 58, in install\r\n\r\n    installed = scout_apm.core.install()\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/compat.py\", line 132, in wrapper\r\n\r\n    return func(*args, **kwargs)\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/core/__init__.py\", line 46, in install\r\n\r\n    report_app_metadata()\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py\", line 17, in report_app_metadata\r\n\r\n    event_value=get_metadata(),\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py\", line 37, in get_metadata\r\n\r\n    \"libraries\": get_python_packages_versions(),\r\n\r\n  File \"/usr/local/lib/python3.7/site-packages/scout_apm/core/metadata.py\", line 60, in get_python_packages_versions\r\n\r\n    for distribution in distributions()\r\n\r\nTypeError: '<' not supported between instances of 'NoneType' and 'str'\r\n\r\n`\n", "before_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport datetime as dt\nimport sys\nfrom os import getpid\n\nfrom scout_apm.core.commands import ApplicationEvent\nfrom scout_apm.core.config import scout_config\nfrom scout_apm.core.socket import CoreAgentSocketThread\n\n\ndef report_app_metadata():\n    CoreAgentSocketThread.send(\n        ApplicationEvent(\n            event_type=\"scout.metadata\",\n            event_value=get_metadata(),\n            source=\"Pid: \" + str(getpid()),\n            timestamp=dt.datetime.utcnow(),\n        )\n    )\n\n\ndef get_metadata():\n    data = {\n        \"language\": \"python\",\n        \"language_version\": \"{}.{}.{}\".format(*sys.version_info[:3]),\n        \"server_time\": dt.datetime.utcnow().isoformat() + \"Z\",\n        \"framework\": scout_config.value(\"framework\"),\n        \"framework_version\": scout_config.value(\"framework_version\"),\n        \"environment\": \"\",\n        \"app_server\": scout_config.value(\"app_server\"),\n        \"hostname\": scout_config.value(\"hostname\"),\n        \"database_engine\": \"\",\n        \"database_adapter\": \"\",\n        \"application_name\": \"\",\n        \"libraries\": get_python_packages_versions(),\n        \"paas\": \"\",\n        \"application_root\": scout_config.value(\"application_root\"),\n        \"scm_subdirectory\": scout_config.value(\"scm_subdirectory\"),\n        \"git_sha\": scout_config.value(\"revision_sha\"),\n    }\n    # Deprecated - see #327:\n    data[\"version\"] = data[\"language_version\"]\n    return data\n\n\ndef get_python_packages_versions():\n    try:\n        if sys.version_info >= (3, 8):\n            from importlib.metadata import distributions\n        else:\n            from importlib_metadata import distributions\n    except ImportError:\n        # For some reason it is unavailable\n        return []\n\n    return sorted(\n        (distribution.metadata[\"Name\"], distribution.metadata[\"Version\"])\n        for distribution in distributions()\n    )\n", "path": "src/scout_apm/core/metadata.py"}], "after_files": [{"content": "# coding=utf-8\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport datetime as dt\nimport sys\nfrom os import getpid\n\nfrom scout_apm.core.commands import ApplicationEvent\nfrom scout_apm.core.config import scout_config\nfrom scout_apm.core.socket import CoreAgentSocketThread\n\n\ndef report_app_metadata():\n    CoreAgentSocketThread.send(\n        ApplicationEvent(\n            event_type=\"scout.metadata\",\n            event_value=get_metadata(),\n            source=\"Pid: \" + str(getpid()),\n            timestamp=dt.datetime.utcnow(),\n        )\n    )\n\n\ndef get_metadata():\n    data = {\n        \"language\": \"python\",\n        \"language_version\": \"{}.{}.{}\".format(*sys.version_info[:3]),\n        \"server_time\": dt.datetime.utcnow().isoformat() + \"Z\",\n        \"framework\": scout_config.value(\"framework\"),\n        \"framework_version\": scout_config.value(\"framework_version\"),\n        \"environment\": \"\",\n        \"app_server\": scout_config.value(\"app_server\"),\n        \"hostname\": scout_config.value(\"hostname\"),\n        \"database_engine\": \"\",\n        \"database_adapter\": \"\",\n        \"application_name\": \"\",\n        \"libraries\": get_python_packages_versions(),\n        \"paas\": \"\",\n        \"application_root\": scout_config.value(\"application_root\"),\n        \"scm_subdirectory\": scout_config.value(\"scm_subdirectory\"),\n        \"git_sha\": scout_config.value(\"revision_sha\"),\n    }\n    # Deprecated - see #327:\n    data[\"version\"] = data[\"language_version\"]\n    return data\n\n\ndef get_python_packages_versions():\n    try:\n        if sys.version_info >= (3, 8):\n            from importlib.metadata import distributions\n        else:\n            from importlib_metadata import distributions\n    except ImportError:\n        # For some reason it is unavailable\n        return []\n\n    return sorted(\n        (\n            distribution.metadata[\"Name\"],\n            (distribution.metadata[\"Version\"] or \"Unknown\"),\n        )\n        for distribution in distributions()\n        # Filter out distributions wtih None for name or value. This can be the\n        # case for packages without a METADATA or PKG-INFO file in their relevant\n        # distribution directory. According to comments in importlib.metadata\n        # internals this is possible for certain old packages, but I could only\n        # recreate it by deliberately deleting said files.\n        if distribution.metadata[\"Name\"]\n    )\n", "path": "src/scout_apm/core/metadata.py"}]}