Skip to content

Commit cdc33f6

Browse files
authored
ref(code_review): Do not emit enqueued_at (#111398)
We can use `taskworker.worker.execution_latency` instead.
1 parent d4fb07f commit cdc33f6

File tree

4 files changed

+39
-141
lines changed

4 files changed

+39
-141
lines changed

src/sentry/seer/code_review/webhooks/check_run.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import enum
1212
import logging
1313
from collections.abc import Mapping
14-
from datetime import datetime, timezone
1514
from enum import StrEnum
1615
from typing import Any
1716

@@ -126,7 +125,6 @@ def handle_check_run_event(
126125
seer_path=SeerEndpoint.PR_REVIEW_RERUN.value,
127126
# A reduced payload is enough for the task to process.
128127
event_payload={"original_run_id": validated_event.check_run.external_id},
129-
enqueued_at_str=datetime.now(timezone.utc).isoformat(),
130128
tags=tags,
131129
)
132130
record_webhook_enqueued(github_event, action)

src/sentry/seer/code_review/webhooks/task.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import logging
44
from collections.abc import Mapping
5-
from datetime import datetime, timezone
65
from typing import Any
76

87
import sentry_sdk
98
from taskbroker_client.retry import Retry
10-
from taskbroker_client.state import current_task
119
from urllib3.exceptions import HTTPError
1210

1311
from sentry.integrations.github.webhook_types import GithubWebhookType
@@ -38,7 +36,6 @@
3836
MAX_RETRIES = 5
3937
DELAY_BETWEEN_RETRIES = 60 # 1 minute
4038
RETRYABLE_ERRORS = (HTTPError,)
41-
METRICS_PREFIX = "seer.code_review.task"
4239

4340

4441
def schedule_task(
@@ -95,7 +92,6 @@ def schedule_task(
9592
process_github_webhook_event.delay(
9693
seer_path=get_seer_path_for_request(github_event.value, github_event_action),
9794
event_payload=payload,
98-
enqueued_at_str=datetime.now(timezone.utc).isoformat(),
9995
tags=tags,
10096
)
10197
record_webhook_enqueued(github_event, github_event_action)
@@ -109,7 +105,6 @@ def schedule_task(
109105
)
110106
def process_github_webhook_event(
111107
*,
112-
enqueued_at_str: str,
113108
seer_path: str,
114109
event_payload: Mapping[str, Any],
115110
tags: Mapping[str, Any] | None = None,
@@ -119,14 +114,13 @@ def process_github_webhook_event(
119114
Forward a validated code-review payload to Seer.
120115
121116
Args:
122-
enqueued_at_str: The timestamp when the task was enqueued
123117
seer_path: The path to the Seer API endpoint to call
124118
event_payload: The payload (already validated before scheduling)
125119
tags: Sentry SDK tags to set on this task's scope for error correlation
126120
**kwargs: Absorbs legacy serialized task arguments from in-flight work
121+
(e.g. removed ``enqueued_at_str``).
127122
"""
128123
status = "success"
129-
should_record_latency = True
130124
try:
131125
if tags:
132126
sentry_sdk.set_tags(tags)
@@ -137,36 +131,7 @@ def process_github_webhook_event(
137131
make_seer_request(path=seer_path, payload=event_payload, viewer_context=viewer_context)
138132
except Exception as e:
139133
status = e.__class__.__name__
140-
# Retryable errors are automatically retried by taskworker.
141-
if isinstance(e, RETRYABLE_ERRORS):
142-
task = current_task()
143-
if task and task.retries_remaining:
144-
should_record_latency = False
145134
raise
146135
finally:
147136
if status != "success":
148137
metrics.incr(f"{PREFIX}.error", tags={"error_status": status}, sample_rate=1.0)
149-
if should_record_latency:
150-
record_latency(status, enqueued_at_str)
151-
152-
153-
def record_latency(status: str, enqueued_at_str: str) -> None:
154-
latency_ms = calculate_latency_ms(enqueued_at_str)
155-
if latency_ms > 0:
156-
metrics.timing(f"{PREFIX}.e2e_latency", latency_ms, tags={"status": status})
157-
158-
159-
def calculate_latency_ms(timestamp_str: str) -> int:
160-
"""Calculate the latency in milliseconds between the given timestamp and now."""
161-
try:
162-
timestamp = datetime.fromisoformat(timestamp_str)
163-
now = datetime.now(timezone.utc)
164-
return int((now - timestamp).total_seconds() * 1000)
165-
except (ValueError, TypeError) as e:
166-
# Don't fail the task if timestamp parsing fails
167-
logger.warning(
168-
"%s.invalid_timestamp",
169-
PREFIX,
170-
extra={"timestamp": timestamp_str, "error": str(e)},
171-
)
172-
return 0

0 commit comments

Comments
 (0)