-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
sentry_runner(feat): Report development issues #24512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ment If the developer uses `direnv` it will load the `SENTRY_DEVENV_DSN` env variable. When using the `sentry` CLI, this will enable reporting development environment issues to Sentry.io
If the developer has SENTRY_DEVENV_DSN set we can report issues faced by the Sentry runner.
src/sentry/runner/__init__.py
Outdated
| ) | ||
| cli(prog_name=get_prog(), obj={}, max_content_width=100) | ||
| except Exception as e: | ||
| if os.environ.get("SENTRY_DEVENV_DSN"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@untitaker @billyvg For me, this block is sufficient. The changes in the sdk.py did not work to catch issues raised and we can investigate later if we need to make changes there; works for you? (If you say so, I will go and remove all changes from sdk.py).
You can test this change by shutting down the devservices and running sentry cleanup.
You can see the issue reported here:
https://sentry.io/organizations/sentry/issues/2279751970/?project=1492057&query=is%3Aunresolved+is%3Afor_review+assigned_or_suggested%3Ame_or_none
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to remove the changes to sdk.py. This will be good enough for now.
src/sentry/runner/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this in a with-stmt:
with init():
# capture_exception etc
then the old client will be restored at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it won't (it just blocks until the error has been sent) but I'd still recommend
src/sentry/runner/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| raise (e) | |
| raise e |
19709ca to
6d7fafb
Compare
src/sentry/runner/__init__.py
Outdated
| from sentry.utils.imports import import_string | ||
| from sentry.utils.compat import map | ||
|
|
||
| logging.basicConfig(format="%(asctime)s [%(levelname)s] %(message)s", level=logging.INFO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to understand how other pieces of code do logging.
I tried using setLevel(logging.INFO) on my logger so I could see logger.info("We have reported the error below to Sentry") at the end with no avail. Adding basicConfig() does the trick but I don't know why it would need that.
I've also tried using logging practices for the project but it's unclear to me.
I've looked at the modules that generate this output:
20:11:30 [WARNING] sentry.utils.geo: settings.GEOIP_PATH_MMDB not configured.
20:11:32 [INFO] sentry.plugins.github: apps-not-configured
and I know they listen to SENTRY_LOG_LEVEL=INFO and SENTRY_LOG_FORMAT='MACHINE', however, their code seems typical import logging and using a getLogger(); what am I missing?
src/sentry/runner/__init__.py
Outdated
| from sentry.utils.imports import import_string | ||
| from sentry.utils.compat import map | ||
|
|
||
| logging.basicConfig(format="%(asctime)s [%(levelname)s] %(message)s", level=logging.INFO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would only run this based on SENTRY_DEVENV_DSN to avoid potential impact on prod
|
Tagging @evanpurkhiser for the last blessing since he's touched the file few times in the last year. |
|
|
||
| ### You can override the exported variables with a .env file | ||
| # All exports should happen before here unless they're safeguarded (see devenv error reporting below) | ||
| if [ -f '.env' ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this up here works better when I want to load "SENTRY_DEVENV_NO_REPORT" through the .env file.
| else | ||
| info "Development errors will be reported to Sentry.io."$'\n'" If you wish to opt-out, set SENTRY_DEVENV_NO_REPORT as an env variable." | ||
| export SENTRY_DSN=https://[email protected]/1492057 | ||
| export SENTRY_DEVENV_DSN=https://[email protected]/1492057 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm renaming this variable since SENTRY_DSN since that is the default variable and I would not want it to conflict with what some engineer would have defined by hand or in their own start-up scripts.
src/sentry/runner/__init__.py
Outdated
| "Use SENTRY_DEVENV_NO_REPORT to avoid reporting issues." | ||
| ) | ||
| try: | ||
| cli(prog_name=get_prog(), obj={}, max_content_width=100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous commit, I only had cli() once, however, I had 2-3 if conditions. This makes it easier to read but will require the next person to ever touch the command to also update it below.
My apologies for the multiple comments (and probably multiple emails). I was only expecting to make 1 single comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we refactor this to a new function so that we don't need to update both cli() call sites?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billyvg I've used this:
diff --git a/src/sentry/runner/__init__.py b/src/sentry/runner/__init__.py
index 6522718a7d..436c5b1e0a 100644
--- a/src/sentry/runner/__init__.py
+++ b/src/sentry/runner/__init__.py
@@ -163,6 +163,12 @@ def call_command(name, obj=None, **kwargs):
def main():
+ func = cli
+ kwargs = {
+ "prog_name": get_prog(),
+ "obj": {},
+ "max_content_width": 100,
+ }
# This variable is *only* set as part of direnv/.envrc, thus, we cannot affect production
if os.environ.get("SENTRY_DEVENV_DSN"):
# We do this here because `configure_structlog` executes later
@@ -174,7 +180,7 @@ def main():
"Use SENTRY_DEVENV_NO_REPORT to avoid reporting issues."
)
try:
- cli(prog_name=get_prog(), obj={}, max_content_width=100)
+ func(**kwargs)
except Exception as e:
# This reports to the project sentry-dev-env
with sentry_sdk.init(dsn=os.environ["SENTRY_DEVENV_DSN"]):
@@ -184,5 +190,4 @@ def main():
logger.info("We have reported the error below to Sentry")
raise e
else:
- # If you change this command here make sure to also change it in the block above
- cli(prog_name=get_prog(), obj={}, max_content_width=100)
+ func(**kwargs)| "Use SENTRY_DEVENV_NO_REPORT to avoid reporting issues." | ||
| ) | ||
| try: | ||
| func(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cli(**kwargs) is probably sufficient
This change enables error reporting issues when using `sentry`'s CLI runner.
If the developer has
SENTRY_DEVENV_DSNset (if the developer usesdirenvit will be set) we can report issues faced by the Sentry runner.