nebius/SWE-bench-extra huggingface dataset:
Repository: kiwicom/structlog-sentry

Issue:
Support for capturing stack locals with `logging.error()`
Sentry supports capturing stack variables for non-exception messages with `logger.error("something", exc_info=True)` (added in https://github.com/getsentry/sentry-python/pull/176).

I might have some time to contribute this, but opening it here first in case I don't or you have other ideas. :)

Comments:

Patch:
diff --git a/structlog_sentry/__init__.py b/structlog_sentry/__init__.py
index f6a7168..c8055c9 100644
--- a/structlog_sentry/__init__.py
+++ b/structlog_sentry/__init__.py
@@ -40,6 +40,9 @@ class SentryProcessor:
         :param event_dict: structlog event_dict
         """
         exc_info = event_dict.pop("exc_info", sys.exc_info())
+        if exc_info is True:
+            # logger.exeception() or logger.error(exc_info=True)
+            exc_info = sys.exc_info()
         has_exc_info = exc_info and exc_info != (None, None, None)
 
         if has_exc_info:


Test patch:
diff --git a/test/test_sentry_processor.py b/test/test_sentry_processor.py
index 3307c82..22ca188 100644
--- a/test/test_sentry_processor.py
+++ b/test/test_sentry_processor.py
@@ -77,6 +77,27 @@ def test_sentry_log_failure(mocker, level):
     )
 
 
+@pytest.mark.parametrize("level", ["error", "critical"])
+def test_sentry_log_failure_exc_info_true(mocker, level):
+    """Make sure sentry_sdk.utils.exc_info_from_error doesn't raise ValueError
+    Because it can't introspect exc_info.
+    Bug triggered when logger.error(..., exc_info=True) or logger.exception(...)
+    are used.
+    """
+    m_capture_event = mocker.patch("structlog_sentry.capture_event")
+
+    event_data = {"level": level, "event": level + " message", "exc_info": True}
+    processor = SentryProcessor(level=getattr(logging, level.upper()))
+    try:
+        1 / 0
+    except ZeroDivisionError:
+        processor(None, None, event_data)
+
+    assert m_capture_event.call_count == 1
+    _, kwargs = m_capture_event.call_args
+    assert kwargs["hint"]["exc_info"][0] == ZeroDivisionError
+
+
 @pytest.mark.parametrize("level", ["debug", "info", "warning"])
 def test_sentry_log_no_extra(mocker, level):
     m_capture_event = mocker.patch("structlog_sentry.capture_event")