An overview of the

If you are developing using PyCharm, you need to configure something to run and debug.

This document describes some configurations that are useful for Sentry development

configuration

Python interpreter :(make sure it is a venv interpreter) for example ~/venv/sentry/bin/ Python

To create a configuration (run/debug configuration), only to run | Edit Configurations… (Also available in the default toolbar).

Test runner

Sentry uses PyTest for unit testing.

Create pyTest configuration (under Python Tests)

Set Target: Custom

Additional Arguments: Tests/Sentry

Dev Server with everything you need

For running with all Settings (Web, worker, cron) (non-debugging) :

  • Create anotherPythonconfiguration
  • Script path (Script path) :<venv dir>/bin/sentry e.g. ~/venv/sentry/bin/sentry
  • Parameters (Parameters) :devserver --workers
  • The Python interpreter (Python interpreter) :venv interpreter
  • Working Catalogue (Working dir): (in sentry installation directorysrcPath) um participant.~/dev/sentry/src

Note: You will not be able to debug the Web Worker using this configuration (the Web Worker is started by calling the UWSGi server).

Use PyCharm for debugging

The devServer command exists primarily to generate daemons in a separate process, which means attaching the Debugger to it in default mode is not very useful.

Web server

The devServer command has a special flag that causes the Web Server to start in a thread of the same process (rather than as a Web daemon). This allows the same PyCharm “Debug” action that started DevServer to attach to the Web Server and hit the breakpoint on the back end.

Clone your devServer to run the configuration and add –debug-server to the end of the “Parameters” field. Start it by selecting “Debug” instead of “Run”.

The — Debug-server flag may cause the process to fail to respond properly to SIGINT and shut down less elegantly than the original configuration. It is recommended to keep both and use the first with the Run command and the second with the Debug command.

You can keep the –workers flag with — Debug-server, but note that it is not possible to attach breakpoints to Workers, nor to any other daemons generated by DevServer.

Standalone daemon

To attach the Debugger to a single daemon other than the Web, create a run configuration for the daemon. The following properties should be the same as your DevServer configuration. (You can clone it and just change the Parameters field.)

  • Script path (Script path) :<venv dir>/bin/sentry, such as:~/venv/sentry/bin/sentry
  • The Python interpreter (Python interpreter) :venv interpreter
  • Working Catalogue (Working dir) : (sentryIn the installation directorysrcPath) for example~/dev/sentry/src

Set the parameters of the new run configuration to the run command to start the daemon, for example:

  • run cron
  • run worker -c 1

Tips and troubleshooting

  • If you want to debug it, the same set of changes will applygetentryOperation configuration of the project.
  • PyCharmCompoundRun configuration types are useful for starting multiple run configurations at once. If you are debugging one or more separate daemons that work with the development server, it might be convenient to set one up.

  • If you wishSentryThe behavior in the debug environment is different from the behavior in the normal run, you can add any environment variable, and then in your.sentry/sentry.conf.pyCheck them in the file.

For example, the screen capture below shows the setting to disable APM sampling during debugging (because stopping at breakpoints would contaminate time measurements). Note that PYCHARM_DEBUG is an arbitrary name; It has no special meaning for PyCharm and Sentry.

  • If your daemon running alone doesn’t work, you can debug itdevserver --debug-serverAnd in thesrc/sentry/runner/commands/devserver.pyInsert a breakpoint on to troubleshoot. This will let you check manuallydevserverCommand Indicates the running command. (Look near the bottommanager.add_processCall.) Try adjusting the parameters in the run configuration to match these commands if they don’t already exist.