Add tracking for Celery canvas primitives (map/starmap/chunks)#38
Merged
Add tracking for Celery canvas primitives (map/starmap/chunks)#38
Conversation
0a65d2b to
802d3f3
Compare
Previously, tasks spawned via Celery canvas primitives like map, starmap, and chunks were not tracked because these execute as built-in celery.map or celery.starmap tasks, which were filtered out by the before_task_publish signal handler. This change adds a _maybe_create_task function called during task_prerun that: - Creates TaskBadger tasks for canvas primitives with descriptive names like "(map 5) myapp.tasks.process_item" - Includes metadata about canvas_type and item_count in task data - Optionally includes celery_task_items when record_task_args is enabled - Carefully orders checks to avoid thread-local Badger state pollution - Respects existing tracking intent via taskbadger_track header For example, when using task.chunks(items, 2).group(), each chunk now creates a TaskBadger task named "(starmap 2) myapp.tasks.process_item" with data showing the canvas type and item count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
map,starmap,chunks)canvas_typeanditem_counttest_task_map,test_task_starmap, andtest_task_chunksBackground
Previously, tasks using canvas primitives like
task.chunks(items, n).group()ortask.map(items)were not tracked because these execute as built-incelery.map/celery.starmaptasks, which were filtered out by thebefore_task_publishsignal handler.Implementation
Added
_maybe_create_taskfunction called duringtask_prerunthat:{"canvas_type": "celery.starmap", "item_count": 3}taskbadger_trackheaderTest plan
🤖 Generated with Claude Code