gluetool.sentry module

Integration with Sentry, error tracking software.

In theory, when an exception is raised and not handled, you can use this module to submit it to your Sentry instance, and track errors produced by your application.

The actual integration is controlled by several environment variables. Each can be unset, empty or set:

  • SENTRY_DSN - Client key, or DSN as called by Sentry docs.

    When unset or empty, the integration is disabled and no events are sent to the Sentry server.

  • SENTRY_BASE_URL - Optional: base URL of your project on the Sentry web server. The module can then use this value and construct URLs for reported events, which, when followed, will lead to the corresponding issue.

    When unset or empty, such URLs will not be available.

  • SENTRY_TAG_MAP - Optional: comma-separated mapping between environment variables and additional tags, which are attached to every reported event. E.g. username=USER,hostname=HOSTNAME will add 2 tags, username and hostname, setting their values according to the environment. Unset variables are silently ignored.

    When unset or empty, no additional tags are added to events.

The actual names of these variables can be changed when creating an instance of gluetool.sentry.Sentry.

class gluetool.sentry.Sentry(dsn_env_var='SENTRY_DSN', base_url_env_var='SENTRY_BASE_URL', tags_map_env_var='SENTRY_TAG_MAP')[source]

Bases: object

Provides unified interface to the Sentry client, Raven. Callers don’t have to think whether the submitting is enabled or not, and we can add common tags and other bits we’d like to track for all events.

Parameters:
  • dsn_env_var (str) – Name of environment variable setting Sentry DSN. Set to None to explicitly disable Sentry integration.
  • base_url_env_var (str) – Name of environment variable setting base URL of Sentry server. Setting to None will cause the per-event links will not be available to users of this class.
  • tags_map_env_var (str) – Name of environment variable setting mapping between environment variables and additional tags. Set to None to disable adding these tags.
_capture(event_type, logger=None, failure=None, **kwargs)[source]

Prepare common arguments, and then submit the data to the Sentry server.

enable_logging_breadcrumbs(logger)[source]
enabled
event_url(event_id, logger=None)[source]

Return URL showing the event on the Sentry server. If event_id is None or when base URL of the Sentry server was not set, None is returned instead.

Parameters:
static log_issue(failure, logger=None)[source]

Nicely log issue and possibly its URL.

Parameters:
submit_exception(failure, logger=None, **kwargs)[source]

Submits an exception to the Sentry server. Exceptions are usually submitted automagically, but sometimes you might feel the need to share arbitrary issues with the world.

When submitting is not enabled, this method simply returns without sending anything anywhere.

Parameters:
  • failure (gluetool.glue.Failure) – Failure instance describing the exception.
  • kwargs (dict) – Additional arguments that will be passed to Sentry’s captureException method.
submit_warning(msg, logger=None, **kwargs)[source]

Submits a warning to the Sentry server. You might feel the need to share arbitrary issues - e.g. warnings that are not serious enough to kill the pipeline - with the world.

When submitting is not enabled, this method simply returns without sending anything anywhere.

Parameters:
  • msg (str) – Message describing the issue.
  • kwargs (dict) – additional arguments that will be passed to Sentry’s captureMessage method.