Nameko ClusterRpcProxy exception does not report errors to sentry

Hi,

I have a simple method where when I call:

def test_sentry():
   with ClusterRpcProxy(CONFIG) as rpc:
                result = rpc.some_unknown_service.some_method()

an exception is thrown (observed from docker-compose logs), but the event isn’t sent to sentry. Please note in other places when exceptions are thrown, events are being sent to sentry.

My hypothesis is that ClusterRpcProxy launches a separate thread. Does anyone run into issues like this?

Stacktrace below.

amqp.exceptions.ChannelError: Basic.return: (312) NO_ROUTE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/nameko/rpc.py", line 445, in _call
    extra_headers=extra_headers
  File "/usr/local/lib/python3.6/site-packages/nameko/amqp/publish.py", line 214, in publish
    raise UndeliverableMessage()
nameko.amqp.publish.UndeliverableMessage

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/some_package/some_folder/my_file.py", line 593, in test_sentry
    result = rpc.aje.blah()
  File "/usr/local/lib/python3.6/site-packages/nameko/rpc.py", line 372, in __call__
    reply = self._call(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/nameko/rpc.py", line 448, in _call
    raise UnknownService(self.service_name)
nameko.exceptions.UnknownService: Unknown service `some_unknown_service`

So how I work around this issue is to manually catch the expected exception myself, and send it to Sentry which, after I’ve tested, does work.

def test_sentry():
   with ClusterRpcProxy(CONFIG) as rpc:
          try:
                result = rpc.some_unknown_service.some_method()
          except UnknownService as ex:
                capture_exception(ex)