Skip to content

Conversation

@sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Dec 10, 2025

Description

Add a queue.submit.django span when a Task in enqueued via Django.

Screenshot 2025-12-10 at 13 26 04

Issues

Closes #5201
Closes PY-2006

Reminders

@sentrivana sentrivana requested a review from a team as a code owner December 10, 2025 12:27
@linear
Copy link

linear bot commented Dec 10, 2025

@sentrivana sentrivana changed the title feat(django): Add span for Task.enqueue feat(django): Add span around Task.enqueue Dec 10, 2025
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.26%. Comparing base (46676a9) to head (176a660).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/integrations/django/tasks.py 91.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5209      +/-   ##
==========================================
+ Coverage   82.87%   84.26%   +1.39%     
==========================================
  Files         181      182       +1     
  Lines       18459    18489      +30     
  Branches     3287     3290       +3     
==========================================
+ Hits        15297    15580     +283     
+ Misses       2141     1895     -246     
+ Partials     1021     1014       -7     
Files with missing lines Coverage Δ
sentry_sdk/consts.py 99.41% <100.00%> (+<0.01%) ⬆️
sentry_sdk/integrations/django/__init__.py 85.27% <100.00%> (+0.07%) ⬆️
sentry_sdk/integrations/django/tasks.py 91.30% <91.30%> (ø)

... and 16 files with indirect coverage changes

)

with sentry_sdk.start_span(
op=OP.QUEUE_SUBMIT_DJANGO, name=name, origin=DjangoIntegration.origin
Copy link

Choose a reason for hiding this comment

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

Bug: Queue span uses HTTP origin instead of queue origin

The queue.submit.django span uses DjangoIntegration.origin which is "auto.http.django", but queue operations in other integrations (arq, celery, huey) consistently use "auto.queue.{name}" as the origin. This causes the span to be incorrectly categorized as an HTTP operation rather than a queue operation, which is inconsistent with other queue integrations and may affect how Sentry analyzes and displays queue-related telemetry data.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a valid point @sentrivana.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDK if origin is actually used anywhere on the server, but the OG idea behind the field is just to be able to determine which integration the span is coming from, nothing more.

When someone actually uses Celery/some other queuing library as a backend for django.tasks, those will have their own origin.

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

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

LGTM, see the comments before merging 🙏

return old_task_enqueue(self, *args, **kwargs)

name = (
getattr(self.func, "__name__", repr(self.func)) or "<unknown Django task>"
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: would it make more sense to use __qualname__ here?

Suggested change
getattr(self.func, "__name__", repr(self.func)) or "<unknown Django task>"
getattr(self.func, "__qualname__", repr(self.func)) or "<unknown Django task>"

)

with sentry_sdk.start_span(
op=OP.QUEUE_SUBMIT_DJANGO, name=name, origin=DjangoIntegration.origin
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a valid point @sentrivana.

if integration is None:
return old_task_enqueue(self, *args, **kwargs)

name = qualname_from_function(self.func) or "<unknown Django task>"

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not public, but it's def there and pretty integral to the whole tasks feature, so I don't expect it to disappear.

@sentrivana sentrivana merged commit f8f49f6 into master Dec 11, 2025
153 checks passed
@sentrivana sentrivana deleted the ivana/django-tasks branch December 11, 2025 10:50
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.

Check that Django 6.0 is fully instrumented

3 participants