We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Errors in celery don't get sent to Sentry


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `warehouse/celery.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12 
13 import celery.backends
14 
15 # We need to trick Celery into supporting rediss:// URLs which is how redis-py
16 # signals that you should use Redis with TLS.
17 celery.backends.BACKEND_ALIASES["rediss"] = "warehouse.celery:TLSRedisBackend"  # noqa
18 
19 from celery import Celery, Task
20 from celery.backends.redis import RedisBackend as _RedisBackend
21 from celery.signals import celeryd_init
22 from pyramid import scripting
23 from pyramid.threadlocal import get_current_request
24 
25 from warehouse.config import Environment, configure
26 
27 
28 @celeryd_init.connect
29 def _configure_celery(*args, **kwargs):
30     configure()
31 
32 
33 class TLSRedisBackend(_RedisBackend):
34 
35     def _params_from_url(self, url, defaults):
36         params = super()._params_from_url(url, defaults)
37         params.update({"connection_class": self.redis.SSLConnection})
38         return params
39 
40 
41 class WarehouseTask(Task):
42 
43     abstract = True
44 
45     def __call__(self, *args, **kwargs):
46         registry = self.app.pyramid_config.registry
47         pyramid_env = scripting.prepare(registry=registry)
48 
49         try:
50             return super().__call__(pyramid_env["request"], *args, **kwargs)
51         finally:
52             pyramid_env["closer"]()
53 
54     def apply_async(self, *args, **kwargs):
55         # The API design of Celery makes this threadlocal pretty impossible to
56         # avoid :(
57         request = get_current_request()
58 
59         # If for whatever reason we were unable to get a request we'll just
60         # skip this and call the original method to send this immediately.
61         if request is None or not hasattr(request, "tm"):
62             return super().apply_async(*args, **kwargs)
63 
64         # This will break things that expect to get an AsyncResult because
65         # we're no longer going to be returning an async result from this when
66         # called from within a request, response cycle. Ideally we shouldn't be
67         # waiting for responses in a request/response cycle anyways though.
68         request.tm.get().addAfterCommitHook(
69             self._after_commit_hook,
70             args=args,
71             kws=kwargs,
72         )
73 
74     def _after_commit_hook(self, success, *args, **kwargs):
75         if success:
76             super().apply_async(*args, **kwargs)
77 
78 
79 app = Celery("warehouse")
80 app.Task = WarehouseTask
81 
82 
83 task = app.task
84 
85 
86 def includeme(config):
87     s = config.registry.settings
88     app.pyramid_config = config
89     app.conf.update(
90         BROKER_URL=s["celery.broker_url"],
91         BROKER_USE_SSL=s["warehouse.env"] == Environment.production,
92         CELERY_DISABLE_RATE_LIMITS=True,
93         CELERY_RESULT_BACKEND=s["celery.result_url"],
94         CELERY_RESULT_SERIALIZER="json",
95         CELERY_TASK_SERIALIZER="json",
96         CELERY_ACCEPT_CONTENT=["json", "msgpack"],
97         CELERY_MESSAGE_COMPRESSION="gzip",
98         CELERY_QUEUE_HA_POLICY="all",
99     )
100
```
--- 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/warehouse/celery.py b/warehouse/celery.py
--- a/warehouse/celery.py
+++ b/warehouse/celery.py
@@ -21,13 +21,16 @@
 from celery.signals import celeryd_init
 from pyramid import scripting
 from pyramid.threadlocal import get_current_request
+from raven.contrib.celery import register_signal, register_logger_signal
 
 from warehouse.config import Environment, configure
 
 
 @celeryd_init.connect
 def _configure_celery(*args, **kwargs):
-    configure()
+    config = configure()
+    register_logger_signal(config.registry["raven.client"])
+    register_signal(config.registry["raven.client"])
 
 
 class TLSRedisBackend(_RedisBackend):

