Skip to content

Conversation

jlc-christie
Copy link

Description

As described in #3002, the current default behaviour results in all celery tasks that execute are child spans of the code that pushed it on to the broker, which conflicts with the semantic conventions.

This PR doesn't change the default behaviour since this may be undesirable for consumers expecting the behaviour to be consistent.

Fixes #3002 by providing an optional parameter to the .instrument() method to allow for optionally using span links, e.g.

CeleryInstrumentor().instrument(use_links=True)

Type of change

  • New feature (non-breaking change which adds functionality)

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

  • Unit test added
  • Tested E2E locally with jaeger with use_links=False and also use_links=True and observed the expected behaviour: when the flag is False (default) all task executions of a fan-out job are child spans of the code that enqueued it and when True they appeared as linked spans.

Does This PR Require a Core Repo Change?

  • 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

@jlc-christie jlc-christie requested a review from a team as a code owner September 24, 2025 16:24
Copy link

linux-foundation-easycla bot commented Sep 24, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Comment on lines +266 to +268
SpanAttributes.MESSAGING_DESTINATION: "celery",
},
)
Copy link
Author

Choose a reason for hiding this comment

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

This section of code is just duplicated from test_task, the remaining assertions below are the only meaningful changes

@jlc-christie jlc-christie force-pushed the celery-allow-using-links-instead-of-child-spans branch from b87b7a0 to 541face Compare September 26, 2025 08:00
@jlc-christie jlc-christie force-pushed the celery-allow-using-links-instead-of-child-spans branch from 541face to b87b7a0 Compare September 26, 2025 11:40
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

Should celery add a span link instead?
2 participants