-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(segment-enrichment): Bump segment clusterer rule lifetimes #104280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| """Write transactions into redis sets""" | ||
|
|
||
| import logging | ||
| from collections.abc import Callable, Iterator, Mapping | ||
| from collections.abc import Callable, Iterator, Mapping, Sequence | ||
| from typing import Any | ||
|
|
||
| import orjson | ||
| import sentry_sdk | ||
| from django.conf import settings | ||
| from rediscluster import RedisCluster | ||
|
|
@@ -133,6 +134,12 @@ def record_segment_name(project: Project, segment_span: CompatibleSpan) -> None: | |
| project, | ||
| segment_name, | ||
| ) | ||
| if in_random_rollout("txnames.bump-lifetime-sample-rate"): | ||
| safe_execute( | ||
| _bump_rule_lifetime_for_segment, | ||
| project, | ||
| segment_span, | ||
| ) | ||
|
|
||
|
|
||
| def _should_store_transaction_name(event_data: Mapping[str, Any]) -> str | None: | ||
|
|
@@ -181,9 +188,22 @@ def _should_store_segment_name_inner( | |
|
|
||
|
|
||
| def _bump_rule_lifetime(project: Project, event_data: Mapping[str, Any]) -> None: | ||
| applied_rules = event_data.get("_meta", {}).get("transaction", {}).get("", {}).get("rem", {}) | ||
| _bump_rule_lifetime_inner(project, applied_rules) | ||
|
|
||
|
|
||
| def _bump_rule_lifetime_for_segment(project: Project, segment_span: CompatibleSpan) -> None: | ||
| meta_str: str = attribute_value( | ||
| segment_span, f"sentry._meta.fields.attributes.{ATTRIBUTE_NAMES.SENTRY_SEGMENT_NAME}" | ||
| ) | ||
| meta = orjson.loads(meta_str) | ||
| applied_rules = meta.get("meta", {}).get("", {}).get("rem", []) | ||
| _bump_rule_lifetime_inner(project, applied_rules) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing null check before parsing JSON metadataThe
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think cursor is right, does mypy actually accept |
||
|
|
||
|
|
||
| def _bump_rule_lifetime_inner(project: Project, applied_rules: Sequence): | ||
| from sentry.ingest.transaction_clusterer import rules as clusterer_rules | ||
|
|
||
| applied_rules = event_data.get("_meta", {}).get("transaction", {}).get("", {}).get("rem", {}) | ||
| if not applied_rules: | ||
| return | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug:
applied_ruleson line 191 defaults to a dictionary ({}) instead of a list ([]), causing a type mismatch with expectedSequenceiteration.Severity: MEDIUM | Confidence: High
🔍 Detailed Analysis
On line 191 of
src/sentry/ingest/transaction_clusterer/datasource/redis.py, theapplied_rulesvariable defaults to an empty dictionary ({}) when theremfield is absent from transaction event data. This creates a type mismatch because the code expectsapplied_rulesto be aSequence(specifically a list) for iteration, as evidenced by test data, type annotations, and the loop logic on lines 210-217. This inconsistency with the segment case (line 200, which defaults to[]) means that if a non-empty dictionary is ever provided, the iteration logic will fail.💡 Suggested Fix
Change the default value for
applied_ruleson line 191 from{}to[]to align with the expectedSequencetype and the segment implementation.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
4996900