python icon indicating copy to clipboard operation
python copied to clipboard

Unable to capture server exceptions with Sentry

Open Gunni opened this issue 6 months ago • 2 comments

I am trying to use sentry_sdk to capture exceptions in the varlink api.

So far the only way i have found is to wrap varlink.RequestHandler like this:

class ServiceRequestHandler(varlink.RequestHandler):
    service = service

    def __init__(self, *args, **kwargs):
        with sentry_sdk.start_transaction(op='fallback', name='ServiceRequestHandler') as t:
            try:
                super().__init__(*args, **kwargs)
            except:
                sentry_sdk.capture_exception()
                raise

The problem is that this starts a new transaction instead of using the one i already made:

@service.interface('com.example')
class Example:
    def Add(self, something):
        with sentry_sdk.start_transaction(op='call', name=f'{Path(__file__).name}::Add'):
            ...

And my workaround also marks all the exceptions i do get as "handled" because of how I captured them.

Any ideas?

Gunni avatar Jun 20 '25 15:06 Gunni