Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Dump copilot requests, too if CODEGATE_DUMP_DIR is set #1196

Merged
merged 1 commit into from
Mar 4, 2025
Merged
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
11 changes: 8 additions & 3 deletions src/codegate/providers/copilot/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
TEMPDIR = tempfile.TemporaryDirectory(prefix="codegate-", dir=basedir, delete=False)


def _dump_data(suffix, func):
def _dump_data(suffix, func, trigger: bytes | None = None):
if os.getenv("CODEGATE_DUMP_DIR"):
buf = bytearray(b"")

Expand All @@ -48,7 +48,7 @@ def inner(self, data: bytes):
func(self, data)
buf.extend(data)

if data == b"0\r\n\r\n":
if not trigger or data == trigger:
ts = datetime.datetime.now()
fname = os.path.join(TEMPDIR.name, ts.strftime(f"{suffix}-%Y%m%dT%H%M%S%f.txt"))
with open(fname, mode="wb") as fd:
Expand All @@ -64,7 +64,7 @@ def _dump_request(func):


def _dump_response(func):
return _dump_data("response", func)
return _dump_data("response", func, b"0\r\n\r\n")


# Constants
Expand Down Expand Up @@ -336,7 +336,12 @@ def _check_buffer_size(self, new_data: bytes) -> bool:
"""Check if adding new data would exceed buffer size limit"""
return len(self.buffer) + len(new_data) <= MAX_BUFFER_SIZE

@_dump_request
def _dump_create_http_request(self, data: bytes) -> bytes:
return data

async def _forward_data_through_pipeline(self, data: bytes) -> Union[HttpRequest, HttpResponse]:
self._dump_create_http_request(data)
http_request = http_request_from_bytes(data)
if not http_request:
# we couldn't parse this into an HTTP request, so we just pass through
Expand Down