fix(api): attach exc_info=True to 11 logger.debug/info('...: %s', str(e)) sites — sibling of #41066 (DEBUG/INFO level) (#41077)

Co-authored-by: Harsh Kashyap <harsh23kashyap@gmail.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Harsh Kashyap
2026-08-24 09:08:08 +00:00
committed by GitHub
parent cfae2515fd
commit ff3cf5681f
7 changed files with 72 additions and 16 deletions
+2 -2
View File
@@ -280,9 +280,9 @@ class AliyunLogStore:
else:
logger.info("Using SDK mode for project %s", self.project_name)
return False
except Exception as e:
except Exception:
logger.info("Using SDK mode for project %s", self.project_name)
logger.debug("PG connection details: %s", str(e))
logger.debug("PG connection details", exc_info=True)
self._use_pg_protocol = False
return False
@@ -42,8 +42,8 @@ class AliyunLogStorePG:
result = sock.connect_ex((host, port))
sock.close()
return result == 0
except Exception as e:
logger.debug("Port connectivity check failed for %s:%d: %s", host, port, str(e))
except Exception:
logger.debug("Port connectivity check failed for %s:%d", host, port, exc_info=True)
return False
def init_connection(self) -> bool:
@@ -100,7 +100,7 @@ class AliyunLogStorePG:
)
return True
except Exception as e:
except Exception:
self._use_pg_protocol = False
if self._engine:
try:
@@ -109,7 +109,7 @@ class AliyunLogStorePG:
logger.debug("Failed to dispose engine during cleanup, ignoring")
self._engine = None
logger.debug("Using SDK mode for region: %s", str(e))
logger.debug("Using SDK mode for region", exc_info=True)
return False
@contextmanager
@@ -592,7 +592,7 @@ class LangFuseDataTrace(BaseTraceInstance):
try:
return self.langfuse_client.auth_check()
except Exception as e:
logger.debug("LangFuse API check failed: %s", str(e))
logger.debug("LangFuse API check failed", exc_info=True)
raise ValueError(f"LangFuse API check failed: {str(e)}")
def get_project_key(self):
@@ -600,5 +600,5 @@ class LangFuseDataTrace(BaseTraceInstance):
projects = self.langfuse_client.api.projects.get()
return projects.data[0].id
except Exception as e:
logger.debug("LangFuse get project key failed: %s", str(e))
logger.debug("LangFuse get project key failed", exc_info=True)
raise ValueError(f"LangFuse get project key failed: {str(e)}")
@@ -509,7 +509,7 @@ class LangSmithDataTrace(BaseTraceInstance):
self.langsmith_client.delete_project(project_name=random_project_name)
return True
except Exception as e:
logger.debug("LangSmith API check failed: %s", str(e))
logger.debug("LangSmith API check failed", exc_info=True)
raise ValueError(f"LangSmith API check failed: {str(e)}")
def get_project_url(self):
@@ -528,5 +528,5 @@ class LangSmithDataTrace(BaseTraceInstance):
)
return project_url.split("/r/")[0]
except Exception as e:
logger.debug("LangSmith get run url failed: %s", str(e))
logger.debug("LangSmith get run url failed", exc_info=True)
raise ValueError(f"LangSmith get run url failed: {str(e)}")
@@ -75,7 +75,7 @@ class WeaveDataTrace(BaseTraceInstance):
project_url = f"https://wandb.ai/{project_identifier}"
return project_url
except Exception as e:
logger.debug("Weave get run url failed: %s", str(e))
logger.debug("Weave get run url failed", exc_info=True)
raise ValueError(f"Weave get run url failed: {str(e)}")
@override
@@ -433,7 +433,7 @@ class WeaveDataTrace(BaseTraceInstance):
logger.info("Weave login successful")
return True
except Exception as e:
logger.debug("Weave API check failed: %s", str(e))
logger.debug("Weave API check failed", exc_info=True)
raise ValueError(f"Weave API check failed: {str(e)}")
def _normalize_time(self, dt: datetime | None) -> datetime:
@@ -80,8 +80,8 @@ def enable_annotation_reply_task(
)
try:
old_vector.delete()
except Exception as e:
logger.info(click.style(f"Delete annotation index error: {str(e)}", fg="red"))
except Exception:
logger.info("Delete annotation index error", exc_info=True)
annotation_setting.score_threshold = score_threshold
annotation_setting.collection_binding_id = dataset_collection_binding.id
annotation_setting.updated_user_id = user_id
@@ -116,8 +116,8 @@ def enable_annotation_reply_task(
vector = Vector(dataset, attributes=["doc_id", "annotation_id", "app_id"], session=session)
try:
vector.delete_by_metadata_field("app_id", app_id)
except Exception as e:
logger.info(click.style(f"Delete annotation index error: {str(e)}", fg="red"))
except Exception:
logger.info("Delete annotation index error", exc_info=True)
vector.create(documents)
session.commit()
redis_client.setex(enable_app_annotation_job_key, 600, "completed")
@@ -0,0 +1,56 @@
"""Test that the AliyunLogStorePG port-connectivity logger captures the traceback.
Cycle 21 (sibling of #41066 / merged in #41068): `logger.debug("...: %s", str(e))`
sites in `extensions/logstore/aliyun_logstore_pg.py` were converted to
`logger.debug("...", exc_info=True)` so the traceback is captured at the
same log level rather than being silently dropped. This test exercises one
of the modified sites — `_check_port_connectivity` — to confirm the fix
shape is correct: the captured log record has a non-empty traceback.
"""
from __future__ import annotations
from unittest.mock import patch
import pytest
from extensions.logstore.aliyun_logstore_pg import AliyunLogStorePG
def test_check_port_connectivity_captures_traceback_on_exception(caplog: pytest.LogCaptureFixture) -> None:
"""A socket failure during the port check must produce a log record with exc_info set.
Before cycle 21: the record was logged as
`Port connectivity check failed for host:port: <str(exception)>` with no
traceback. After cycle 21: the record is logged as
`Port connectivity check failed for host:port` with `exc_info=True`, so
the traceback is part of the log record (and the host/port are still
included via the format args).
"""
store = AliyunLogStorePG(
access_key_id="ak",
access_key_secret="sk",
endpoint="https://example.com",
project_name="p",
)
with (
patch("extensions.logstore.aliyun_logstore_pg.socket.socket", side_effect=OSError("boom")),
caplog.at_level("DEBUG", logger="extensions.logstore.aliyun_logstore_pg"),
):
result = store._check_port_connectivity("example.invalid", 9999)
assert result is False
matching_records = [r for r in caplog.records if r.name == "extensions.logstore.aliyun_logstore_pg"]
assert len(matching_records) == 1
record = matching_records[0]
assert record.levelname == "DEBUG"
assert record.exc_info is not None
formatted = caplog.text
assert "Port connectivity check failed for example.invalid:9999" in formatted
assert "Traceback (most recent call last)" in formatted
assert "OSError: boom" in formatted
# The exception is captured via the traceback, not interpolated into the
# format string — so the message text is the short form, not the long one.
assert "boom" not in record.getMessage()