Skip to content
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
41 changes: 25 additions & 16 deletions src/sentry/seer/agent/service_map_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Any, cast

import orjson
from sentry_sdk import traces

from sentry import options
from sentry.search.eap.types import SearchResolverConfig
Expand All @@ -27,7 +28,6 @@
)
from sentry.snuba.referrer import Referrer
from sentry.snuba.spans_rpc import Spans
from sentry.utils.tracing import set_span_data, start_span

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,10 +79,13 @@ def _process_rows(rows: list[dict]) -> None:

# Broad scan: Org-wide — only segments WITH a parent (cross-project candidates).
page_limit = min(_SNUBA_MAX_ROWS, max_segments)
with start_span(
op="explorer.service_map.broad_scan", name="explorer.service_map.broad_scan"
with traces.start_span(
name="explorer.service_map.broad_scan",
attributes={
"sentry.op": "explorer.service_map.broad_scan",
"limit": page_limit,
},
) as span:
set_span_data(span, "limit", page_limit)
result = Spans.run_table_query(
params=snuba_params,
query_string="is_transaction:true has:parent_span",
Expand All @@ -95,8 +98,8 @@ def _process_rows(rows: list[dict]) -> None:
)
rows = result.get("data", [])
_process_rows(rows)
set_span_data(span, "rows_returned", len(rows))
set_span_data(span, "covered_projects", len(covered_project_ids))
span.set_attribute("rows_returned", len(rows))
span.set_attribute("covered_projects", len(covered_project_ids))

# Fallback scan: One scoped query for projects with no representation in the broad scan.
# No has:parent_span filter — broad scan to give low-traffic projects a second chance.
Expand All @@ -108,11 +111,14 @@ def _process_rows(rows: list[dict]) -> None:
)
uncovered_params = dataclasses.replace(snuba_params, projects=uncovered)
page_limit = min(_SNUBA_MAX_ROWS, max_segments)
with start_span(
op="explorer.service_map.fallback_scan", name="explorer.service_map.fallback_scan"
with traces.start_span(
name="explorer.service_map.fallback_scan",
attributes={
"sentry.op": "explorer.service_map.fallback_scan",
"uncovered_projects": len(uncovered),
"limit": page_limit,
},
) as span:
set_span_data(span, "uncovered_projects", len(uncovered))
set_span_data(span, "limit", page_limit)
result = Spans.run_table_query(
params=uncovered_params,
query_string="is_transaction:true",
Expand All @@ -131,7 +137,7 @@ def _process_rows(rows: list[dict]) -> None:
)
rows = result.get("data", [])
_process_rows(rows)
set_span_data(span, "rows_returned", len(rows))
span.set_attribute("rows_returned", len(rows))

unique_parent_span_ids = list(segments_by_parent.keys())
if not unique_parent_span_ids:
Expand All @@ -143,11 +149,14 @@ def _process_rows(rows: list[dict]) -> None:
edges_by_pair: dict[tuple[int, str, int, str], int] = defaultdict(int)
batch_size = options.get("explorer.service_map.parent_span_batch_size")

with start_span(
op="explorer.service_map.resolve_parents", name="explorer.service_map.resolve_parents"
with traces.start_span(
name="explorer.service_map.resolve_parents",
attributes={
"sentry.op": "explorer.service_map.resolve_parents",
"unique_parent_spans": len(unique_parent_span_ids),
"batch_count": math.ceil(len(unique_parent_span_ids) / batch_size),
},
) as span:
set_span_data(span, "unique_parent_spans", len(unique_parent_span_ids))
set_span_data(span, "batch_count", math.ceil(len(unique_parent_span_ids) / batch_size))
for i in range(0, len(unique_parent_span_ids), batch_size):
batch = unique_parent_span_ids[i : i + batch_size]
span_ids = ",".join(batch)
Expand Down Expand Up @@ -179,7 +188,7 @@ def _process_rows(rows: list[dict]) -> None:
segment["child_project_slug"],
)
edges_by_pair[edge_key] += 1
set_span_data(span, "edges_found", len(edges_by_pair))
span.set_attribute("edges_found", len(edges_by_pair))

edges = [
{
Expand Down
8 changes: 5 additions & 3 deletions src/sentry/seer/autofix/autofix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from datetime import datetime, timedelta
from typing import Any

from sentry_sdk import traces

from sentry import tagstore
from sentry.api.endpoints.organization_trace import OrganizationTraceEndpoint
from sentry.constants import ObjectStatus
Expand All @@ -15,7 +17,6 @@
from sentry.services.eventstore.models import Event, GroupEvent
from sentry.snuba.referrer import Referrer
from sentry.utils.concurrent import ContextPropagatingThreadPoolExecutor
from sentry.utils.tracing import start_span

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,8 +89,9 @@ def _fetch_trace():
}

try:
with start_span(
op="seer.autofix.get_trace_tree_for_event", name="seer.autofix.get_trace_tree_for_event"
with traces.start_span(
name="seer.autofix.get_trace_tree_for_event",
attributes={"sentry.op": "seer.autofix.get_trace_tree_for_event"},
):
with ContextPropagatingThreadPoolExecutor() as executor:
future = executor.submit(_fetch_trace)
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/seer/autofix/autofix_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pydantic import BaseModel
from rest_framework.exceptions import PermissionDenied
from scm.types import GetBranchProtocol, GetRepositoryProtocol
from sentry_sdk import traces

from sentry import features, quotas
from sentry.analytics.events.autofix_events import (
Expand Down Expand Up @@ -85,7 +86,6 @@
from sentry.sentry_apps.tasks.sentry_apps import broadcast_webhooks_for_organization
from sentry.sentry_apps.utils.webhooks import SeerActionType
from sentry.utils import json, metrics
from sentry.utils.tracing import trace

if TYPE_CHECKING:
from django.contrib.auth.models import AnonymousUser
Expand Down Expand Up @@ -590,7 +590,7 @@ def _assert_existing_run_belongs_to_group(group: Group, run_id: int) -> None:
raise SeerPermissionError(UNKNOWN_RUN_ID_FOR_GROUP)


@trace
@traces.trace
def trigger_autofix_agent(
group: Group,
step: AutofixStep,
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/seer/autofix/commit_author.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.contrib.auth.models import AnonymousUser
from django.db.models import Q
from sentry_sdk import traces

from sentry.integrations.models.external_actor import ExternalActor
from sentry.integrations.types import ExternalProviders
Expand All @@ -23,7 +24,6 @@
from sentry.users.services.user.model import RpcUser
from sentry.users.services.user.service import user_service
from sentry.utils import json, metrics
from sentry.utils.tracing import trace

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -175,7 +175,7 @@ def _feedback_actor(source: FeedbackSourceBase) -> tuple[str, str] | None:
return ("github", user.login.lstrip("@").lower())


@trace
@traces.trace
def commit_author_for_feedback(
items: Sequence[Feedback], organization_id: int
) -> SeerCommitAuthor | None:
Expand Down
11 changes: 7 additions & 4 deletions src/sentry/seer/autofix/issue_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sentry_sdk
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from sentry_sdk import traces
from taskbroker_client.retry import Retry
from urllib3 import BaseHTTPResponse
from urllib3.connectionpool import HTTPConnectionPool
Expand Down Expand Up @@ -63,7 +64,6 @@
from sentry.utils.cache import cache
from sentry.utils.locking import UnableToAcquireLock
from sentry.utils.settings import is_self_hosted
from sentry.utils.tracing import start_span

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -171,7 +171,9 @@ def _trigger_autofix_task(
sentry_sdk.capture_exception(e)
return

with start_span(op="ai_summary.trigger_autofix", name="ai_summary.trigger_autofix"):
with traces.start_span(
name="ai_summary.trigger_autofix", attributes={"sentry.op": "ai_summary.trigger_autofix"}
):
try:
group = Group.objects.get(id=group_id)
except Group.DoesNotExist:
Expand Down Expand Up @@ -355,8 +357,9 @@ def get_and_update_group_fixability_score(
extra={"group_id": group.id},
)

with start_span(
op="ai_summary.generate_fixability_score", name="ai_summary.generate_fixability_score"
with traces.start_span(
name="ai_summary.generate_fixability_score",
attributes={"sentry.op": "ai_summary.generate_fixability_score"},
):
issue_summary = _generate_fixability_score(group, summary=summary)

Expand Down
17 changes: 8 additions & 9 deletions src/sentry/seer/autofix/on_completion_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.db import router, transaction
from django.utils import timezone
from pydantic import ValidationError
from sentry_sdk import traces

from sentry import analytics, features
from sentry.analytics.events.autofix_events import (
Expand Down Expand Up @@ -73,7 +74,6 @@
from sentry.sentry_apps.tasks.sentry_apps import broadcast_webhooks_for_organization
from sentry.sentry_apps.utils.webhooks import SeerActionType
from sentry.utils import metrics
from sentry.utils.tracing import start_span
from sentry.viewer_context import get_viewer_context

if TYPE_CHECKING:
Expand Down Expand Up @@ -130,15 +130,14 @@ def execute(cls, organization: Organization, run_id: int) -> None:
organization: The organization context
run_id: The ID of the completed run
"""
with (
sentry_sdk.isolation_scope(),
start_span(
with sentry_sdk.isolation_scope():
traces.new_trace()
with traces.start_span(
name="autofix.on_completion_hook",
op="function",
transaction=True,
),
):
cls._execute(organization, run_id)
attributes={"sentry.op": "function"},
parent_span=None,
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Resolved
):
cls._execute(organization, run_id)

@classmethod
def _execute(cls, organization: Organization, run_id: int) -> None:
Expand Down
12 changes: 6 additions & 6 deletions src/sentry/seer/autofix/pr_iteration/check_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PaginationParams,
PullRequest,
)
from sentry_sdk import traces

from sentry import features
from sentry.constants import ObjectStatus
Expand All @@ -50,7 +51,6 @@
from sentry.seer.models import SeerApiError, SeerUnavailableError
from sentry.seer.models.run import SeerRun
from sentry.utils import metrics
from sentry.utils.tracing import trace

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -346,7 +346,7 @@ class CheckSuiteAutofixRun:
group_id: int


@trace
@traces.trace
def resolve_check_suite_autofix_run(
event: GithubCheckSuiteEvent, repositories: Sequence[Repository] | None = None
) -> CheckSuiteAutofixRun | None:
Expand Down Expand Up @@ -597,7 +597,7 @@ def pr_iteration_enabled(organization: Organization) -> bool:
)


@trace
@traces.trace
def resolve_green_check_suite(
check_suite_event: CheckSuiteEvent,
) -> ResolvedGreenCheckSuite | None:
Expand Down Expand Up @@ -728,7 +728,7 @@ def inspect_check_suite_head(
)


@trace
@traces.trace
def confirm_green_check_suite(
resolved: ResolvedGreenCheckSuite,
) -> GreenCheckSuiteContext | None:
Expand Down Expand Up @@ -756,7 +756,7 @@ def confirm_green_check_suite(
)


@trace
@traces.trace
def should_defer_pr_iteration(resolved: ResolvedGreenCheckSuite) -> bool:
"""Whether a PR-iteration event on this head must leave a parked consume deferred.

Expand Down Expand Up @@ -847,7 +847,7 @@ def record(self, *, outcome: str) -> None:
)


@trace
@traces.trace
def sweep_check_runs(
scm: SourceCodeManager, head_sha: str, *, log_extra: Mapping[str, object]
) -> CheckRunsSweep | None:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/seer/autofix/pr_iteration/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import TypeVar

from django.utils import timezone
from sentry_sdk import traces

from sentry import analytics
from sentry.analytics.events.pr_iteration_events import (
Expand All @@ -43,7 +44,6 @@
from sentry.seer.autofix.pr_iteration.pause import PauseReason
from sentry.seer.autofix.pr_iteration.tracing import set_pr_iteration_attributes
from sentry.seer.models.run import SeerRun, SeerRunPrIteration
from sentry.utils.tracing import trace

EventT = TypeVar("EventT", bound=analytics.Event)

Expand Down Expand Up @@ -446,7 +446,7 @@ def record_pr_iteration_failure_reason(
log_ctx.error("autofix.pr_iteration.details.failure_reason_failed")


@trace
@traces.trace
def complete_pr_iteration_details(
*,
log_ctx: PrIterationLogContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Literal

from pydantic import Field, PrivateAttr, root_validator
from sentry_sdk import traces

from sentry.seer.agent.client_models import SeerRunState
from sentry.seer.autofix.pr_iteration.check_suites import (
Expand All @@ -24,7 +25,6 @@
TriggerDecision,
)
from sentry.utils import metrics
from sentry.utils.tracing import trace

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -163,7 +163,7 @@ def _live_head(self, run_state: SeerRunState) -> LivePullRequestHead:
)
return LivePullRequestHead("unexpected_error")

@trace
@traces.trace
def should_consume(self, run_state: SeerRunState) -> Decision:
head_sha, repo_name, matched = check_suite_head_match(self.event, run_state)
attempt_key = self.check_suite_attempt_key()
Expand Down Expand Up @@ -199,7 +199,7 @@ def should_consume(self, run_state: SeerRunState) -> Decision:
return Decision(ok=False, reason="live_head_mismatch")
return Decision(ok=True, reason="head_matches")

@trace
@traces.trace
def should_trigger(self, run_state: SeerRunState) -> TriggerDecision:
try:
autofix_run = self.autofix_run
Expand Down
Loading
Loading