Skip to content

Commit

Permalink
chore(similarity): Add temp metric for stacktraces with limited data (#…
Browse files Browse the repository at this point in the history
…81700)

Add temporary metric for stacktraces with no header, filename, and only
have one frame
  • Loading branch information
jangjodi authored Dec 6, 2024
1 parent cf6da02 commit 011b24a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/sentry/seer/similarity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def get_stacktrace_string(data: dict[str, Any], platform: str | None = None) ->
frame_count = 0
html_frame_count = 0 # for a temporary metric
is_frames_truncated = False
has_no_filename = False # for a temporary metric
stacktrace_str = ""
found_non_snipped_context_line = False

Expand All @@ -209,6 +210,7 @@ def _process_frames(frames: list[dict[str, Any]]) -> list[str]:
nonlocal frame_count
nonlocal html_frame_count
nonlocal is_frames_truncated
nonlocal has_no_filename
nonlocal found_non_snipped_context_line
frame_strings = []

Expand All @@ -229,6 +231,9 @@ def _process_frames(frames: list[dict[str, Any]]) -> list[str]:
if not _is_snipped_context_line(frame_dict["context-line"]):
found_non_snipped_context_line = True

if not frame_dict["filename"]:
has_no_filename = True

# Not an exhaustive list of tests we could run to detect HTML, but this is only
# meant to be a temporary, quick-and-dirty metric
# TODO: Don't let this, and the metric below, hang around forever. It's only to
Expand Down Expand Up @@ -311,6 +316,16 @@ def _process_frames(frames: list[dict[str, Any]]) -> list[str]:
},
)

# Metric for errors with no header, only one frame and no filename
# TODO: Determine how often this occurs and if we should send to seer, then remove metric
if has_no_filename and len(result_parts) == 1:
header, frames = result_parts[0][0], result_parts[0][1]
if header == "" and len(frames) == 1:
metrics.incr(
"seer.grouping.no_header_one_frame_no_filename",
sample_rate=options.get("seer.similarity.metrics_sample_rate"),
)

return stacktrace_str.strip()


Expand Down
17 changes: 16 additions & 1 deletion tests/sentry/seer/similarity/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import copy
from collections.abc import Callable
from typing import Any, Literal, cast
from unittest.mock import patch
from uuid import uuid1

import pytest

from sentry import options
from sentry.eventstore.models import Event
from sentry.seer.similarity.utils import (
BASE64_ENCODED_PREFIXES,
Expand Down Expand Up @@ -299,7 +301,7 @@ class GetStacktraceStringTest(TestCase):
}
}

MOBILE_THREAD_DATA = {
MOBILE_THREAD_DATA: dict[str, Any] = {
"app": {
"type": "component",
"description": "in-app thread stack-trace",
Expand Down Expand Up @@ -865,6 +867,19 @@ def test_no_filename_or_module(self):
== 'ZeroDivisionError: division by zero\n File "None", function divide_by_zero\n divide = 1/0'
)

@patch("sentry.seer.similarity.utils.metrics")
def test_no_header_one_frame_no_filename(self, mock_metrics):
exception = copy.deepcopy(self.MOBILE_THREAD_DATA)
# Remove filename
exception["app"]["component"]["values"][0]["values"][0]["values"][0]["values"][1][
"values"
] = []
get_stacktrace_string(exception)
sample_rate = options.get("seer.similarity.metrics_sample_rate")
mock_metrics.incr.assert_called_with(
"seer.grouping.no_header_one_frame_no_filename", sample_rate=sample_rate
)


class EventContentIsSeerEligibleTest(TestCase):
def get_eligible_event_data(self) -> dict[str, Any]:
Expand Down

0 comments on commit 011b24a

Please sign in to comment.