Skip to main content

Run arbirary scripts with sentry_sdk initialized to some DSN on the fly

Project description

dsnrun

Ad hoc utility to rerun a Python script, but with the sentry_sdk initialized to a specific DSN.

Bring the awesome experience of your error tracking software to ad hoc scripts and tools, non-production scripts and scripts that you cannot easily edit.

Installation & Usage

$ pip install dsnrun
[...]

$ dsnrun -h
Usage: dsnrun [dsn] [-m module | filename] [args...]

To use this, just rewrite your python invocations, i.e.

#!bash
# normal Python
$ python -m failingmodule
[..stacktrace..]

# becomes
$ dsnrun -m failingmodule
#!bash
# normal Python
$ python /tmp/failingmodule.py
[..stacktrace..]

# becomes
$ dsnrun /tmp/failingmodule.py

Now, visit your Error Tracker and get a much prettier stacktrace (including local variables).

Rationale

At Bugsink, we like our Error Tracking so much, that we even use it for local development. (Why wouldn't we: setup is trivial).

If you like Python, you probably do a lot with Python, including things for which you dind't plan on setting up your Error Tracker. Still, you occasionally mess up, leading to a stack trace on-screen.

What if that stacktrace was as awesome as the one in your error tracker?

Features

  • Because we use runpy to run the script, it should work with any Python script that you can run with python -m or python filename.py. i.e. any if __name__ == '__main__': block will still work as expected.

Limitations

Don't use this to set up sentry_dsn for your actual production code. We shouldn't have to explain why, but the gist of it is: There may very well be edge cases that trip this thing up, and why would you break production if you can just add a few lines to your actual production code?

These are current limitations, meaning we might as well improve the script if it turns out to be useful:

  • the on-screen (printed) stacktrace for dsnrun is not equal to the regular-python version; it also contains dsnrun itself and the functions it invokes. The event as sent to your DSN does not contain these though (we prune it).

  • dsn is the only currently supported argument to sentry_sdk.init. For future versions I'll put in the work of translating CLI args to SDK args.

  • dsnrun manually patches sys.argv such that the invoked script does not get dsnrun's arguments passed to it. This "seems to work" (but may not generally work). However, I did not find a way to "properly do this". See https://bugs.python.org/issue26388

  • If you mistype the thing-to-run you'll send an ImportError to your DSN. This is not filtered out (yet). Examples:

ImportError: No module named nosuchmodule

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/nosuchfile.py'

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

dsnrun-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsnrun-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file dsnrun-0.1.0.tar.gz.

File metadata

  • Download URL: dsnrun-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for dsnrun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cea002cee0ac206f87b6316225c8372175fb4a7f2e42fc04797d93d2d2dc3906
MD5 4923a99e6f8ec8ad59d33b43d8d111b8
BLAKE2b-256 d16a46709eede1590ffb01de8f9722d649b05a5537f33da4a360caffe4f3874d

See more details on using hashes here.

File details

Details for the file dsnrun-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dsnrun-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for dsnrun-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad3e74eb2bd3998be9f23fbad9bb19b57dc1e4f149c7cabb26d9dd70c3bd620
MD5 02ccbe0f7de958578183ea1cf4132ec3
BLAKE2b-256 b5814473159281e6a335296c598c2e014f04a36c622ceac010fa4b7955fd669b

See more details on using hashes here.

Supported by

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