Skip to content

aioredis raises CancelledError in _finish_span  #3253

@mabdinur

Description

@mabdinur

Which version of dd-trace-py are you using?

0.53.0 0.58.0

Which version of pip are you using?

21.3.1

Which version of the libraries are you using?

django==3.2.11
django-redis==5.0.0
channels==3.0.4
daphne==3.0.2

How can we reproduce your problem?

I am using code similar to the following:

asgi.py

import django
from channels.routing import get_default_application
from ddtrace.contrib.asgi import TraceMiddleware

django.setup()
application = TraceMiddleware(get_default_application())

routing.py

from django.urls import re_path
import my_app.consumers

websocket_urlpatterns = [
    re_path(r"^ws/test/$", consumers.TestConsumer.as_asgi()),
]

my_app/consumers.py

from channels.generic.websocket import WebsocketConsumer

class TestConsumer(WebsocketConsumer):
    groups = ["broadcast"]

    def connect(self):
        self.accept()

    def receive(self, text_data=None, bytes_data=None):
        raise Exception("An test exception")

I am running the application with: ddtrace-run daphne asgi:application --bind 0.0.0.0 --port 8001

What is the result that you get?

I don't get any traces at all, and my logs show this:

handle: <Handle traced_13_execute_command.<locals>._finish_span(<Future cancelled>) at /usr/local/lib/python3.10/site-packages/ddtrace/contrib/aioredis/patch.py:140>

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/aioredis/patch.py", line 146, in _finish_span
    future.result()
asyncio.exceptions.CancelledError

What is the result that you expected?

No errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions