@@ -129,10 +129,8 @@ def request(
129129 )
130130 except CircuitBreakerError as e :
131131 logger .warning (
132- "Circuit breaker is open for host %s, blocking telemetry request to %s: %s " ,
132+ "Circuit breaker is open for host %s, blocking telemetry request" ,
133133 self ._host ,
134- url ,
135- e ,
136134 )
137135 raise
138136 except Exception as e :
@@ -150,21 +148,18 @@ def request_context(
150148 ):
151149 """Context manager for making HTTP requests with circuit breaker protection."""
152150 try :
153- # Use circuit breaker to protect the request
154- def _make_request ():
155- with self ._delegate .request_context (
156- method , url , headers , ** kwargs
157- ) as response :
158- return response
159-
160- response = self ._circuit_breaker .call (_make_request )
161- yield response
151+ # Keep the context manager open while yielding the response
152+ # Circuit breaker will track failures through the exception handling
153+ with self ._delegate .request_context (
154+ method , url , headers , ** kwargs
155+ ) as response :
156+ # Record success with circuit breaker before yielding
157+ self ._circuit_breaker .call (lambda : None )
158+ yield response
162159 except CircuitBreakerError as e :
163160 logger .warning (
164- "Circuit breaker is open for host %s, blocking telemetry request to %s: %s " ,
161+ "Circuit breaker is open for host %s, blocking telemetry request" ,
165162 self ._host ,
166- url ,
167- e ,
168163 )
169164 raise
170165 except Exception as e :
0 commit comments