Skip to content
Draft
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
5 changes: 1 addition & 4 deletions src/sentry/ai_monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
)
from sentry.models.project import Project
from sentry.options.rollout import in_rollout_group
from sentry.seer.signed_seer_api import SeerViewerContext
from sentry.silo.base import SiloMode
from sentry.tasks.base import instrumented_task
from sentry.taskworker.namespaces import ai_agent_monitoring_tasks
Expand Down Expand Up @@ -85,9 +84,7 @@ def generate_ai_conversation_title(
metrics.incr("ai_monitoring.conversation_title.skip", tags={"reason": "later_or_equal_ts"})
return

title = generate_conversation_title(
first_user_message, viewer_context=SeerViewerContext(organization_id=organization.id)
)
title = generate_conversation_title(first_user_message)
stored_conversation_id = clamp_conversation_id_for_storage(conversation_id)

# Update an existing row only if this span is still the earliest.
Expand Down
3 changes: 0 additions & 3 deletions src/sentry/deletions/tasks/seer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from taskbroker_client.retry import Retry
from urllib3.exceptions import HTTPError

from sentry.seer.signed_seer_api import SeerViewerContext
from sentry.silo.base import SiloMode
from sentry.tasks.base import instrumented_task
from sentry.taskworker.namespaces import deletion_tasks
Expand Down Expand Up @@ -36,7 +35,6 @@ def notify_seer_repository_deleted(
# imported here to avoid circular imports
from sentry.seer.code_review.utils import SeerEndpoint, make_seer_request

viewer_context = SeerViewerContext(organization_id=organization_id)
make_seer_request(
path=SeerEndpoint.REPOSITORY_OFFBOARD.value,
payload={
Expand All @@ -45,7 +43,6 @@ def notify_seer_repository_deleted(
"provider": provider,
"repository_name": repository_name,
},
viewer_context=viewer_context,
)
logger.info(
"seer.forward_repository_delete.success",
Expand Down
6 changes: 1 addition & 5 deletions src/sentry/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
from sentry.receivers.onboarding import record_release_received
from sentry.releases.auto_creation import should_auto_create_releases
from sentry.reprocessing2 import is_reprocessed_event
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.services.eventstore.processing import event_processing_store
from sentry.signals import (
first_event_received,
Expand Down Expand Up @@ -1978,7 +1978,6 @@ def make_severity_score_request(
body: SeverityScoreRequest,
connection_pool: HTTPConnectionPool | None = None,
timeout: int | float | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
payload: SeverityScoreRequest = {**body}
if options.get("processing.severity-backlog-test.timeout"):
Expand All @@ -1990,7 +1989,6 @@ def make_severity_score_request(
"/v0/issues/severity-score",
body=orjson.dumps(payload),
timeout=timeout,
viewer_context=viewer_context,
)


Expand Down Expand Up @@ -2211,12 +2209,10 @@ def _get_severity_score(event: Event) -> tuple[float, str]:
"issues.severity.seer-timeout",
settings.SEER_SEVERITY_TIMEOUT,
)
viewer_context = SeerViewerContext(organization_id=event.project.organization_id)
response = make_severity_score_request(
payload,
connection_pool=severity_connection_pool,
timeout=timeout,
viewer_context=viewer_context,
)
severity = orjson.loads(response.data).get("severity")
reason = "ml"
Expand Down
11 changes: 2 additions & 9 deletions src/sentry/feedback/usecases/ingest/create_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from sentry.models.group import GroupStatus
from sentry.models.project import Project
from sentry.seer.seer_setup import has_seer_access
from sentry.seer.signed_seer_api import SeerViewerContext
from sentry.signals import first_feedback_received, first_new_feedback_received
from sentry.types.group import GroupSubStatus
from sentry.utils import json, metrics
Expand Down Expand Up @@ -275,17 +274,14 @@ def create_feedback_issue(
_seer_vc = ViewerContext(
organization_id=project.organization_id, project_id=project.id, actor_type=ActorType.SYSTEM
)
viewer_context = SeerViewerContext(organization_id=project.organization_id)

# Spam detection.
is_message_spam = None
is_spam_enabled = spam_detection_enabled(project)
if is_spam_enabled:
# Will be None if the request fails
with viewer_context_scope(_seer_vc):
is_message_spam = is_spam_seer(
feedback_message, project.organization_id, viewer_context=viewer_context
)
is_message_spam = is_spam_seer(feedback_message, project.organization_id)

metrics.incr(
"feedback.create_feedback_issue.seer_spam_detection",
Expand Down Expand Up @@ -315,7 +311,6 @@ def create_feedback_issue(
feedback_message,
project.organization_id,
use_ai_title,
viewer_context=viewer_context,
)
)

Expand Down Expand Up @@ -352,9 +347,7 @@ def create_feedback_issue(
if should_query_seer:
try:
with viewer_context_scope(_seer_vc):
labels = generate_labels(
feedback_message, project.organization_id, viewer_context=viewer_context
)
labels = generate_labels(feedback_message, project.organization_id)
# This will rarely happen unless the user writes a really long feedback message
if len(labels) > MAX_AI_LABELS:
logger.info(
Expand Down
12 changes: 2 additions & 10 deletions src/sentry/grouping/ingest/seer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from sentry.grouping.variants import BaseVariant
from sentry.models.grouphash import GroupHash
from sentry.models.project import Project
from sentry.seer.signed_seer_api import SeerViewerContext
from sentry.seer.similarity.config import (
get_grouping_model_version,
should_send_to_seer_for_training,
Expand Down Expand Up @@ -362,11 +361,9 @@ def get_seer_similar_issues(

request_data, seer_request_metric_tags = _build_seer_request(event, variants)

viewer_context = SeerViewerContext(organization_id=event.project.organization_id)
seer_results, model_used = get_similarity_data_from_seer(
request_data,
{**seer_request_metric_tags, "hybrid_fingerprint": event_has_hybrid_fingerprint},
viewer_context=viewer_context,
)

# All of these will get overridden if we find a usable match
Expand Down Expand Up @@ -434,9 +431,7 @@ def get_seer_similar_issues(

# We only want this for the side effect, and we know it'll return no matches, so we don't
# bother to capture the return value.
get_similarity_data_from_seer(
request_data, seer_request_metric_tags, viewer_context=viewer_context
)
get_similarity_data_from_seer(request_data, seer_request_metric_tags)

is_hybrid_fingerprint_case = (
event_has_hybrid_fingerprint
Expand Down Expand Up @@ -726,11 +721,8 @@ def maybe_send_seer_for_new_model_training(

request_data, metric_tags = _build_seer_request(event, variants, training_mode=True)

viewer_context = SeerViewerContext(organization_id=event.project.organization_id)
try:
get_similarity_data_from_seer(
request_data, metric_tags, raise_on_error=True, viewer_context=viewer_context
)
get_similarity_data_from_seer(request_data, metric_tags, raise_on_error=True)
except Exception as e:
sentry_sdk.capture_exception(
e,
Expand Down
3 changes: 1 addition & 2 deletions src/sentry/pr_metrics/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
UpdatePrMetricsErrorResponse,
UpdatePrMetricsSuccessResponse,
)
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.utils import json, metrics

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -235,7 +235,6 @@ def forward_pr_to_seer_judge(pull_request: PullRequest, repository: Repository)
connection_pool=seer_pr_metrics_connection_pool,
path=SEER_PR_METRICS_JUDGE_PATH,
body=payload.json().encode("utf-8"),
viewer_context=SeerViewerContext(organization_id=pull_request.organization_id),
)
if response.status >= 500 or response.status == 429:
raise HTTPError(f"Seer judge forward returned retryable status {response.status}")
Expand Down
4 changes: 0 additions & 4 deletions src/sentry/replays/usecases/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from sentry.replays.usecases.events import archive_event
from sentry.replays.usecases.query import execute_query, handle_search_filters
from sentry.replays.usecases.query.configs.aggregate import search_config as agg_search_config
from sentry.seer.signed_seer_api import SeerViewerContext
from sentry.utils.concurrent import ContextPropagatingThreadPoolExecutor
from sentry.utils.retries import ConditionalRetryPolicy, exponential_delay
from sentry.utils.snuba import (
Expand Down Expand Up @@ -201,14 +200,11 @@ def delete_seer_replay_data(organization_id: int, project_id: int, replay_ids: l
project_id=project_id,
)

viewer_context = SeerViewerContext(organization_id=organization_id)

try:
response = make_replay_delete_request(
seer_request,
timeout=5,
retries=Retry(total=1, backoff_factor=3), # 1 retry after a 3 second delay.
viewer_context=viewer_context,
)
except Exception:
logger.exception(
Expand Down
4 changes: 1 addition & 3 deletions src/sentry/seer/agent/snapshot_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from sentry.seer.sentry_data_models import AgentExportIndexesResponse
from sentry.seer.signed_seer_api import (
AgentExportIndexesRequest,
SeerViewerContext,
make_agent_export_indexes_request,
)
from sentry.utils.json import JSONDecodeError
Expand All @@ -20,9 +19,8 @@ def export_agent_indexes(*, org_id: int) -> AgentExportIndexesResponse:
Intended for local eval DB seeding — calls the Seer export endpoint and
returns the serialized table data.
"""
viewer_context = SeerViewerContext(organization_id=org_id)
body = AgentExportIndexesRequest(org_id=org_id)
response = make_agent_export_indexes_request(body, viewer_context=viewer_context)
response = make_agent_export_indexes_request(body)
if response.status >= 400:
raise SeerApiError("Seer export-indexes request failed", response.status)

Expand Down
7 changes: 2 additions & 5 deletions src/sentry/seer/anomaly_detection/delete_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sentry.models.organization import Organization
from sentry.net.http import connection_from_url
from sentry.seer.anomaly_detection.types import AlertInSeer, DataSourceType, DeleteAlertDataRequest
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.utils import json
from sentry.utils.json import JSONDecodeError

Expand All @@ -25,13 +25,11 @@
def make_delete_alert_data_request(
body: DeleteAlertDataRequest,
connection_pool: HTTPConnectionPool | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
return make_signed_seer_api_request(
connection_pool or seer_anomaly_detection_connection_pool,
SEER_ALERT_DELETION_URL,
body=json.dumps(body).encode("utf-8"),
viewer_context=viewer_context,
)


Expand Down Expand Up @@ -81,9 +79,8 @@ def delete_rule_in_seer(source_id: int, organization: Organization) -> bool:
extra_data = {
"source_id": source_id,
}
viewer_context = SeerViewerContext(organization_id=organization.id)
try:
response = make_delete_alert_data_request(body, viewer_context=viewer_context)
response = make_delete_alert_data_request(body)
except (TimeoutError, MaxRetryError):
logger.warning(
"Timeout error when hitting Seer delete rule data endpoint",
Expand Down
14 changes: 3 additions & 11 deletions src/sentry/seer/anomaly_detection/get_anomaly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TimeSeriesPoint,
)
from sentry.seer.anomaly_detection.utils import get_aggregate_type, translate_direction
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.snuba.models import QuerySubscription, SnubaQuery
from sentry.utils import json
from sentry.utils.json import JSONDecodeError
Expand Down Expand Up @@ -67,28 +67,24 @@ def _adjust_timestamps_for_time_window(
def make_detect_anomalies_request(
body: DetectAnomaliesRequest,
connection_pool: HTTPConnectionPool | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
return make_signed_seer_api_request(
connection_pool or SEER_ANOMALY_DETECTION_CONNECTION_POOL,
SEER_ANOMALY_DETECTION_ENDPOINT_URL,
body=json.dumps(body).encode("utf-8"),
retries=SEER_RETRIES,
viewer_context=viewer_context,
)


def make_get_anomaly_threshold_data_request(
body: GetAnomalyThresholdDataRequest,
connection_pool: HTTPConnectionPool | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
return make_signed_seer_api_request(
connection_pool or SEER_ANOMALY_DETECTION_CONNECTION_POOL,
SEER_ANOMALY_DETECTION_ALERT_DATA_URL,
body=json.dumps(body).encode("utf-8"),
retries=SEER_RETRIES,
viewer_context=viewer_context,
)


Expand Down Expand Up @@ -143,10 +139,7 @@ def get_anomaly_data_from_seer(
extra_data["dataset"] = snuba_query.dataset
try:
logger.info("Sending subscription update data to Seer", extra=extra_data)
viewer_context = SeerViewerContext(organization_id=subscription.project.organization_id)
response = make_detect_anomalies_request(
detect_anomalies_request, viewer_context=viewer_context
)
response = make_detect_anomalies_request(detect_anomalies_request)
except (TimeoutError, MaxRetryError):
logger.warning("Timeout error when hitting anomaly detection endpoint", extra=extra_data)
return None
Expand Down Expand Up @@ -229,9 +222,8 @@ def get_anomaly_threshold_data_from_seer(
start=start,
end=end,
)
viewer_context = SeerViewerContext(organization_id=subscription.project.organization_id)
try:
response = make_get_anomaly_threshold_data_request(body, viewer_context=viewer_context)
response = make_get_anomaly_threshold_data_request(body)
except (TimeoutError, MaxRetryError):
logger.warning("anomaly_threshold.timeout_error_hitting_seer_endpoint")
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DetectHistoricalAnomaliesRequest,
TimeSeriesPoint,
)
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.utils import json
from sentry.utils.json import JSONDecodeError

Expand All @@ -37,14 +37,12 @@
def make_detect_historical_anomalies_request(
body: DetectHistoricalAnomaliesRequest,
connection_pool: HTTPConnectionPool | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
return make_signed_seer_api_request(
connection_pool or seer_anomaly_detection_connection_pool,
SEER_ANOMALY_DETECTION_ENDPOINT_URL,
body=json.dumps(body).encode("utf-8"),
retries=SEER_RETRIES,
viewer_context=viewer_context,
)


Expand Down Expand Up @@ -136,9 +134,8 @@ def get_historical_anomaly_data_from_seer_preview(
"config": config,
"context": context,
}
viewer_context = SeerViewerContext(organization_id=organization_id)
try:
response = make_detect_historical_anomalies_request(body, viewer_context=viewer_context)
response = make_detect_historical_anomalies_request(body)
except (TimeoutError, MaxRetryError):
logger.warning("Timeout error when hitting anomaly detection endpoint", extra=extra_data)
return None
Expand Down
7 changes: 2 additions & 5 deletions src/sentry/seer/anomaly_detection/store_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
get_event_types,
translate_direction,
)
from sentry.seer.signed_seer_api import SeerViewerContext, make_signed_seer_api_request
from sentry.seer.signed_seer_api import make_signed_seer_api_request
from sentry.snuba.models import SnubaQuery, SnubaQueryEventType
from sentry.utils import json, metrics
from sentry.utils.json import JSONDecodeError
Expand All @@ -48,13 +48,11 @@
def make_store_data_request(
body: StoreDataRequest,
connection_pool: HTTPConnectionPool | None = None,
viewer_context: SeerViewerContext | None = None,
) -> BaseHTTPResponse:
return make_signed_seer_api_request(
connection_pool or seer_anomaly_detection_connection_pool,
SEER_ANOMALY_DETECTION_STORE_DATA_URL,
body=json.dumps(body).encode("utf-8"),
viewer_context=viewer_context,
)


Expand Down Expand Up @@ -243,9 +241,8 @@ def send_historical_data_to_seer_legacy(
"meta": json.dumps(historical_data.data.get("meta", {}).get("fields", {})),
},
)
viewer_context = SeerViewerContext(organization_id=alert_rule.organization.id)
try:
response = make_store_data_request(body, viewer_context=viewer_context)
response = make_store_data_request(body)
# See SEER_ANOMALY_DETECTION_TIMEOUT in sentry.conf.server.py
except (TimeoutError, MaxRetryError):
logger.warning(
Expand Down
Loading
Loading