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

Celery add support for anon tasks #1052

Conversation

goatsthatcode
Copy link

@goatsthatcode goatsthatcode commented Apr 13, 2022

Description

This changes the way spans are initialized for the celery instrumentation hooks and handles the case where Celery tasks are not available in the registry and called anonymously using the signature() or send_task()

Fixes #1002, #609
possibly addresses #784

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

@goatsthatcode Did you run the reproducible example provided in #609 and can confirm it is fixed?

@@ -132,6 +132,11 @@ def attach_span(task, task_id, span, is_publish=False):
NOTE: We cannot test for this well yet, because we do not run a celery worker,
and cannot run `task.apply_async()`
"""
if task is None:
Copy link
Member

Choose a reason for hiding this comment

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

I'll copy the comment I wrote on the original PR in your fork for the wide discussion:

I think the effect of this return statement is that the span (along with activation) will not be recorded into the CTX_KEY, which means that a later invocation of the _trace_after_publish signal will not be able to retrieve_span thus will not end the span.
Am I missing something?

Didn't actually try to run it, so I might just not fully understand the details of what causes the "publish" span to be ended.

@goatsthatcode
Copy link
Author

Hi guys, sorry for the radio silence here. I got really sick this last week so was offline for a bit. I am picking up the remaining pieces today to make sure this at least ready to be merged (unless any additional comments come up). Sorry for the delay :D

@sanketmehta28
Copy link
Member

Please resolves build errors.

@yousifd
Copy link

yousifd commented May 17, 2022

@goatsthatcode can you please resolve the build errors?

Copy link

@Vivalldi Vivalldi left a comment

Choose a reason for hiding this comment

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

I believe these will take care of the linting issues

def test_hidden_task(self):
# no-op since already instrumented
CeleryInstrumentor().instrument()
import ipdb; ipdb.set_trace()
Copy link

Choose a reason for hiding this comment

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

Suggested change
import ipdb; ipdb.set_trace()
import ipdb
ipdb.set_trace()

Copy link
Member

Choose a reason for hiding this comment

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

pytest-ipdb is unfortunately not supported anymore.
You can remove these lines.

The solution is to add "--pdb --pdbcls=IPython.terminal.debugger:Pdb" with pytest command

From the help command:

pytest -h
--pdb start the interactive Python debugger on errors.
--pdbcls=modulename:classname
start a custom interactive Python debugger on errors.
For example:
--pdbcls=IPython.terminal.debugger:TerminalPdb

Comment on lines +119 to +121
self.assertEqual(
producer.name, "apply_async/app.hidden_task"
)
Copy link

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(
producer.name, "apply_async/app.hidden_task"
)
self.assertEqual(producer.name, "apply_async/app.hidden_task")

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we still working on this issue ?

@sanketmehta28
Copy link
Member

There are still some lint and generate build issues. Please do resolve them

@naormalca
Copy link
Contributor

@goatsthatcode i'm very interested in this fix, are you still working on it? if not, could i take it from here?

@srikanthccv
Copy link
Member

succeeded by #1407

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.

Using CeleryInstrumentor and linking Celery task trace back to requested trace
8 participants