Skip to content

Commit

Permalink
add logic for internal exceptions function
Browse files Browse the repository at this point in the history
  • Loading branch information
devonwarren committed Jul 4, 2024
1 parent 0a6d19a commit 3c3fd49
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions structlog_sentry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from sentry_sdk import Hub
from sentry_sdk.integrations.logging import _IGNORED_LOGGERS
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception
from sentry_sdk.utils import capture_internal_exceptions, event_from_exception, current_stacktrace
from structlog.types import EventDict, ExcInfo, WrappedLogger


Expand Down Expand Up @@ -121,10 +121,29 @@ def _get_event_and_hint(self, event_dict: EventDict) -> tuple[dict, dict]:
if has_exc_info:
client = self._get_hub().client
options: dict[str, Any] = client.options if client else {}
event, hint = event_from_exception(
exc_info,
client_options=options,
)

# if the stack_info field is set utilize the internal sentry capture function to send out the exception
# with the stack trace. Ref: https://github.com/kiwicom/structlog-sentry/issues/87
if event_dict.get("stack_info", False):
event, hint = {}, {}
with capture_internal_exceptions():
event["threads"] = {
"values": [
{
"stacktrace": current_stacktrace(
include_local_variables=options["include_local_variables"],
max_value_length=options["max_value_length"],
),
"crashed": False,
"current": True,
}
]
}
else:
event, hint = event_from_exception(
exc_info,
client_options=options,
)
else:
event, hint = {}, {}

Expand Down

0 comments on commit 3c3fd49

Please sign in to comment.