Skip to content
Merged
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
65 changes: 65 additions & 0 deletions drift/instrumentation/requests/e2e-tests/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,71 @@ def text_response():
return jsonify({"error": str(e)}), 500


@app.route("/test/session-send-direct", methods=["GET"])
def session_send_direct():
try:
session = requests.Session()

# Create a PreparedRequest manually
req = requests.Request("GET", "https://jsonplaceholder.typicode.com/posts/2")
prepared = session.prepare_request(req)

# Call send() directly - bypasses request() method
response = session.send(prepared, timeout=10)

return jsonify({"status_code": response.status_code, "data": response.json(), "test": "session-send-direct"})
except Exception as e:
return jsonify({"error": str(e)}), 500


@app.route("/test/streaming-iter-lines", methods=["GET"])
def test_streaming_iter_lines():
"""Test streaming response using iter_lines."""
try:
response = requests.get(
"https://httpbin.org/stream/5", # Returns 5 JSON lines
stream=True,
timeout=10,
)
# Consume the stream using iter_lines
lines = []
for line in response.iter_lines():
if line:
lines.append(line.decode("utf-8"))

return jsonify(
{"test": "streaming-iter-lines", "status_code": response.status_code, "lines_received": len(lines)}
)
except Exception as e:
return jsonify({"error": str(e)}), 500


@app.route("/test/response-hooks", methods=["GET"])
def test_response_hooks():
"""Test response hooks that modify response."""
try:
hook_called = {"value": False}
hook_status = {"value": 0}

def response_hook(response, *args, **kwargs):
hook_called["value"] = True
hook_status["value"] = response.status_code
return response

response = requests.get("https://httpbin.org/get", hooks={"response": response_hook}, timeout=10)

return jsonify(
{
"test": "response-hooks",
"status_code": response.status_code,
"hook_called": hook_called["value"],
"hook_status": hook_status["value"],
}
)
except Exception as e:
return jsonify({"error": str(e)}), 500


if __name__ == "__main__":
sdk.mark_app_as_ready()
app.run(host="0.0.0.0", port=8000, debug=False)
6 changes: 6 additions & 0 deletions drift/instrumentation/requests/e2e-tests/src/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,10 @@ def make_request(method, endpoint, **kwargs):
# Text response handling
make_request("GET", "/api/text-response")

make_request("GET", "/test/session-send-direct")

make_request("GET", "/test/streaming-iter-lines")

make_request("GET", "/test/response-hooks")

print("\nAll requests completed successfully")
Loading