Skip to content

APM resource names for Django class-based views no longer include the view class name #5711

@sam-xif

Description

@sam-xif

Summary of problem

I recently performed an upgrade from Django 2.2 to Django 4.1 for a codebase that I contribute to, and we observed that resource names for traces of API calls to Django views changed: resource names now look like {method} <module>.views.view (we have DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT set to true) whereas they previously looked like {method} <module>.views.<view classname>. I managed to track down the ticket in Django which caused this to here, and the corresponding commit here, specifically the changes to django/views/generic/base.py.

The problem is that, prior to Django 4.0, the as_view() method of the base View used func_tools.update_wrapper to give the dynamically generated view() wrapper the proper __name__ and __qualname__ attributes to allow ddtrace to properly generate the resource name. Ever since the change linked previously, __name__ and __qualname__ are no longer implicitly set, and an inline comment in the code recommends a best practice of accessing the name and other metadata of the wrapped view through the view_class attribute on the returned object.

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

0.59.1, but I also confirmed that this behavior persists on the latest version, 1.12.2.

Which version of pip are you using?

20.0.2

Which libraries and their versions are you using?

`pip freeze`

datadog==0.43.0
ddtrace==0.59.1 (but note above that I also reproduced this bug with the latest version)
Django==4.1.7
djangorestframework==3.14.0

How can we reproduce your problem?

Look at APM traces of any class-based Django view, using Django >= 4.0, with DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT=true

What is the result that you get?

Resource names look like {method} <module>.views.view. This greatly reduces the readability and searchability of APM traces when using the {method} {handler} resource format (DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT=true), since the view class name is not included in the resource name.

What is the result that you expected?

Resource names should look like {method} <module>.views.<view classname>, as they did prior to the Django version upgrade.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions