Skip to main content

A small set of utilities for configuring sentry & modifying normal sentry_sdk functionality

Project description

Lenders Sentry Utils

This is a package containing Sentry related utilities used across several Lenders Cooperative projects.

Installation

$ pip install lenders-sentry-utils

Usage

There are two major components in the package, sentry_init and TrafficSplittingHttpTransport. These are explained in the sections below. Additionally, there is one minor component, capture_exception. This is a simple wrapper for sentry_sdk.capture_exception that adds an event processor to protect a request's body if it exists in the event.

Sentry Init

This package's sentry_init is a wrapper for sentry_sdk.init with default values and automatic checking of environment variables. The following table lists each parameter and its relevant information. Any parameter with no description directly corresponds to a sentry_sdk.init option.

Parameter name Type Default value Description
env Env None An Env object to search if dsn, environment, or release are not passed
dsn str env("SENTRY_DSN")
environment str env("BASE_URL")
release str env("VERSION")
debug bool False
send_default_pii bool True
traces_sample_rate float 0.1
integrations List Django, Celery, Redis integrations
transport Transport HTTPTransport
before_send function None

Note: env, dsn, and environment are dependent on each other to a certain degree. If dsn or environment are not passed as parameters, env must be passed in order to pull the corresponding environment variable. Additionally, if dsn or environment are passed, the passed value will be used even if the corresponding environment variable exists in env. release is similar to dsn and environment, but it is fully optional.

Sentry Init Examples

from lenders_sentry_utils import sentry_init
from environ import Env

env = Env(
    SENTRY_DSN = (str, 'https://PK@sentry.io/0'),
    BASE_URL = (str, 'base.com'),
)

# Minimum viable function call
sentry_init(env=env)

# Forcing a DSN that's not in the environment
different_dsn = 'https://different@not.sentry.io/3'
sentry_init(env=env, dsn=different_dsn)

# Setting DSN and environment without using environment variables
sentry_init(dsn=different_dsn, environment='special.env.com')

TrafficSplittingHttpTransport

TrafficSplittingHttpTransport is a custom transport that splits transaction events to a second DSN while still sending error events to the primary DSN. This is usually done for billing purposes to ensure that all errors can be reported to Sentry. To use this transport, the environment variable SENTRY_TRANSACTIONS_DSN must be set with the second DSN as its value. If this environment variable is not set, transaction events will instead be discarded.

TrafficSplittingHttpTransport Examples

import lenders_sentry_utils as lsu
from environ import Env

drop_transactions_env = Env(
    SENTRY_DSN = (str, 'https://error_dsn@sentry.io/0'),
    BASE_URL = (str, 'base.com'),
)
send_transactions_env = Env(
    SENTRY_DSN = (str, 'https://error_dsn@sentry.io/0'),
    BASE_URL = (str, 'base.com'),
    SENTRY_TRANSACTIONS_DSN = (str, 'https://transactions_dsn@sentry.io/0'),
)

# Example 1: Sending transaction events
lsu.sentry_init(env=send_transactions_env, transport=lsu.TrafficSplittingHttpTransport)

# Example 2: Ignoring transaction events
lsu.sentry_init(env=drop_transactions_env, transport=lsu.TrafficSplittingHttpTransport)

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

lenders-sentry-utils-0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

lenders_sentry_utils-0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file lenders-sentry-utils-0.2.tar.gz.

File metadata

  • Download URL: lenders-sentry-utils-0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.1

File hashes

Hashes for lenders-sentry-utils-0.2.tar.gz
Algorithm Hash digest
SHA256 c8ad5950ccf7c5b1b986b54c5c8c087e31d51e306f59fb5051fdb554bac85001
MD5 bdb39407be73c0cd777832ee20bfe802
BLAKE2b-256 efe3cfddb9322c81b54b225ff675ea0c76c2ced020638078269a836e1e8ed0f0

See more details on using hashes here.

File details

Details for the file lenders_sentry_utils-0.2-py3-none-any.whl.

File metadata

  • Download URL: lenders_sentry_utils-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.1

File hashes

Hashes for lenders_sentry_utils-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 04d4708dc669eb1ef56eeb2a94aa19b829c81e55db1633b3ac82861765389337
MD5 7e21cbae6f1b2142c5d9467dab10e7f2
BLAKE2b-256 4fd2dd44d41e7ee60020e46a0a4ec1b7d6a3c17de90578736dfa57b49c940dcd

See more details on using hashes here.

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