Skip to content

Commit 9ab1d73

Browse files
fix formatting
1 parent c59d998 commit 9ab1d73

2 files changed

Lines changed: 20 additions & 27 deletions

File tree

drift/instrumentation/requests/e2e-tests/src/app.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def text_response():
261261
except Exception as e:
262262
return jsonify({"error": str(e)}), 500
263263

264+
264265
@app.route("/test/session-send-direct", methods=["GET"])
265266
def session_send_direct():
266267
try:
@@ -273,37 +274,33 @@ def session_send_direct():
273274
# Call send() directly - bypasses request() method
274275
response = session.send(prepared, timeout=10)
275276

276-
return jsonify({
277-
"status_code": response.status_code,
278-
"data": response.json(),
279-
"test": "session-send-direct"
280-
})
277+
return jsonify({"status_code": response.status_code, "data": response.json(), "test": "session-send-direct"})
281278
except Exception as e:
282279
return jsonify({"error": str(e)}), 500
283280

281+
284282
@app.route("/test/streaming-iter-lines", methods=["GET"])
285283
def test_streaming_iter_lines():
286284
"""Test streaming response using iter_lines."""
287285
try:
288286
response = requests.get(
289287
"https://httpbin.org/stream/5", # Returns 5 JSON lines
290288
stream=True,
291-
timeout=10
289+
timeout=10,
292290
)
293291
# Consume the stream using iter_lines
294292
lines = []
295293
for line in response.iter_lines():
296294
if line:
297-
lines.append(line.decode('utf-8'))
295+
lines.append(line.decode("utf-8"))
298296

299-
return jsonify({
300-
"test": "streaming-iter-lines",
301-
"status_code": response.status_code,
302-
"lines_received": len(lines)
303-
})
297+
return jsonify(
298+
{"test": "streaming-iter-lines", "status_code": response.status_code, "lines_received": len(lines)}
299+
)
304300
except Exception as e:
305301
return jsonify({"error": str(e)}), 500
306302

303+
307304
@app.route("/test/response-hooks", methods=["GET"])
308305
def test_response_hooks():
309306
"""Test response hooks that modify response."""
@@ -316,18 +313,16 @@ def response_hook(response, *args, **kwargs):
316313
hook_status["value"] = response.status_code
317314
return response
318315

319-
response = requests.get(
320-
"https://httpbin.org/get",
321-
hooks={"response": response_hook},
322-
timeout=10
323-
)
316+
response = requests.get("https://httpbin.org/get", hooks={"response": response_hook}, timeout=10)
324317

325-
return jsonify({
326-
"test": "response-hooks",
327-
"status_code": response.status_code,
328-
"hook_called": hook_called["value"],
329-
"hook_status": hook_status["value"]
330-
})
318+
return jsonify(
319+
{
320+
"test": "response-hooks",
321+
"status_code": response.status_code,
322+
"hook_called": hook_called["value"],
323+
"hook_status": hook_status["value"],
324+
}
325+
)
331326
except Exception as e:
332327
return jsonify({"error": str(e)}), 500
333328

drift/instrumentation/requests/instrumentation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def original_call():
131131
# REPLAY mode: Use handle_replay_mode for proper background request handling
132132
if sdk.mode == TuskDriftMode.REPLAY:
133133
return handle_replay_mode(
134-
replay_mode_handler=lambda: instrumentation_self._handle_replay_send(
135-
sdk, request, **kwargs
136-
),
134+
replay_mode_handler=lambda: instrumentation_self._handle_replay_send(sdk, request, **kwargs),
137135
no_op_request_handler=lambda: instrumentation_self._get_default_response(url),
138136
is_server_request=False,
139137
)
@@ -182,7 +180,6 @@ def _handle_record_send(
182180
Similar to _handle_record but works with PreparedRequest objects.
183181
184182
Args:
185-
sdk: TuskDrift instance
186183
session_self: Session instance
187184
prepared_request: PreparedRequest object
188185
is_pre_app_start: Whether this is before app start
@@ -319,6 +316,7 @@ def _handle_replay_send(
319316
# Dispatch response hooks (matches Session.send() behavior)
320317
# This ensures hooks registered via hooks={"response": callback} are called
321318
from requests.hooks import dispatch_hook
319+
322320
mock_response = dispatch_hook("response", prepared_request.hooks, mock_response, **kwargs)
323321
return mock_response
324322

0 commit comments

Comments
 (0)