Skip to content

Commit

Permalink
add all values at once
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Mar 13, 2024
1 parent 60045e6 commit 11b75fe
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/sentry/eventstore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,36 +549,31 @@ def as_dict(self) -> Mapping[str, Any]:
@memoize
def search_message(self) -> str:
"""
The internal search_message attribute is only used for search purposes.
The internal `search_message` attribute is only used for search purposes.
It adds a bunch of data from the metadata and the culprit.
"""
data = self.data
culprit = self.culprit
metadata = self.get_event_metadata() or eventtypes.get(
self.get_event_type()
)().get_metadata(self.data)
search_message_values = set()

event_metadata = self.get_event_metadata()
search_message_values.add(self.culprit or "")

if event_metadata is None:
event_metadata = eventtypes.get(self.get_event_type())().get_metadata(self.data)

message = ""
for key, value in metadata.items():
if key in SEARCH_MESSAGE_SKIPPED_KEYS or isinstance(value, (bool, int, float)):
continue
search_message_values.add(value)

if data.get("logentry"):
message += data["logentry"].get("formatted") or data["logentry"].get("message") or ""

if event_metadata:
for key, value in event_metadata.items():
if key in SEARCH_MESSAGE_SKIPPED_KEYS or isinstance(value, (bool, int, float)):
continue
log_message = data["logentry"].get("formatted") or data["logentry"].get("message") or ""
search_message_values.add(log_message)

value_u = force_str(value, errors="replace")
if value_u not in message:
message = f"{message} {value_u}"

if culprit and culprit not in message:
culprit_u = force_str(culprit, errors="replace")
message = f"{message} {culprit_u}"
concatenated = " ".join(
[force_str(value, errors="replace") for value in search_message_values]
)

return cast(str, trim(message.strip(), settings.SENTRY_MAX_MESSAGE_LENGTH))
return cast(str, trim(concatenated.strip(), settings.SENTRY_MAX_MESSAGE_LENGTH))

def _get_column_name(self, column: Columns) -> str:
# Events are currently populated from the Events dataset
Expand Down

0 comments on commit 11b75fe

Please sign in to comment.