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.

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

# becomes
$ dsnrun -m failingmodule
# 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.2.0.tar.gz (6.9 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.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dsnrun-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f8c324c509d9668bfdbf65bae13a315beda3e43a2a173f19453f4b0d7549f297
MD5 7745b9d8f168eed1c8714c5e2aa13362
BLAKE2b-256 b431e04fc64c0f525aa4f12d4a9a6a2b46ecb568b8a8eca94e59bc6319fb5d0e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dsnrun-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 127b4175b41da814bd50c2043c44a3cd1fb5499c0d557e6ee32c5c288624e0ce
MD5 66a63ed9397b901d6e82483c05031af5
BLAKE2b-256 108b0d8d42ba4dbd0e1c43835ac978b7d8fef91e1fd2c1f34ad11da1eaf99289

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