Skip to content

fix(auto_source_config): Pass group_id to avoid Snuba call #83650

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
merged 11 commits into from
Jan 20, 2025
28 changes: 19 additions & 9 deletions src/sentry/tasks/auto_source_code_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DeriveCodeMappingsErrorReason(StrEnum):
EMPTY_TREES = "The trees are empty."


def process_error(error: ApiError, extra: dict[str, str]) -> None:
def process_error(error: ApiError, extra: dict[str, Any]) -> None:
"""Log known issues and report unknown ones"""
if error.json:
json_data: Any = error.json
Expand Down Expand Up @@ -85,27 +85,37 @@ def process_error(error: ApiError, extra: dict[str, str]) -> None:
default_retry_delay=60 * 10,
max_retries=3,
)
def auto_source_code_config(project_id: int, event_id: str, **kwargs: Any) -> None:
def auto_source_code_config(
project_id: int, group_id: int | None, event_id: str, **kwargs: Any
) -> None:
"""
Process errors for customers with source code management installed and calculate code mappings
among other things.

This task is queued at most once per hour per project.
"""
project = Project.objects.get(id=project_id)
org: Organization = Organization.objects.get(id=project.organization_id)
org = Organization.objects.get(id=project.organization_id)
set_tag("organization.slug", org.slug)
# When you look at the performance page the user is a default column
set_user({"username": org.slug})
set_tag("project.slug", project.slug)
extra: dict[str, Any] = {"organization.slug": org.slug, "event_id": event_id}

event = eventstore.backend.get_event_by_id(project_id, event_id)
extra = {
"organization.slug": org.slug,
"project_id": project_id,
"group_id": group_id,
Copy link
Member

@JoshFerge JoshFerge Jan 17, 2025

Choose a reason for hiding this comment

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

do you have to access it using kwargs["group_id"] too? or is making it optional in the signature enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let us not find out the wrong way.
I have changed it to None by default.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine to have it in the signature with = None

"event_id": event_id,
}

if group_id is None:
event = eventstore.backend.get_event_by_id(project_id, event_id)
else:
event = eventstore.backend.get_event_by_id(project_id, event_id, group_id)
if event is None:
logger.error("Event not found.", extra={"project_id": project_id, "event_id": event_id})
logger.error("Event not found.", extra=extra)
return

stacktrace_paths: list[str] = identify_stacktrace_paths(event.data)
stacktrace_paths = identify_stacktrace_paths(event.data)
if not stacktrace_paths:
logger.info("No stacktrace paths found.", extra=extra)
return
Expand Down Expand Up @@ -133,7 +143,7 @@ def auto_source_code_config(project_id: int, event_id: str, **kwargs: Any) -> No
lifecycle.record_halt(error, extra)
return
except UnableToAcquireLock as error:
extra["error"] = error
extra["error"] = str(error)
lifecycle.record_failure(error, extra)
return
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/tasks/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def process_code_mappings(job: PostProcessJob) -> None:
else:
return

auto_source_code_config.delay(project.id, event_id=event.event_id)
auto_source_code_config.delay(project.id, event_id=event.event_id, group_id=group_id)
Copy link
Member

Choose a reason for hiding this comment

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

Just make sure that the **kwargs in the definition is already deployed before this deploys. I assume it is, just want to be doubly sure


except Exception:
logger.exception("Failed to process automatic source code config")
Expand Down
Loading
Loading