Skip to content

ref(onboardingtasks): Add more instrumentation to help investigate bug #85826

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/sentry/api/endpoints/organization_onboarding_tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sentry_sdk
from django.utils import timezone
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -8,7 +9,7 @@
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission
from sentry.api.serializers import serialize
from sentry.models.organizationonboardingtask import OnboardingTaskStatus
from sentry.models.organizationonboardingtask import OnboardingTask, OnboardingTaskStatus


class OnboardingTaskPermission(OrganizationPermission):
Expand Down Expand Up @@ -62,6 +63,14 @@ def post(self, request: Request, organization) -> Response:
values=values,
)

if created and task_id == OnboardingTask.FIRST_PROJECT:
scope = sentry_sdk.get_current_scope()
scope.set_extra("org", organization.id)
sentry_sdk.capture_message(
f"Onboarding task {task_id} was created unexpectedly. It should have been updated instead.",
level="warning",
)
Comment on lines +66 to +72
Copy link
Member

Choose a reason for hiding this comment

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

If the task should not be create here, but only updated, why are we calling create_or_update in the method?

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 thought about replacing it with update only but I was afraid of causing issues, so instead I decided to first add the capture_message and see if this is actually happening - I know it does happen for tests but that is ok


if rows_affected or created:
onboarding_tasks.try_mark_onboarding_complete(organization.id)

Expand Down
10 changes: 2 additions & 8 deletions src/sentry/models/organizationonboardingtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def record(self, organization_id, task, **kwargs):
try:
with transaction.atomic(router.db_for_write(OrganizationOnboardingTask)):
self.create(organization_id=organization_id, task=task, **kwargs)
# Store marker to prevent running all the time
cache.set(cache_key, 1, 3600)
return True
except IntegrityError as error:
if task == OnboardingTask.FIRST_PROJECT:
Expand All @@ -74,14 +76,6 @@ def record(self, organization_id, task, **kwargs):
level="warning",
)
pass

# Store marker to prevent running all the time
cache.set(cache_key, 1, 3600)
Copy link
Member Author

Choose a reason for hiding this comment

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

We should only set the cache if the task was successfully created

if task == OnboardingTask.FIRST_PROJECT:
sentry_sdk.capture_message(
f"First project task not created for org {organization_id}, cache key {cache_key} set",
level="warning",
)
Comment on lines -81 to -84
Copy link
Member Author

Choose a reason for hiding this comment

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

removing this as it is super noisy!

return False


Expand Down
Loading