{"golden_diff": "diff --git a/warehouse/celery.py b/warehouse/celery.py\n--- a/warehouse/celery.py\n+++ b/warehouse/celery.py\n@@ -21,13 +21,16 @@\n from celery.signals import celeryd_init\n from pyramid import scripting\n from pyramid.threadlocal import get_current_request\n+from raven.contrib.celery import register_signal, register_logger_signal\n \n from warehouse.config import Environment, configure\n \n \n @celeryd_init.connect\n def _configure_celery(*args, **kwargs):\n-    configure()\n+    config = configure()\n+    register_logger_signal(config.registry[\"raven.client\"])\n+    register_signal(config.registry[\"raven.client\"])\n \n \n class TLSRedisBackend(_RedisBackend):\n", "issue": "Errors in celery don't get sent to Sentry\n\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport celery.backends\n\n# We need to trick Celery into supporting rediss:// URLs which is how redis-py\n# signals that you should use Redis with TLS.\ncelery.backends.BACKEND_ALIASES[\"rediss\"] = \"warehouse.celery:TLSRedisBackend\"  # noqa\n\nfrom celery import Celery, Task\nfrom celery.backends.redis import RedisBackend as _RedisBackend\nfrom celery.signals import celeryd_init\nfrom pyramid import scripting\nfrom pyramid.threadlocal import get_current_request\n\nfrom warehouse.config import Environment, configure\n\n\n@celeryd_init.connect\ndef _configure_celery(*args, **kwargs):\n    configure()\n\n\nclass TLSRedisBackend(_RedisBackend):\n\n    def _params_from_url(self, url, defaults):\n        params = super()._params_from_url(url, defaults)\n        params.update({\"connection_class\": self.redis.SSLConnection})\n        return params\n\n\nclass WarehouseTask(Task):\n\n    abstract = True\n\n    def __call__(self, *args, **kwargs):\n        registry = self.app.pyramid_config.registry\n        pyramid_env = scripting.prepare(registry=registry)\n\n        try:\n            return super().__call__(pyramid_env[\"request\"], *args, **kwargs)\n        finally:\n            pyramid_env[\"closer\"]()\n\n    def apply_async(self, *args, **kwargs):\n        # The API design of Celery makes this threadlocal pretty impossible to\n        # avoid :(\n        request = get_current_request()\n\n        # If for whatever reason we were unable to get a request we'll just\n        # skip this and call the original method to send this immediately.\n        if request is None or not hasattr(request, \"tm\"):\n            return super().apply_async(*args, **kwargs)\n\n        # This will break things that expect to get an AsyncResult because\n        # we're no longer going to be returning an async result from this when\n        # called from within a request, response cycle. Ideally we shouldn't be\n        # waiting for responses in a request/response cycle anyways though.\n        request.tm.get().addAfterCommitHook(\n            self._after_commit_hook,\n            args=args,\n            kws=kwargs,\n        )\n\n    def _after_commit_hook(self, success, *args, **kwargs):\n        if success:\n            super().apply_async(*args, **kwargs)\n\n\napp = Celery(\"warehouse\")\napp.Task = WarehouseTask\n\n\ntask = app.task\n\n\ndef includeme(config):\n    s = config.registry.settings\n    app.pyramid_config = config\n    app.conf.update(\n        BROKER_URL=s[\"celery.broker_url\"],\n        BROKER_USE_SSL=s[\"warehouse.env\"] == Environment.production,\n        CELERY_DISABLE_RATE_LIMITS=True,\n        CELERY_RESULT_BACKEND=s[\"celery.result_url\"],\n        CELERY_RESULT_SERIALIZER=\"json\",\n        CELERY_TASK_SERIALIZER=\"json\",\n        CELERY_ACCEPT_CONTENT=[\"json\", \"msgpack\"],\n        CELERY_MESSAGE_COMPRESSION=\"gzip\",\n        CELERY_QUEUE_HA_POLICY=\"all\",\n    )\n", "path": "warehouse/celery.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport celery.backends\n\n# We need to trick Celery into supporting rediss:// URLs which is how redis-py\n# signals that you should use Redis with TLS.\ncelery.backends.BACKEND_ALIASES[\"rediss\"] = \"warehouse.celery:TLSRedisBackend\"  # noqa\n\nfrom celery import Celery, Task\nfrom celery.backends.redis import RedisBackend as _RedisBackend\nfrom celery.signals import celeryd_init\nfrom pyramid import scripting\nfrom pyramid.threadlocal import get_current_request\nfrom raven.contrib.celery import register_signal, register_logger_signal\n\nfrom warehouse.config import Environment, configure\n\n\n@celeryd_init.connect\ndef _configure_celery(*args, **kwargs):\n    config = configure()\n    register_logger_signal(config.registry[\"raven.client\"])\n    register_signal(config.registry[\"raven.client\"])\n\n\nclass TLSRedisBackend(_RedisBackend):\n\n    def _params_from_url(self, url, defaults):\n        params = super()._params_from_url(url, defaults)\n        params.update({\"connection_class\": self.redis.SSLConnection})\n        return params\n\n\nclass WarehouseTask(Task):\n\n    abstract = True\n\n    def __call__(self, *args, **kwargs):\n        registry = self.app.pyramid_config.registry\n        pyramid_env = scripting.prepare(registry=registry)\n\n        try:\n            return super().__call__(pyramid_env[\"request\"], *args, **kwargs)\n        finally:\n            pyramid_env[\"closer\"]()\n\n    def apply_async(self, *args, **kwargs):\n        # The API design of Celery makes this threadlocal pretty impossible to\n        # avoid :(\n        request = get_current_request()\n\n        # If for whatever reason we were unable to get a request we'll just\n        # skip this and call the original method to send this immediately.\n        if request is None or not hasattr(request, \"tm\"):\n            return super().apply_async(*args, **kwargs)\n\n        # This will break things that expect to get an AsyncResult because\n        # we're no longer going to be returning an async result from this when\n        # called from within a request, response cycle. Ideally we shouldn't be\n        # waiting for responses in a request/response cycle anyways though.\n        request.tm.get().addAfterCommitHook(\n            self._after_commit_hook,\n            args=args,\n            kws=kwargs,\n        )\n\n    def _after_commit_hook(self, success, *args, **kwargs):\n        if success:\n            super().apply_async(*args, **kwargs)\n\n\napp = Celery(\"warehouse\")\napp.Task = WarehouseTask\n\n\ntask = app.task\n\n\ndef includeme(config):\n    s = config.registry.settings\n    app.pyramid_config = config\n    app.conf.update(\n        BROKER_URL=s[\"celery.broker_url\"],\n        BROKER_USE_SSL=s[\"warehouse.env\"] == Environment.production,\n        CELERY_DISABLE_RATE_LIMITS=True,\n        CELERY_RESULT_BACKEND=s[\"celery.result_url\"],\n        CELERY_RESULT_SERIALIZER=\"json\",\n        CELERY_TASK_SERIALIZER=\"json\",\n        CELERY_ACCEPT_CONTENT=[\"json\", \"msgpack\"],\n        CELERY_MESSAGE_COMPRESSION=\"gzip\",\n        CELERY_QUEUE_HA_POLICY=\"all\",\n    )\n", "path": "warehouse/celery.py"}]}