-
Notifications
You must be signed in to change notification settings - Fork 789
celery: allow using links instead of child spans for task execution #3779
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
Open
jlc-christie
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
jlc-christie:celery-allow-using-links-instead-of-child-spans
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,63 @@ def _retrieve_context_wrapper_none_token( | |
|
||
unwrap(utils, "retrieve_context") | ||
|
||
def test_task_use_span_links(self): | ||
CeleryInstrumentor().instrument(use_span_links=True) | ||
|
||
result = task_add.delay(1, 2) | ||
|
||
timeout = time.time() + 60 * 1 # 1 minute from now | ||
while not result.ready(): | ||
if time.time() > timeout: | ||
break | ||
time.sleep(0.05) | ||
|
||
spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) | ||
self.assertEqual(len(spans), 2) | ||
|
||
consumer, producer = spans | ||
|
||
self.assertEqual(consumer.name, "run/tests.celery_test_tasks.task_add") | ||
self.assertEqual(consumer.kind, SpanKind.CONSUMER) | ||
self.assertSpanHasAttributes( | ||
consumer, | ||
{ | ||
"celery.action": "run", | ||
"celery.state": "SUCCESS", | ||
SpanAttributes.MESSAGING_DESTINATION: "celery", | ||
"celery.task_name": "tests.celery_test_tasks.task_add", | ||
}, | ||
) | ||
|
||
self.assertEqual(consumer.status.status_code, StatusCode.UNSET) | ||
self.assertEqual(0, len(consumer.events)) | ||
|
||
self.assertEqual( | ||
producer.name, "apply_async/tests.celery_test_tasks.task_add" | ||
) | ||
self.assertEqual(producer.kind, SpanKind.PRODUCER) | ||
self.assertSpanHasAttributes( | ||
producer, | ||
{ | ||
"celery.action": "apply_async", | ||
"celery.task_name": "tests.celery_test_tasks.task_add", | ||
SpanAttributes.MESSAGING_DESTINATION_KIND: "queue", | ||
SpanAttributes.MESSAGING_DESTINATION: "celery", | ||
}, | ||
) | ||
Comment on lines
+266
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section of code is just duplicated from |
||
|
||
# Verify that consumer span is not a child of producer span when using links | ||
self.assertIsNone(consumer.parent) | ||
self.assertNotEqual( | ||
consumer.context.trace_id, producer.context.trace_id | ||
) | ||
|
||
# Verify that consumer span has a link to the producer span | ||
self.assertEqual(len(consumer.links), 1) | ||
link = consumer.links[0] | ||
self.assertEqual(link.context.span_id, producer.context.span_id) | ||
self.assertEqual(link.context.trace_id, producer.context.trace_id) | ||
|
||
|
||
class TestCelerySignatureTask(TestBase): | ||
def setUp(self): | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but this pylint rule seems useless in this project, can we disable it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True... I added it to keep it consistent with the rest of the file but I'll add an issue to the project for this