Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions sentry_sdk/integrations/dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ def processor(event: "Event", hint: "Optional[Hint]") -> "Optional[Event]":

exc = exc_info[1]
if last_seen is exc:
exceptions = (event.get("exception") or {}).get("values") or ()
for error in exceptions:
mechanism = (
error.get("mechanism") if isinstance(error, dict) else None
)
if (
isinstance(mechanism, dict)
and mechanism.get("handled") is False
):
session = (
sentry_sdk.get_isolation_scope()._session
or sentry_sdk.get_current_scope()._session
)
if session is not None:
session.update(status="crashed")
break

logger.info("DedupeIntegration dropped duplicated error event %s", exc)
return None

Expand Down
31 changes: 31 additions & 0 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,37 @@ def index():
assert session["attrs"]["release"] == "demo-release"


def test_flask_session_tracking_log_then_reraise(sentry_init, capture_envelopes, app):
sentry_init(
integrations=[flask_sentry.FlaskIntegration()],
release="demo-release",
)

@app.route("/")
def index():
try:
raise ValueError("db down")
except ValueError:
logging.exception("failed to load")
raise

envelopes = capture_envelopes()

with app.test_client() as client:
with pytest.raises(ValueError):
client.get("/")

sentry_sdk.flush()

session_envelopes = [
e for e in envelopes if any(item.type == "sessions" for item in e.items)
]
assert len(session_envelopes) == 1
aggregates = session_envelopes[0].items[0].payload.json["aggregates"]
assert sum(agg.get("crashed", 0) for agg in aggregates) == 1
assert sum(agg.get("errored", 0) for agg in aggregates) == 0


@pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"])
def test_flask_empty_json_request(sentry_init, capture_events, app, data):
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
Expand Down