From d99cfc582b0973690b601656ed4b85b6971780e3 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 11:18:21 +0100 Subject: [PATCH 01/15] Added check-in data category --- sentry_sdk/envelope.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index a3e4b5a940..de5bcd6991 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -262,6 +262,8 @@ def data_category(self): return "profile" elif ty == "statsd": return "statsd" + elif ty == "check_in": + return "check-in" else: return "default" From b9d76d77abf30f83307dd95076f82930ac0ea22e Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:21:27 +0100 Subject: [PATCH 02/15] Added test --- tests/test_crons.py | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/test_crons.py b/tests/test_crons.py index 9ea98df2ac..ec94e605dd 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -4,6 +4,8 @@ import sentry_sdk from sentry_sdk.crons import capture_checkin +from sentry_sdk import Hub, configure_scope, set_level + try: from unittest import mock # python 3.3 and above except ImportError: @@ -220,3 +222,55 @@ def test_capture_checkin_sdk_not_initialized(): duration=None, ) assert check_in_id == "112233" + + +def test_scope_data_in_checkin(sentry_init, capture_envelopes): + sentry_init() + envelopes = capture_envelopes() + + valid_keys = [ + # Mandatory event keys + "type", + "event_id", + "timestamp", + "platform", + # Optional event keys + "release", + "environment", + # Mandatory check-in specific keys + "check_in_id", + "monitor_slug", + "status", + # Optional check-in specific keys + "duration", + "monitor_config", + "contexts", + ] + + hub = Hub.current + with configure_scope() as scope: + # Add some data to the scope + set_level("warning") + hub.add_breadcrumb(message="test breadcrumb") + scope.set_tag("test_tag", "test_value") + scope.set_extra("test_extra", "test_value") + scope.set_context("test_context", {"test_key": "test_value"}) + + capture_checkin( + monitor_slug="abc123", + check_in_id="112233", + status="ok", + duration=123, + ) + + (envelope,) = envelopes + check_in_event = envelope.items[0].payload.json + + invalid_keys = [] + for key in check_in_event.keys(): + if key not in valid_keys: + invalid_keys.append(key) + + assert ( + len(invalid_keys) == 0 + ), f"Unexpected keys found in checkin: {invalid_keys}" From 641f9376c6b67f800552e3927b90c1d09040a47c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:22:03 +0100 Subject: [PATCH 03/15] Made apply_to_event more readable --- sentry_sdk/scope.py | 99 ++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index d2768fb374..ffe3d76156 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -560,58 +560,48 @@ def func(event, exc_info): self._error_processors.append(func) - @_disable_capture - def apply_to_event( - self, - event, # type: Event - hint, # type: Hint - options=None, # type: Optional[Dict[str, Any]] - ): - # type: (...) -> Optional[Event] - """Applies the information contained on the scope to the given event.""" - - def _drop(cause, ty): - # type: (Any, str) -> Optional[Any] - logger.info("%s (%s) dropped event", ty, cause) - return None - - is_transaction = event.get("type") == "transaction" - - # put all attachments into the hint. This lets callbacks play around - # with attachments. We also later pull this out of the hint when we - # create the envelope. - attachments_to_send = hint.get("attachments") or [] - for attachment in self._attachments: - if not is_transaction or attachment.add_to_transactions: - attachments_to_send.append(attachment) - hint["attachments"] = attachments_to_send - + def apply_level_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._level is not None: event["level"] = self._level - if not is_transaction: - event.setdefault("breadcrumbs", {}).setdefault("values", []).extend( - self._breadcrumbs - ) + def apply_breadcrumbs_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None + event.setdefault("breadcrumbs", {}).setdefault("values", []).extend( + self._breadcrumbs + ) + def apply_user_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("user") is None and self._user is not None: event["user"] = self._user + def apply_transaction_name_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("transaction") is None and self._transaction is not None: event["transaction"] = self._transaction + def apply_transaction_info_to_event(self, event, hint, options): if event.get("transaction_info") is None and self._transaction_info is not None: event["transaction_info"] = self._transaction_info + def apply_fingerprint_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("fingerprint") is None and self._fingerprint is not None: event["fingerprint"] = self._fingerprint + def apply_extra_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._extras: event.setdefault("extra", {}).update(self._extras) + def apply_tags_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._tags: event.setdefault("tags", {}).update(self._tags) + def apply_contexts_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._contexts: event.setdefault("contexts", {}).update(self._contexts) @@ -633,22 +623,67 @@ def _drop(cause, ty): "replay_id": replay_id, } + def run_error_processors(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None exc_info = hint.get("exc_info") if exc_info is not None: for error_processor in self._error_processors: new_event = error_processor(event, exc_info) if new_event is None: - return _drop(error_processor, "error processor") + logger.info("error processor (%s) dropped event", error_processor) + return None + event = new_event + def run_event_processors(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None for event_processor in chain(global_event_processors, self._event_processors): new_event = event with capture_internal_exceptions(): new_event = event_processor(event, hint) if new_event is None: - return _drop(event_processor, "event processor") + logger.info("event processor (%s) dropped event", event_processor) + return None event = new_event + @_disable_capture + def apply_to_event( + self, + event, # type: Event + hint, # type: Hint + options=None, # type: Optional[Dict[str, Any]] + ): + # type: (...) -> Optional[Event] + """Applies the information contained on the scope to the given event.""" + ty = event.get("type") + is_transaction = ty == "transaction" + + # put all attachments into the hint. This lets callbacks play around + # with attachments. We also later pull this out of the hint when we + # create the envelope. + attachments_to_send = hint.get("attachments") or [] + for attachment in self._attachments: + if not is_transaction or attachment.add_to_transactions: + attachments_to_send.append(attachment) + hint["attachments"] = attachments_to_send + + self.apply_level_to_event(event, hint, options) + + if not is_transaction: + self.apply_breadcrumbs_to_event(event, hint, options) + + self.apply_user_to_event(event, hint, options) + self.apply_transaction_name_to_event(event, hint, options) + self.apply_transaction_info_to_event(event, hint, options) + self.apply_fingerprint_to_event(event, hint, options) + self.apply_extra_to_event(event, hint, options) + self.apply_tags_to_event(event, hint, options) + self.apply_contexts_to_event(event, hint, options) + + self.run_error_processors(event, hint, options) + + self.run_event_processors(event, hint, options) + return event def update_from_scope(self, scope): From 25d71bcbf5247eb25ebcc429fc3700f239b4fcf9 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:34:20 +0100 Subject: [PATCH 04/15] Updated test --- tests/test_crons.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_crons.py b/tests/test_crons.py index ec94e605dd..6707a86c1d 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -245,6 +245,13 @@ def test_scope_data_in_checkin(sentry_init, capture_envelopes): "duration", "monitor_config", "contexts", + # TODO: These fields need to be checked if valid for checkin: + "level", + "tags", + "extra", + "modules", + "server_name", + "sdk", ] hub = Hub.current From d79fb10baa87ec68a470974816c9f4fe8f1ee28a Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:34:47 +0100 Subject: [PATCH 05/15] Do not add scope that to checkin that does not belong there --- sentry_sdk/scope.py | 50 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index ffe3d76156..170d387ccf 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -560,59 +560,61 @@ def func(event, exc_info): self._error_processors.append(func) - def apply_level_to_event(self, event, hint, options): + def _apply_level_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._level is not None: event["level"] = self._level - def apply_breadcrumbs_to_event(self, event, hint, options): + def _apply_breadcrumbs_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None event.setdefault("breadcrumbs", {}).setdefault("values", []).extend( self._breadcrumbs ) - def apply_user_to_event(self, event, hint, options): + def _apply_user_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("user") is None and self._user is not None: event["user"] = self._user - def apply_transaction_name_to_event(self, event, hint, options): + def _apply_transaction_name_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("transaction") is None and self._transaction is not None: event["transaction"] = self._transaction - def apply_transaction_info_to_event(self, event, hint, options): + def _apply_transaction_info_to_event(self, event, hint, options): if event.get("transaction_info") is None and self._transaction_info is not None: event["transaction_info"] = self._transaction_info - def apply_fingerprint_to_event(self, event, hint, options): + def _apply_fingerprint_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("fingerprint") is None and self._fingerprint is not None: event["fingerprint"] = self._fingerprint - def apply_extra_to_event(self, event, hint, options): + def _apply_extra_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._extras: event.setdefault("extra", {}).update(self._extras) - def apply_tags_to_event(self, event, hint, options): + def _apply_tags_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._tags: event.setdefault("tags", {}).update(self._tags) - def apply_contexts_to_event(self, event, hint, options): + def _apply_contexts_to_event(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if self._contexts: event.setdefault("contexts", {}).update(self._contexts) contexts = event.setdefault("contexts", {}) + # Add "trace" context if contexts.get("trace") is None: if has_tracing_enabled(options) and self._span is not None: contexts["trace"] = self._span.get_trace_context() else: contexts["trace"] = self.get_trace_context() + # Add "reply_id" context try: replay_id = contexts["trace"]["dynamic_sampling_context"]["replay_id"] except (KeyError, TypeError): @@ -623,7 +625,7 @@ def apply_contexts_to_event(self, event, hint, options): "replay_id": replay_id, } - def run_error_processors(self, event, hint, options): + def _run_error_processors(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None exc_info = hint.get("exc_info") if exc_info is not None: @@ -635,7 +637,7 @@ def run_error_processors(self, event, hint, options): event = new_event - def run_event_processors(self, event, hint, options): + def _run_event_processors(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None for event_processor in chain(global_event_processors, self._event_processors): new_event = event @@ -657,6 +659,7 @@ def apply_to_event( """Applies the information contained on the scope to the given event.""" ty = event.get("type") is_transaction = ty == "transaction" + is_check_in = ty == "check_in" # put all attachments into the hint. This lets callbacks play around # with attachments. We also later pull this out of the hint when we @@ -667,22 +670,23 @@ def apply_to_event( attachments_to_send.append(attachment) hint["attachments"] = attachments_to_send - self.apply_level_to_event(event, hint, options) + self._apply_level_to_event(event, hint, options) + self._apply_fingerprint_to_event(event, hint, options) + self._apply_user_to_event(event, hint, options) + self._apply_tags_to_event(event, hint, options) + self._apply_contexts_to_event(event, hint, options) + self._apply_transaction_name_to_event(event, hint, options) - if not is_transaction: - self.apply_breadcrumbs_to_event(event, hint, options) + if not is_check_in: + self._apply_transaction_info_to_event(event, hint, options) + self._apply_extra_to_event(event, hint, options) - self.apply_user_to_event(event, hint, options) - self.apply_transaction_name_to_event(event, hint, options) - self.apply_transaction_info_to_event(event, hint, options) - self.apply_fingerprint_to_event(event, hint, options) - self.apply_extra_to_event(event, hint, options) - self.apply_tags_to_event(event, hint, options) - self.apply_contexts_to_event(event, hint, options) + if not is_transaction and not is_check_in: + self._apply_breadcrumbs_to_event(event, hint, options) - self.run_error_processors(event, hint, options) + self._run_error_processors(event, hint, options) - self.run_event_processors(event, hint, options) + self._run_event_processors(event, hint, options) return event From 14a20e591abb05e12096f57c42681e15ad8094c3 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:46:04 +0100 Subject: [PATCH 06/15] Fixed data category --- sentry_sdk/_types.py | 1 + sentry_sdk/envelope.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/_types.py b/sentry_sdk/_types.py index bfe4b4ab2b..c421a6756b 100644 --- a/sentry_sdk/_types.py +++ b/sentry_sdk/_types.py @@ -54,6 +54,7 @@ "internal", "profile", "statsd", + "check_in", ] SessionStatus = Literal["ok", "exited", "crashed", "abnormal"] EndpointType = Literal["store", "envelope"] diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index de5bcd6991..de4f99774e 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -263,7 +263,7 @@ def data_category(self): elif ty == "statsd": return "statsd" elif ty == "check_in": - return "check-in" + return "check_in" else: return "default" From 918d31f9e9d7efe9e07867e612f5309ef4474622 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:48:46 +0100 Subject: [PATCH 07/15] Made linter happy --- sentry_sdk/scope.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 170d387ccf..be05cfd9cc 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -582,6 +582,7 @@ def _apply_transaction_name_to_event(self, event, hint, options): event["transaction"] = self._transaction def _apply_transaction_info_to_event(self, event, hint, options): + # type: (Event, Hint, Optional[Dict[str, Any]]) -> None if event.get("transaction_info") is None and self._transaction_info is not None: event["transaction_info"] = self._transaction_info @@ -640,7 +641,7 @@ def _run_error_processors(self, event, hint, options): def _run_event_processors(self, event, hint, options): # type: (Event, Hint, Optional[Dict[str, Any]]) -> None for event_processor in chain(global_event_processors, self._event_processors): - new_event = event + new_event = event # type: Optional[Event] with capture_internal_exceptions(): new_event = event_processor(event, hint) if new_event is None: From 6ef7b095176e8d24fbdb2eff7fe9063f4018197c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 13:56:43 +0100 Subject: [PATCH 08/15] Fix --- sentry_sdk/scope.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index be05cfd9cc..9d27a27aae 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -685,9 +685,13 @@ def apply_to_event( if not is_transaction and not is_check_in: self._apply_breadcrumbs_to_event(event, hint, options) - self._run_error_processors(event, hint, options) + event = self._run_error_processors(event, hint, options) + if event is None: + return None - self._run_event_processors(event, hint, options) + event = self._run_event_processors(event, hint, options) + if event is None: + return None return event From 22f0c25cc0c7e62154629fe88b6d01138b8bf394 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 14:30:12 +0100 Subject: [PATCH 09/15] moved proccessors back out, because they broke things --- sentry_sdk/scope.py | 48 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 9d27a27aae..b1f5a07df2 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -626,29 +626,6 @@ def _apply_contexts_to_event(self, event, hint, options): "replay_id": replay_id, } - def _run_error_processors(self, event, hint, options): - # type: (Event, Hint, Optional[Dict[str, Any]]) -> None - exc_info = hint.get("exc_info") - if exc_info is not None: - for error_processor in self._error_processors: - new_event = error_processor(event, exc_info) - if new_event is None: - logger.info("error processor (%s) dropped event", error_processor) - return None - - event = new_event - - def _run_event_processors(self, event, hint, options): - # type: (Event, Hint, Optional[Dict[str, Any]]) -> None - for event_processor in chain(global_event_processors, self._event_processors): - new_event = event # type: Optional[Event] - with capture_internal_exceptions(): - new_event = event_processor(event, hint) - if new_event is None: - logger.info("event processor (%s) dropped event", event_processor) - return None - event = new_event - @_disable_capture def apply_to_event( self, @@ -685,13 +662,26 @@ def apply_to_event( if not is_transaction and not is_check_in: self._apply_breadcrumbs_to_event(event, hint, options) - event = self._run_error_processors(event, hint, options) - if event is None: - return None + # run error processors + exc_info = hint.get("exc_info") + if exc_info is not None: + for error_processor in self._error_processors: + new_event = error_processor(event, exc_info) + if new_event is None: + logger.info("error processor (%s) dropped event", error_processor) + return None - event = self._run_event_processors(event, hint, options) - if event is None: - return None + event = new_event + + # run event processors + for event_processor in chain(global_event_processors, self._event_processors): + new_event = event # type: Optional[Event] + with capture_internal_exceptions(): + new_event = event_processor(event, hint) + if new_event is None: + logger.info("event processor (%s) dropped event", event_processor) + return None + event = new_event return event From 562f2052f7776d0dc7eece09cc57bb87c0520a9c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 14:32:38 +0100 Subject: [PATCH 10/15] Cleanup --- sentry_sdk/scope.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index b1f5a07df2..94673bdbfc 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -662,25 +662,28 @@ def apply_to_event( if not is_transaction and not is_check_in: self._apply_breadcrumbs_to_event(event, hint, options) + def _drop(cause, ty): + # type: (Any, str) -> Optional[Any] + logger.info("%s (%s) dropped event", ty, cause) + return None + # run error processors exc_info = hint.get("exc_info") if exc_info is not None: for error_processor in self._error_processors: new_event = error_processor(event, exc_info) if new_event is None: - logger.info("error processor (%s) dropped event", error_processor) - return None + return _drop(error_processor, "error processor") event = new_event # run event processors for event_processor in chain(global_event_processors, self._event_processors): - new_event = event # type: Optional[Event] + new_event = event with capture_internal_exceptions(): new_event = event_processor(event, hint) if new_event is None: - logger.info("event processor (%s) dropped event", event_processor) - return None + return _drop(event_processor, "event processor") event = new_event return event From 05a2e95862be47caea1912c4dbf604ed88637fdc Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 14:38:35 +0100 Subject: [PATCH 11/15] Fixed old python syntax problem --- tests/test_crons.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_crons.py b/tests/test_crons.py index 6707a86c1d..2c202f763e 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -278,6 +278,6 @@ def test_scope_data_in_checkin(sentry_init, capture_envelopes): if key not in valid_keys: invalid_keys.append(key) - assert ( - len(invalid_keys) == 0 - ), f"Unexpected keys found in checkin: {invalid_keys}" + assert len(invalid_keys) == 0, "Unexpected keys found in checkin: {}".format( + invalid_keys + ) From b32ba8ed5bcba07a2f33de2d2c84cd8cd8a8ca6e Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 14:46:27 +0100 Subject: [PATCH 12/15] Allowing also _meta in event --- tests/test_crons.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_crons.py b/tests/test_crons.py index 2c202f763e..07d35aa0fe 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -246,6 +246,7 @@ def test_scope_data_in_checkin(sentry_init, capture_envelopes): "monitor_config", "contexts", # TODO: These fields need to be checked if valid for checkin: + "_meta", "level", "tags", "extra", From 5b457e7ad761891f8c440c3c5759b01afaba1e80 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 15:19:45 +0100 Subject: [PATCH 13/15] Removed more data --- sentry_sdk/scope.py | 13 ++++++------- tests/test_crons.py | 5 ++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 94673bdbfc..60f714c14d 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -648,15 +648,14 @@ def apply_to_event( attachments_to_send.append(attachment) hint["attachments"] = attachments_to_send - self._apply_level_to_event(event, hint, options) - self._apply_fingerprint_to_event(event, hint, options) - self._apply_user_to_event(event, hint, options) - self._apply_tags_to_event(event, hint, options) - self._apply_contexts_to_event(event, hint, options) - self._apply_transaction_name_to_event(event, hint, options) - if not is_check_in: + self._apply_level_to_event(event, hint, options) + self._apply_fingerprint_to_event(event, hint, options) + self._apply_user_to_event(event, hint, options) + self._apply_transaction_name_to_event(event, hint, options) self._apply_transaction_info_to_event(event, hint, options) + self._apply_tags_to_event(event, hint, options) + self._apply_contexts_to_event(event, hint, options) self._apply_extra_to_event(event, hint, options) if not is_transaction and not is_check_in: diff --git a/tests/test_crons.py b/tests/test_crons.py index 07d35aa0fe..39d02a5d47 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -244,12 +244,11 @@ def test_scope_data_in_checkin(sentry_init, capture_envelopes): # Optional check-in specific keys "duration", "monitor_config", - "contexts", + "contexts", # an event processor adds this # TODO: These fields need to be checked if valid for checkin: "_meta", - "level", "tags", - "extra", + "extra", # an event processor adds this "modules", "server_name", "sdk", From 6ac2b3ceee54aed7843f6df10139e4fee0632d9b Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 10 Nov 2023 15:45:15 +0100 Subject: [PATCH 14/15] Removed unused ignore statements --- sentry_sdk/integrations/rq.py | 2 +- sentry_sdk/transport.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/rq.py b/sentry_sdk/integrations/rq.py index 7f1a79abed..b5eeb0be85 100644 --- a/sentry_sdk/integrations/rq.py +++ b/sentry_sdk/integrations/rq.py @@ -99,7 +99,7 @@ def sentry_patched_handle_exception(self, job, *exc_info, **kwargs): # Note, the order of the `or` here is important, # because calling `job.is_failed` will change `_status`. if job._status == JobStatus.FAILED or job.is_failed: - _capture_exception(exc_info) # type: ignore + _capture_exception(exc_info) return old_handle_exception(self, job, *exc_info, **kwargs) diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index 4b12287ec9..8eb00bed12 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -586,7 +586,7 @@ def make_transport(options): elif isinstance(ref_transport, type) and issubclass(ref_transport, Transport): transport_cls = ref_transport elif callable(ref_transport): - return _FunctionTransport(ref_transport) # type: ignore + return _FunctionTransport(ref_transport) # if a transport class is given only instantiate it if the dsn is not # empty or None From 9da5bfff13aecbcdec4596e6b5d35de2d2bae52e Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 13 Nov 2023 09:26:08 +0100 Subject: [PATCH 15/15] Added contexts also for checking (because it contains the trace context) --- sentry_sdk/scope.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 60f714c14d..b9071cc694 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -648,6 +648,8 @@ def apply_to_event( attachments_to_send.append(attachment) hint["attachments"] = attachments_to_send + self._apply_contexts_to_event(event, hint, options) + if not is_check_in: self._apply_level_to_event(event, hint, options) self._apply_fingerprint_to_event(event, hint, options) @@ -655,7 +657,6 @@ def apply_to_event( self._apply_transaction_name_to_event(event, hint, options) self._apply_transaction_info_to_event(event, hint, options) self._apply_tags_to_event(event, hint, options) - self._apply_contexts_to_event(event, hint, options) self._apply_extra_to_event(event, hint, options) if not is_transaction and not is_check_in: