Skip to content

Commit c070fb6

Browse files
authored
fix(aci): More manageable delayed_workflow logs (#96611)
We can't log the raw redis data; it's too big, too noisy, and it yields broken JSON we can't query. This replaces that with two slightly more targeted data log messages to let us definitively identify involved workflows, and their associated groups/events. We prefer sorted lists over sets because sets log unordered and are hard to search through. Also, this moves from logging DataConditionGroups (which have a large and not particularly useful string repr) to just the sorted IDs.
1 parent 9b1aebb commit c070fb6

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/sentry/workflow_engine/processors/delayed_workflow.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,16 @@ def repr_keys[T, V](d: dict[T, V]) -> dict[str, V]:
795795
return {repr(key): value for key, value in d.items()}
796796

797797

798+
def _summarize_by_first[
799+
T1, T2: int | str
800+
](it: Iterable[tuple[T1, T2]],) -> dict[T1, list[T2]]:
801+
"Logging helper to allow pairs to be summarized as a mapping from first to list of second"
802+
result = defaultdict(set)
803+
for key, value in it:
804+
result[key].add(value)
805+
return {key: sorted(values) for key, values in result.items()}
806+
807+
798808
@instrumented_task(
799809
name="sentry.workflow_engine.processors.delayed_workflow",
800810
queue="delayed_rules",
@@ -850,11 +860,23 @@ def process_delayed_workflows(
850860
extra={"no_slow_condition_groups": sorted(no_slow_condition_groups)},
851861
)
852862

863+
# Ensure we have a record of the involved workflows in our logs.
853864
logger.info(
854865
"delayed_workflow.workflows",
855866
extra={
856-
"data": redis_data,
857-
"workflows": event_data.workflow_ids,
867+
"workflows": sorted(event_data.workflow_ids),
868+
},
869+
)
870+
# Ensure we log which groups/events being processed by which workflows.
871+
# This is logged independently to avoid the risk of generating log messages that need to be
872+
# truncated (and thus no longer valid JSON that we can query).
873+
logger.info(
874+
"delayed_workflow.group_events_to_workflow_ids",
875+
extra={
876+
"group_events_to_workflow_ids": _summarize_by_first(
877+
(f"{event_key.group_id}:{instance.event_id}", event_key.workflow_id)
878+
for event_key, instance in event_data.events.items()
879+
),
858880
},
859881
)
860882

@@ -896,7 +918,12 @@ def process_delayed_workflows(
896918
)
897919
logger.info(
898920
"delayed_workflow.groups_to_fire",
899-
extra={"groups_to_dcgs": groups_to_dcgs},
921+
extra={
922+
"groups_to_dcgs": {
923+
group_id: sorted(dcg.id for dcg in dcgs)
924+
for group_id, dcgs in groups_to_dcgs.items()
925+
},
926+
},
900927
)
901928

902929
group_to_groupevent = get_group_to_groupevent(

0 commit comments

Comments
 (0)