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

feat(celery): Queues module producer implementation #3079

Merged
merged 2 commits into from
May 17, 2024

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented May 16, 2024

Depends on #3082

Fixes #3078

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/celery-producer branch from dd9cd92 to 3d6154d Compare May 16, 2024 17:13
Copy link

@edwardgou-sentry edwardgou-sentry left a comment

Choose a reason for hiding this comment

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

tested locally, from a product perspective I think this looks good. Thanks!

Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

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

Just one question, but otherwise looks very good!

def sentry_publish(self, *args, **kwargs):
# type: (Producer, *Any, **Any) -> Any
kwargs_headers = kwargs.get("headers", {})
if not isinstance(kwargs_headers, Mapping):
Copy link
Member

Choose a reason for hiding this comment

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

If kwargs_headers is a list [("key", "value"), ("k", "v")] then it would be reset to an empty dict?

I am not sure if this list of tuples could happen, but I do not understand this if.

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, what I am trying to do here is to make sure that the get operations (line 453 to 455) are successful.

Mapping (full name collections.abc.Mapping) is the abstract base class that all mapping types in Python inherit from. dict inherits from Mapping, so this isinstance is true for any dictionary, but it would also be possible to create a custom Mapping type, which provides similar functionality to a dict, but which does not inherit from dict. This isinstance also evaluates to True for any of these dict-like data structures.

Regarding your example, isinstance([("key", "value"), ("k", "v")], Mapping) would evaluate to False since list does not inherit from Mapping (it does not have a get method, which all Mapping types have). So, we would replace it with an empty dictionary to ensure that the get calls don't raise an exception.

Copy link
Member

Choose a reason for hiding this comment

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

now I get it!

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/celery-producer branch from 3d6154d to de047fe Compare May 17, 2024 08:56
def sentry_publish(self, *args, **kwargs):
# type: (Producer, *Any, **Any) -> Any
kwargs_headers = kwargs.get("headers", {})
if not isinstance(kwargs_headers, Mapping):
Copy link
Member

Choose a reason for hiding this comment

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

now I get it!

@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/celery-producer branch from de047fe to 4402cf4 Compare May 17, 2024 10:07
szokeasaurusrex added a commit that referenced this pull request May 17, 2024
Recently `flake8` started to fail with `N803` errors in some places where it had previously passed. This PR adds `# noqa` comments to suppress these errors.

Unblocks #3079
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/celery-producer branch from 4402cf4 to 3283960 Compare May 17, 2024 10:34
@szokeasaurusrex szokeasaurusrex changed the base branch from master to szokeasaurusrex/fix-linter-failures May 17, 2024 10:35
Base automatically changed from szokeasaurusrex/fix-linter-failures to master May 17, 2024 11:05
@szokeasaurusrex szokeasaurusrex force-pushed the szokeasaurusrex/celery-producer branch from 3283960 to 22df82d Compare May 17, 2024 11:10
@szokeasaurusrex szokeasaurusrex merged commit 22df82d into master May 17, 2024
111 checks passed
@szokeasaurusrex szokeasaurusrex deleted the szokeasaurusrex/celery-producer branch May 17, 2024 11:24
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.

Queues module: Celery producer instrumentation
3 participants