From 93375bc22141b716c7b2a308a0a03b2b85138947 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 7 Jun 2022 09:36:09 +0200 Subject: [PATCH 1/3] Cound the number of issues on the issue page. --- .../api/endpoints/organization_group_index.py | 4 ++++ .../api/endpoints/organization_issues_count.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sentry/api/endpoints/organization_group_index.py b/src/sentry/api/endpoints/organization_group_index.py index 488bf6fb9d3f8b..3f2d4741d8cb0d 100644 --- a/src/sentry/api/endpoints/organization_group_index.py +++ b/src/sentry/api/endpoints/organization_group_index.py @@ -6,6 +6,7 @@ from rest_framework.exceptions import ParseError, PermissionDenied from rest_framework.request import Request from rest_framework.response import Response +from sentry_sdk import start_transaction from sentry import features, search from sentry.api.bases import OrganizationEventPermission, OrganizationEventsEndpointBase @@ -345,6 +346,9 @@ def get(self, request: Request, organization) -> Response: self.add_cursor_headers(request, response, cursor_result) # TODO(jess): add metrics that are similar to project endpoint here + transaction = start_transaction(name="measuring issues") + transaction.set_measurement("issues.unresolved", len(cursor_result)) + return response @track_slo_response("workflow") diff --git a/src/sentry/api/endpoints/organization_issues_count.py b/src/sentry/api/endpoints/organization_issues_count.py index 2bdae71f482d41..15c9537aa0c591 100644 --- a/src/sentry/api/endpoints/organization_issues_count.py +++ b/src/sentry/api/endpoints/organization_issues_count.py @@ -1,6 +1,7 @@ from rest_framework.exceptions import ParseError from rest_framework.request import Request from rest_framework.response import Response +from sentry_sdk import start_transaction from sentry import features, search from sentry.api.bases import OrganizationEventsEndpointBase @@ -11,9 +12,13 @@ from sentry.types.ratelimit import RateLimit, RateLimitCategory ERR_INVALID_STATS_PERIOD = "Invalid stats_period. Valid choices are '', '24h', and '14d'" - - ISSUES_COUNT_MAX_HITS_LIMIT = 100 +QUERY_NAMES = { + "is:unresolved is:for_review assigned_or_suggested:[me, none]": "for_review", + "is:unresolved": "unresolved", + "is:ignored": "ignored", + "is:reprocessing": "reprocessing", +} class OrganizationIssuesCountEndpoint(OrganizationEventsEndpointBase): @@ -75,6 +80,7 @@ def get(self, request: Request, organization) -> Response: queries = request.GET.getlist("query") response = {} + transaction = start_transaction(name="measuring issues") for query in queries: try: count = self._count( @@ -86,6 +92,10 @@ def get(self, request: Request, organization) -> Response: {"count_hits": True, "date_to": end, "date_from": start}, ) response[query] = count + query_name = QUERY_NAMES.get(query, None) + if query_name and count: + transaction.set_measurement(f"issues.{query_name}", count) + except (ValidationError, discover.InvalidSearchQuery) as exc: return Response({"detail": str(exc)}, status=400) From 142cdc1318ea4a0eb4f041a9dc2f8d672fd4fc11 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 7 Jun 2022 16:24:55 +0200 Subject: [PATCH 2/3] Update current transaction and correctly initialice sentry sdk --- requirements-base.txt | 2 +- src/sentry/api/endpoints/organization_group_index.py | 7 ++++--- src/sentry/api/endpoints/organization_issues_count.py | 6 +++--- src/sentry/utils/sdk.py | 3 +++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/requirements-base.txt b/requirements-base.txt index 39121ad79c0745..a834c6154f574f 100644 --- a/requirements-base.txt +++ b/requirements-base.txt @@ -56,7 +56,7 @@ rfc3986-validator==0.1.1 # [end] jsonschema format validators sentry-arroyo==0.0.16 sentry-relay==0.8.12 -sentry-sdk>=1.4.3,<1.6.0 +sentry-sdk>=1.5.12,<1.6.0 snuba-sdk==1.0.0 simplejson==3.17.2 statsd==3.3 diff --git a/src/sentry/api/endpoints/organization_group_index.py b/src/sentry/api/endpoints/organization_group_index.py index 3f2d4741d8cb0d..2395f197301bb8 100644 --- a/src/sentry/api/endpoints/organization_group_index.py +++ b/src/sentry/api/endpoints/organization_group_index.py @@ -6,7 +6,7 @@ from rest_framework.exceptions import ParseError, PermissionDenied from rest_framework.request import Request from rest_framework.response import Response -from sentry_sdk import start_transaction +from sentry_sdk import Hub from sentry import features, search from sentry.api.bases import OrganizationEventPermission, OrganizationEventsEndpointBase @@ -346,8 +346,9 @@ def get(self, request: Request, organization) -> Response: self.add_cursor_headers(request, response, cursor_result) # TODO(jess): add metrics that are similar to project endpoint here - transaction = start_transaction(name="measuring issues") - transaction.set_measurement("issues.unresolved", len(cursor_result)) + transaction = Hub.current.scope.transaction + if transaction: + transaction.set_measurement("issues.unresolved", len(cursor_result)) return response diff --git a/src/sentry/api/endpoints/organization_issues_count.py b/src/sentry/api/endpoints/organization_issues_count.py index 15c9537aa0c591..10b80c6068d4dd 100644 --- a/src/sentry/api/endpoints/organization_issues_count.py +++ b/src/sentry/api/endpoints/organization_issues_count.py @@ -1,7 +1,7 @@ from rest_framework.exceptions import ParseError from rest_framework.request import Request from rest_framework.response import Response -from sentry_sdk import start_transaction +from sentry_sdk import Hub from sentry import features, search from sentry.api.bases import OrganizationEventsEndpointBase @@ -78,9 +78,9 @@ def get(self, request: Request, organization) -> Response: {"detail": "You do not have the multi project stream feature enabled"}, status=400 ) + transaction = Hub.current.scope.transaction queries = request.GET.getlist("query") response = {} - transaction = start_transaction(name="measuring issues") for query in queries: try: count = self._count( @@ -93,7 +93,7 @@ def get(self, request: Request, organization) -> Response: ) response[query] = count query_name = QUERY_NAMES.get(query, None) - if query_name and count: + if transaction and query_name and count: transaction.set_measurement(f"issues.{query_name}", count) except (ValidationError, discover.InvalidSearchQuery) as exc: diff --git a/src/sentry/utils/sdk.py b/src/sentry/utils/sdk.py index fd28c99157a71b..a17854881265cc 100644 --- a/src/sentry/utils/sdk.py +++ b/src/sentry/utils/sdk.py @@ -340,6 +340,9 @@ def _capture_anything(self, method_name, *args, **kwargs): RedisIntegration(), ThreadingIntegration(propagate_hub=True), ], + _experiments={ + "custom_measurements": True, + }, **sdk_options, ) From cdb6b8efd868b8ec38a30a456d4995c4d3b994e4 Mon Sep 17 00:00:00 2001 From: Armen Zambrano G Date: Wed, 8 Jun 2022 08:31:07 -0400 Subject: [PATCH 3/3] fix(dev): Do not export SENTRY_DSN in .envrc (#35440) We started exporting SENTRY_DSN back in #32524 in order to fix errors in lib.sh not being reported. Having this variable exported can cause a lot of errors from a developers' development to show up as dev env errors. Exporting inside of lib.sh does not persist in the developers' environment. --- .envrc | 5 ++--- config/hooks/pre-commit | 9 ++------- scripts/lib.sh | 5 ++++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.envrc b/.envrc index 9c7e39591dbcc3..a2aa313736bdb5 100644 --- a/.envrc +++ b/.envrc @@ -59,7 +59,8 @@ report_to_sentry() { curl -sL https://sentry.io/get-cli/ | bash fi # Report to sentry-dev-env project - sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level + SENTRY_DSN="https://9bdb053cb8274ea69231834d1edeec4c@o1.ingest.sentry.io/5723503" \ + sentry-cli send-event -m "$error_message" --logfile "$_SENTRY_LOG_FILE" --level $log_level rm "$_SENTRY_LOG_FILE" } @@ -142,8 +143,6 @@ fi if [ -n "${SENTRY_DEVENV_NO_REPORT+x}" ]; then debug "No development environment errors will be reported (since you've defined SENTRY_DEVENV_NO_REPORT)." else - # This is necessary for the bash-hook in lib.sh to work - export SENTRY_DSN="https://9bdb053cb8274ea69231834d1edeec4c@o1.ingest.sentry.io/5723503" # Since direnv traps the EXIT signal we place the temp file under /tmp for the odd time # the script will use the EXIT path _SENTRY_LOG_FILE=$(mktemp /tmp/sentry.envrc.$$.out || mktemp /tmp/sentry.envrc.XXXXXXXX.out) diff --git a/config/hooks/pre-commit b/config/hooks/pre-commit index dda50c54740d54..6bf9e1bdcebaea 100755 --- a/config/hooks/pre-commit +++ b/config/hooks/pre-commit @@ -16,13 +16,8 @@ if sys.version_info.major < 3: try: import sentry_sdk - if os.environ.get("SENTRY_DSN"): - sentry_sdk.init(dsn=os.environ["SENTRY_DSN"]) - else: - sys.stdout.write( - "WARNING: Errors in this file will not be reported to Sentry since SENTRY_DSN is not set.\n" - "Use this command to report the issue: make direnv-help\n\n" - ) + if not os.environ.get("SENTRY_DEVENV_NO_REPORT"): + sentry_sdk.init(dsn="https://9bdb053cb8274ea69231834d1edeec4c@o1.ingest.sentry.io/5723503") except ModuleNotFoundError: sys.stdout.write( "WARNING: Sentry SDK not installed, thus, errors will not be reported. Run: make install-py-dev\n" diff --git a/scripts/lib.sh b/scripts/lib.sh index de7b6e284b8f89..64aa08f8c50f4f 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -28,10 +28,13 @@ configure-sentry-cli() { # We can remove this after it's fixed # https://github.com/getsentry/sentry-cli/pull/1059 export SENTRY_CLI_NO_EXIT_TRAP=${SENTRY_CLI_NO_EXIT_TRAP-0} - if [ -n "${SENTRY_DSN+x}" ] && [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; then + if [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; then if ! require sentry-cli; then curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION=2.0.4 bash fi + # This exported variable does not persist outside of the calling script, thus, not affecting other + # parts of the system + export SENTRY_DSN="https://9bdb053cb8274ea69231834d1edeec4c@o1.ingest.sentry.io/5723503" eval "$(sentry-cli bash-hook)" fi }