Skip to content

Commit

Permalink
Add try except around crash dump writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Huang authored and Nick Huang committed Oct 9, 2024
1 parent b6fd11b commit 5c6888b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions python/langsmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,19 @@ def request_with_retries(
"LANGSMITH_DEBUG_CRASH_DUMP"
)
if debug_crash_dump_file is not None and e.request is not None:
request_data: requests.Request | requests.PreparedRequest = (
copy.deepcopy(e.request)
)
if "x-api-key" in request_data.headers:
request_data.headers["x-api-key"] = masked_api_key
with gzip.open(debug_crash_dump_file, "ab") as f:
json_data = json.dumps(request_data).encode("utf-8")
f.write(json_data + b"\n")
try:
request_data: requests.Request | requests.PreparedRequest = (
copy.deepcopy(e.request)
)
if "x-api-key" in request_data.headers:
request_data.headers["x-api-key"] = masked_api_key
with gzip.open(debug_crash_dump_file, "ab") as f:
json_data = json.dumps(request_data).encode("utf-8")
f.write(json_data + b"\n")
recommendation += f" More info can be found in: {debug_crash_dump_file}."
except Exception as write_error:
recommendation += f" Encountered this error while trying to write to {debug_crash_dump_file}: {repr(write_error)}"
continue

raise ls_utils.LangSmithConnectionError(
f"Connection error caused failure to {method} {pathname}"
Expand Down

0 comments on commit 5c6888b

Please sign in to comment.