Skip to content

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Mar 17, 2021

If the developer has SENTRY_DEVENV_DSN set (if the developer uses direnv it will be set) we can report issues faced by the Sentry runner.

armenzg added 2 commits March 17, 2021 15:57
…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.
)
cli(prog_name=get_prog(), obj={}, max_content_width=100)
except Exception as e:
if os.environ.get("SENTRY_DEVENV_DSN"):
Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise (e)
raise e

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)
Copy link
Member Author

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?

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)
Copy link
Member

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

@armenzg
Copy link
Member Author

armenzg commented Mar 22, 2021

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
Copy link
Member Author

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
Copy link
Member Author

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.

"Use SENTRY_DEVENV_NO_REPORT to avoid reporting issues."
)
try:
cli(prog_name=get_prog(), obj={}, max_content_width=100)
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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

@armenzg armenzg merged commit 4f5c640 into master Mar 23, 2021
@armenzg armenzg deleted the armenzg/sentry-runner-report-issues branch March 23, 2021 16:51
ahmedetefy pushed a commit that referenced this pull request Mar 26, 2021
This change enables error reporting issues when using `sentry`'s CLI runner.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Component: Developer Environment This covers issues related to setting up a developer's environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants