Skip to main content

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)

Release files for lenders-sentry-utils 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lenders-sentry-utils 0.2
File Size Uploaded
lenders-sentry-utils-0.2.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lenders-sentry-utils 0.2
File Interpreter ABI Platform
lenders_sentry_utils-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / lenders-sentry-utils-0.2.tar.gz

Download URL lenders-sentry-utils-0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c8ad5950ccf7c5b1b986b54c5c8c087e31d51e306f59fb5051fdb554bac85001
BLAKE2b-256 checksum
How to use checksums
efe3cfddb9322c81b54b225ff675ea0c76c2ced020638078269a836e1e8ed0f0
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / lenders_sentry_utils-0.2-py3-none-any.whl

Download URL lenders_sentry_utils-0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04d4708dc669eb1ef56eeb2a94aa19b829c81e55db1633b3ac82861765389337
BLAKE2b-256 checksum
How to use checksums
4fd2dd44d41e7ee60020e46a0a4ec1b7d6a3c17de90578736dfa57b49c940dcd
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page