Skip to content

Error Tracking: Support exceptions from Python's repl

Peter Leitzen requested to merge pl-error-tracking-python-repl into master

What does this MR do and why?

This MR adds support for Sentry exceptions from Python's repl.

When running Python code from repl and raising an exception, the Sentry payload being sent has context_line: null which was required to be a string prior this MR. This MR makes context_line nullable which aligns nicely with Sentry's JSON schema.

See #340178 (comment 735877987)

Screenshots or screen recordings

Screenshot_from_2021-11-17_16-47-08

How to set up and validate locally

  • Create a project on a local GDK instance

  • Enable Integrated Error Tracking

  • Use Sentry DSN in error.py below

  • Run some Python code targeting the error tracking API endpoint of the GDK instance

  • Dockerfile:

FROM python:3

RUN pip install --upgrade sentry-sdk

COPY error.py .

CMD [ "python", "./error.py" ]
  • error.py:
import sentry_sdk

from sentry_sdk import init, capture_exception

init(
    # DSN
    "http://<token>@10.23.0.5:3000/api/v4/error_tracking/collector/<project_id>",

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production.
    traces_sample_rate=1.0,
    debug=True
)

try:
    1/0
except ZeroDivisionError as e:
    print(e)
    capture_exception(e)
  • Run error.py from repl
docker run -i sentry-python /usr/local/bin/python < error.py

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading