22
33import logging
44from collections .abc import Mapping
5- from datetime import datetime , timezone
65from typing import Any
76
87import sentry_sdk
98from taskbroker_client .retry import Retry
10- from taskbroker_client .state import current_task
119from urllib3 .exceptions import HTTPError
1210
1311from sentry .integrations .github .webhook_types import GithubWebhookType
3836MAX_RETRIES = 5
3937DELAY_BETWEEN_RETRIES = 60 # 1 minute
4038RETRYABLE_ERRORS = (HTTPError ,)
41- METRICS_PREFIX = "seer.code_review.task"
4239
4340
4441def 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)
110106def 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