Skip to content

Add extra Celery tags#205

Merged
adamchainz merged 1 commit intomasterfrom
issue_34_celery_queue_name
Aug 10, 2019
Merged

Add extra Celery tags#205
adamchainz merged 1 commit intomasterfrom
issue_34_celery_queue_name

Conversation

@adamchainz
Copy link
Copy Markdown
Contributor

Fixes #34. Tagging with the current queue is only sometimes possible - often the exchange and routing_key are provided instead. The task may have come from a particular queue, but its delivery information normally onyl tracks where it was sent at the top of the AMQP funnel by exchange + routing_key, since that's what's needed for retry. Also track the is_eager flag which may be useful for determining which way the task was run.

More information on these parameters can be gleaned from the source.

Updating the tests to use the fixture added in Celery 4.0, but since we support 3.1 this is in a conditional test. Our test suite currently installs the latest version of Celery only, so I tested locally temporarily with Celery 3.1 as well by specifying celery>=3.1,<3.2 in tox.ini. For complete automated testing in the future, we should look at a better requirements management system.

@adamchainz adamchainz requested a review from cschneid July 2, 2019 10:52
@adamchainz adamchainz force-pushed the issue_34_celery_queue_name branch 3 times, most recently from bc9bc03 to fedd677 Compare July 2, 2019 11:51
adamchainz added a commit that referenced this pull request Jul 2, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
adamchainz added a commit that referenced this pull request Jul 2, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
adamchainz added a commit that referenced this pull request Jul 3, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
Copy link
Copy Markdown
Contributor

@dlanderson dlanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions around changing method signatures and tags

span.tag("is_eager", delivery_info.get("is_eager", False))
span.tag("exchange", delivery_info.get("exchange", "unknown"))
span.tag("routing_key", delivery_info.get("routing_key", "unknown"))
span.tag("queue", delivery_info.get("queue", "unknown"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the core agent knows how to handle the queue tag, but the others are not supported explicitly and will be silently dropped, IIRC. Are we wanting to track this info in span tags or in context? @cschneid might chime in here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, I didn't know that span tags are dropped. Moving to request tags/context is probably the right move in that case, but I'll wait for @cschneid 's input.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in the core agent, span tags are very specific, and unknown ones are dropped. Some upcoming work will be to support the new trace structure, where arbitrary span tags are sent onward, but that's not for a bit. queue is recognized as the string queue name that the job was enqueued on & then popped off of.

For now it's probably ok to add these as request tags (context). But anyway, this does feel like it's scoped to the whole request (the job), not just the section of code that celery is calling first..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving them all to request tags then. I think I had a concern that celery might recursively execute tasks with its fancy chord structures, but after checking the docs again I don't think that's the case

@adamchainz adamchainz force-pushed the issue_34_celery_queue_name branch from fedd677 to 91380a1 Compare August 9, 2019 08:35
Fixes #34. Tagging with the current *queue* is only *sometimes* possible - often the *exchange* and *routing_key* are provided instead. The task may have come from a particular queue, but its delivery information normally onyl tracks where it was sent at the top of the AMQP funnel by exchange + routing_key, since that's what's needed for retry. Also track the `is_eager` flag which may be useful for determining which way the task was run.

More information on these parameters can be gleaned from [the source](https://github.com/celery/celery/blob/8cf8fae70630954cff3448485588bbe2a77ff3ab/celery/app/task.py#L600).

Updating the tests to use the fixture added in Celery 4.0, but since we support 3.1 this is in a conditional test. Our test suite currently installs the latest version of Celery only, so I tested locally temporarily with Celery 3.1 as well by specifying `celery>=3.1,<3.2` in `tox.ini`. For complete automated testing in the future, we should look at a better requirements management system.
@adamchainz adamchainz force-pushed the issue_34_celery_queue_name branch from 91380a1 to 0881794 Compare August 9, 2019 08:47
@adamchainz adamchainz merged commit a830a91 into master Aug 10, 2019
adamchainz added a commit that referenced this pull request Aug 10, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
adamchainz added a commit that referenced this pull request Aug 10, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
@adamchainz adamchainz deleted the issue_34_celery_queue_name branch August 10, 2019 08:42
adamchainz added a commit that referenced this pull request Aug 10, 2019
Fixes #35. Track the queue time by using an extra haeder to track when the task is added to the queue and comparing when it gets executed. This should work in most setups but if the celery app isn't all set up on the producer side, we are well defended against it.

Like #205, I manually tested on Celery 3.1.x locally by editing `tox.ini` and reinstalling with `tox -r`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture Celery Queue Name

3 participants