Skip to content
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

feat(txnames): Include transactions without source in clustering #51437

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/sentry/ingest/transaction_clusterer/datasource/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def clear_samples(namespace: ClustererNamespace, project: Project) -> None:


def record_transaction_name(project: Project, event_data: Mapping[str, Any], **kwargs: Any) -> None:
transaction_name = event_data.get("transaction")

if transaction_name and _should_store_transaction_name(event_data):
if transaction_name := _should_store_transaction_name(event_data):
safe_execute(
_record_sample,
ClustererNamespace.TRANSACTIONS,
Expand All @@ -116,28 +114,41 @@ def record_transaction_name(project: Project, event_data: Mapping[str, Any], **k
safe_execute(_bump_rule_lifetime, project, event_data, _with_transaction=False)


def _should_store_transaction_name(event_data: Mapping[str, Any]) -> bool:
def _should_store_transaction_name(event_data: Mapping[str, Any]) -> Optional[str]:
"""Returns whether the given event must be stored as input for the
transaction clusterer."""
tags = event_data.get("tags")
transaction_name = event_data.get("transaction")
if not transaction_name:
return None

tags = event_data.get("tags") or {}
transaction_info = event_data.get("transaction_info") or {}
source = transaction_info.get("source")

# For now, we also feed back transactions into the clustering algorithm
# We also feed back transactions into the clustering algorithm
# that have already been sanitized, so we have a chance to discover
# more high cardinality segments after partial sanitation.
# For example, we may have sanitized `/orgs/*/projects/foo`,
# But the clusterer has yet to discover `/orgs/*/projects/*`.
#
# Disadvantage: the load on redis does not decrease over time.
#
if source not in (TRANSACTION_SOURCE_URL, TRANSACTION_SOURCE_SANITIZED):
return False
source_matches = source in (TRANSACTION_SOURCE_URL, TRANSACTION_SOURCE_SANITIZED) or (
# Relay leaves source None if it expects it to be high cardinality, (otherwise it sets it to "unknown")
# (see https://github.com/getsentry/relay/blob/2d07bef86415cc0ae8af01d16baecde10cdb23a6/relay-general/src/store/transactions/processor.rs#L369-L373).
#
# Our data shows that a majority of these `None` source transactions contain slashes, so treat them as URL transactions:
source is None
and "/" in transaction_name
)

if not source_matches:
return None

if tags and HTTP_404_TAG in tags:
return False
return None

return True
return transaction_name


def _bump_rule_lifetime(project: Project, event_data: Mapping[str, Any]) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/sentry/ingest/test_transaction_clusterer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def test_distribution():
("route", "/", [["transaction", "/"]], 0),
("url", None, [], 0),
("url", "/a/b/c", [["http.status_code", "404"]], 0),
(None, "/a/b/c", [], 1),
(None, "foo", [], 0),
],
)
def test_record_transactions(mocked_record, default_organization, source, txname, tags, expected):
Expand Down