Skip to content

Commit cafa7f4

Browse files
authored
chore(unmerge): Add more context when logging (#101190)
This would have helped us when investigating some unmerge customer issue.
1 parent 682d3c0 commit cafa7f4

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/sentry/tasks/unmerge.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ def migrate_events(
168168
opt_destination_id: int | None,
169169
opt_eventstream_state: Mapping[str, Any] | None,
170170
) -> tuple[int, Mapping[str, Any]]:
171+
extra = {"source_id": args.source_id, "project_id": project.id}
171172
logger.info(
172173
"migrate_events.start",
173174
extra={
174-
"source_id": args.source_id,
175+
**extra,
175176
"opt_destination_id": opt_destination_id,
176177
"migrate_args": args,
177178
},
@@ -202,7 +203,7 @@ def migrate_events(
202203
destination.update(**get_group_backfill_attributes(caches, destination, events))
203204

204205
update_open_periods(source, destination)
205-
logger.info("migrate_events.migrate", extra={"destination_id": destination_id})
206+
logger.info("migrate_events.migrate", extra={**extra, "destination_id": destination_id})
206207

207208
if isinstance(args, InitialUnmergeArgs) or opt_eventstream_state is None:
208209
eventstream_state = args.replacement.start_snuba_replacement(
@@ -522,6 +523,8 @@ def unlock_hashes(project_id: int, locked_primary_hashes: Sequence[str]) -> None
522523
)
523524
def unmerge(*posargs: Any, **kwargs: Any) -> None:
524525
args = UnmergeArgsBase.parse_arguments(*posargs, **kwargs)
526+
extra = {"source_id": args.source_id, "project_id": args.project_id}
527+
logger.info("unmerge.start.task", extra=extra)
525528

526529
source = Group.objects.get(project_id=args.project_id, id=args.source_id)
527530

@@ -552,22 +555,14 @@ def unmerge(*posargs: Any, **kwargs: Any) -> None:
552555
# Convert Event objects to GroupEvent objects
553556
events: list[GroupEvent] = [event.for_group(source) for event in raw_events]
554557
# Log info related to this unmerge
555-
logger.info(
556-
"unmerge.check",
557-
extra={
558-
"source_id": source.id,
559-
"num_events": len(events),
560-
},
561-
)
558+
logger.info("unmerge.check", extra={**extra, "num_events": len(events)})
562559

563560
# If there are no more events to process, we're done with the migration.
564561
if not events:
565562
unlock_hashes(args.project_id, locked_primary_hashes)
566-
for unmerge_key, (group_id, eventstream_state) in args.destinations.items():
563+
for unmerge_key, (_, eventstream_state) in args.destinations.items():
567564
logger.warning(
568-
"Unmerge complete (eventstream state: %s)",
569-
eventstream_state,
570-
extra={"source_id": source.id},
565+
"Unmerge complete (eventstream state: %s)", eventstream_state, extra=extra
571566
)
572567
if eventstream_state:
573568
args.replacement.stop_snuba_replacement(eventstream_state)
@@ -597,7 +592,7 @@ def unmerge(*posargs: Any, **kwargs: Any) -> None:
597592
logger.info(
598593
"unmerge.destinations",
599594
extra={
600-
"source_id": source.id,
595+
**extra,
601596
"source_events": len(source_events),
602597
"destination_events": len(destination_events),
603598
"source_fields_reset": source_fields_reset,

0 commit comments

Comments
 (0)