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

Set task ID on span (Celery integration) #3015

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions sentry_sdk/consts.py
Expand Up @@ -270,6 +270,11 @@ class SPANDATA:
e.g. the queue name or topic.
"""

MESSAGING_MESSAGE_ID = "messaging.message.id"
"""
The message's identifier.
"""

MESSAGING_MESSAGE_RETRY_COUNT = "messaging.message.retry.count"
"""
Number of retries/attempts to process a message.
Expand Down
2 changes: 2 additions & 0 deletions sentry_sdk/integrations/celery/__init__.py
Expand Up @@ -356,6 +356,8 @@ def _inner(*args, **kwargs):
op=OP.QUEUE_PROCESS, description=task.name
) as span:
_set_messaging_destination_name(task, span)
with capture_internal_exceptions():
span.set_data(SPANDATA.MESSAGING_MESSAGE_ID, task.request.id)
with capture_internal_exceptions():
span.set_data(
SPANDATA.MESSAGING_MESSAGE_RETRY_COUNT, task.request.retries
Expand Down
14 changes: 14 additions & 0 deletions tests/integrations/celery/test_celery.py
Expand Up @@ -661,6 +661,20 @@ def task(): ...
assert "messaging.destination.name" not in span["data"]


def test_messaging_id(init_celery, capture_events):
celery = init_celery(enable_tracing=True)
events = capture_events()

@celery.task
def example_task(): ...

example_task.apply_async()

(event,) = events
(span,) = event["spans"]
assert "messaging.message.id" in span["data"]


def test_retry_count_zero(init_celery, capture_events):
celery = init_celery(enable_tracing=True)
events = capture_events()
Expand Down