Skip to main content

sentry-processor

sentry event processor for protecting sensitive infos.

Demo:

import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_processor import DesensitizationProcessor, POSITION

'''
# origin:
{
    ...
    "vars": {
        "pwd": "12345!@#$%",
        "phone": "13012341234"
    }
    ...
}
# result:
{
    ...
    "vars": {
        "pwd": "********",
        "phone": "130****1234"
    }
    ...
}
'''

def before_send(event, hint):
    # https://docs.sentry.io/error-reporting/configuration/filtering/?platform=python
    # modify event here
    # ...

    # process sensitive infos
    processor = DesensitizationProcessor(
        sensitive_keys=["pwd"],
        with_default_keys=True,
        partial_keys=["phone"],
        mask_position=POSITION.RIGHT,
        off_set=4
    )
    event = processor(event, hint)
    # or
    # event = processor.process(event, hint)

    return event


sentry_sdk.init(
    dsn="dsn",
    integrations=[LoggingIntegration()],
    before_send=before_send
)

API Reference

class DesensitizationProcessor(sensitive_keys=None, mask=None, with_default_keys=True,
                               partial_keys=None, partial_mask=None, mask_position=POSITION.RIGHT, off_set=0)
     Parameters:
        - sensitive_keys:
            A list of sensitive information keys that need to be filtered
            required: false
        - mask:
            The string to replace sensitive informations 
            required: false
        - with_default_keys:
            Whether to use the default sensitive information keys
            required: false
            default: True
        - partial_keys:
            A list of sensitive information keys that need to partially hidden(e.g: "12345678" -> "1234****")
            required: false
        - partial_mask:
            The string to partially hidden sensitive informations
            required: false
        - off_set:
            offset of partial_mask string relative to the starting point
            required: false
            default: 0
        - mask_position:
            starting point, the left or right side of original string
            required: false
            default: POSITION.RIGHT       
    
    process(self, event, hint)
        - event
        - hint

    __call__(self, event, hint)
        - event
        - hint

Metadata

Release files for sentry-processor 0.0.1

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

Source distribution (sdist)

Source distribution for sentry-processor 0.0.1
File Size Uploaded
sentry-processor-0.0.1.tar.gz 4.3 kB Details

Release files / sentry-processor-0.0.1.tar.gz

Download URL sentry-processor-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fd7a30fb57aaf05c01cd04cf7d949c628376b2b55d7a0aaa222efe58a8f122bc
BLAKE2b-256 checksum
How to use checksums
36e3c93206b20e503925094e72fa0d0e4d7bbb7cc617edbb5548166a6d4396a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

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