Skip to content

Commit

Permalink
feat(insights): add trigger for has_insight_xx project flags (#73028)
Browse files Browse the repository at this point in the history
Adds logic to trigger the has_insight_xx receiver flags when a span that
matches a specific insight module is found.

Continuation of #72904
  • Loading branch information
KevinL10 committed Jun 19, 2024
1 parent 9796ade commit 27b3147
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/sentry/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,31 @@ class InsightModules(Enum):
LLM_MONITORING = "llm_monitoring"


# each span filter takes in a span object and returns whether
# the span belongs in the corresponding insight module
INSIGHT_MODULE_SPAN_FILTERS = {
InsightModules.HTTP: lambda span: span.get("op") == "http.client"
and span.get("module") == "http",
InsightModules.DB: lambda span: span.get("module") == "db" and "description" in span.keys(),
InsightModules.ASSETS: lambda span: span.get("op")
in ["resource.script", "resource.css", "resource.font", "resource.img"],
InsightModules.APP_START: lambda span: span.get("op").startswith("app.start."),
InsightModules.SCREEN_LOAD: lambda span: span.get("sentry_tags", {}).get("transaction.op")
== "ui.load",
InsightModules.VITAL: lambda span: span.get("op")
in [
"ui.interaction.click",
"ui.interaction.hover",
"ui.interaction.drag",
"ui.interaction.press",
],
InsightModules.CACHE: lambda span: span.get("op")
in ["cache.get_item", "cache.get", "cache.put"],
InsightModules.QUEUE: lambda span: span.get("op") in ["queue.process", "queue.publish"],
InsightModules.LLM_MONITORING: lambda span: span.get("op").startswith("ai.pipeline"),
}


StatsPeriod = namedtuple("StatsPeriod", ("segments", "interval"))

LEGACY_RATE_LIMIT_OPTIONS = frozenset(("sentry:project-rate-limit", "sentry:account-rate-limit"))
Expand Down
31 changes: 31 additions & 0 deletions src/sentry/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
from sentry.attachments import CachedAttachment, MissingAttachmentChunks, attachment_cache
from sentry.constants import (
DEFAULT_STORE_NORMALIZER_ARGS,
INSIGHT_MODULE_SPAN_FILTERS,
LOG_LEVELS_MAP,
MAX_TAG_VALUE_LENGTH,
PLACEHOLDER_EVENT_TITLES,
DataCategory,
InsightModules,
)
from sentry.culprit import generate_culprit
from sentry.dynamic_sampling import LatestReleaseBias, LatestReleaseParams
Expand Down Expand Up @@ -110,6 +112,7 @@
from sentry.signals import (
first_event_received,
first_event_with_minified_stack_trace_received,
first_insight_span_received,
first_transaction_received,
issue_unresolved,
)
Expand Down Expand Up @@ -223,6 +226,27 @@ def plugin_is_regression(group: Group, event: BaseEvent) -> bool:
return True


def get_project_insight_flag(project: Project, module: InsightModules):
if module == InsightModules.HTTP:
return project.flags.has_insights_http
elif module == InsightModules.DB:
return project.flags.has_insights_db
elif module == InsightModules.ASSETS:
return project.flags.has_insights_assets
elif module == InsightModules.APP_START:
return project.flags.has_insights_app_start
elif module == InsightModules.SCREEN_LOAD:
return project.flags.has_insights_screen_load
elif module == InsightModules.VITAL:
return project.flags.has_insights_vitals
elif module == InsightModules.CACHE:
return project.flags.has_insights_caches
elif module == InsightModules.QUEUE:
return project.flags.has_insights_queues
elif module == InsightModules.LLM_MONITORING:
return project.flags.has_insights_llm_monitoring


def has_pending_commit_resolution(group: Group) -> bool:
"""
Checks that the most recent commit that fixes a group has had a chance to release
Expand Down Expand Up @@ -475,6 +499,13 @@ def save(
project=project, event=jobs[0]["event"], sender=Project
)

for module, is_module_span in INSIGHT_MODULE_SPAN_FILTERS.items():
if not get_project_insight_flag(project, module) and any(
[is_module_span(span) for span in job["data"]["spans"]]
):
first_insight_span_received.send_robust(
project=project, module=module, sender=Project
)
return jobs[0]["event"]
elif event_type == "generic":
job["data"]["project"] = project.id
Expand Down

0 comments on commit 27b3147

Please sign in to comment.