Skip to main content

sentry-sdk but quite

Project description

shy-sentry

sentry-sdk but silent

Shh.

Shh.

Extending getsentry/sentry-python, this package provides the following customizations we found useful in multiple projects:

  • default integrations that have a silent AtexitIntegration.callback
  • a Guard() context manager / decorator which provides quite sentry feedback on errors for parts of code that cannot let exceptions rock all the way up to killing the process. This is intended for use in our legacy cgi scripts, where console output is undesired.
  • loading certain sentry_sdk.init kwargs (dsn, environment, release) from json by default.
  • restores sentry_sdk.serializer.MAX_DATABAG_DEPTH and expands sentry_sdk.serializer.MAX_DATABAG_BREADTH for more complete debugging information. This is intended for use in our legacy cgi scripts, where code complexity per function can be higher then desired in non-legacy code.

Table of contents

Badges

Code style: black PYPI

master

Tests Coverage

Tests Coverage

Tests Coverage

Flake8

develop

Tests Coverage

Tests Coverage

Tests Coverage

Flake8

Install

$ pip install shy-sentry

Usage

Create a JSON configuration file with keys, used to configure sentry sdk:

{
   "SENTRY_DSN": "https://client_key@sentry.io/project_id",
   "SENTRY_ENVIRONMENT": "dev",
   "SENTRY_RELEASE_STRING": "project:branch@version"
}

Then, setup shy-sentry in the desired entry point and guard your entry point using Guard as a context manager or as a decorator.

as context manager
import shy_sentry


def main():
   print(1/0)


if __name__ == "__main__":
   shy_sentry.init(config_path="./sentry_config.json")
   with shy_sentry.Guard():
       main()
as decorator
import shy_sentry


@shy_sentry.Guard()
def main():
   print(1/0)


if __name__ == "__main__":
   shy_sentry.init(config_path="./sentry_config.json")
   main()

Exceptions outside of Guard() will get you ZeroDivisionError issue/event in Sentry AND a traceback in your console, when using default integrations.

import shy_sentry


def main():
   print(1/0)


if __name__ == "__main__":
   shy_sentry.init(config_path="./sentry_config.json")
   main()

If Guard() can't get a sentry_sdk.client.Client instance, it will reraise exceptions instead of ignoring them.

If there are certain exceptions you want reraised from Guard(), you'll need a sub-class like this:

from shy_sentry import Guard

class MyGuard(Guard):
    def __exit__(self, exc_type, exc_val, exc_tb):
        if not super().__exit__(exc_type, exc_val, exc_tb):
            # super intends to ignore, do we want to ignore?
            if isinstance(exc_type, OSError):
                return True
        return False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shy-sentry-1.2.0.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

shy_sentry-1.2.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page