This release of the Python agent improves data collection with the Django web framework. These improvements include better-targeted web transaction naming with the Django REST framework, better coverage of Django template inclusion tags, and better background task monitoring for Django management commands.
For a list of known issues with the Python agent see Status of the Python agent.
Improved Django REST Framework naming
Previously, when using the Django REST framework, web transactions were being named after the class based view that implemented the Django REST framework resources. Now, where such a view provides custom handler methods for different HTTP request method types or actions, the web transaction will be named after that custom handler method rather than the class as a whole. A new function breakdown metric will also be added for the custom handler method. This change will allow web requests using different HTTP request method types to be viewed separately.
Django inclusion tag monitoring
Usage of inclusion tags in Django templates can now be monitored and will appear in the transaction breakdown table, charts and sample transaction traces.
Due to the possibility that a large range of custom inclusion tags might be used and that they may be invoked a large number of times in tight loops, tracking of all inclusion tags may not be practical or may not produce worthwhile results in the transaction breakdown or sample transaction traces. As a result, monitoring of inclusion tags is off by default, with the preferred approach being that specific inclusion tags of interest be individually enabled through the agent configuration file.
To enable monitoring of specific inclusion tags, a new section called
import-hook:djangoshould be added to the agent configuration:[import-hook:django]instrumentation.templates.inclusion_tag = prepopulated_fields_js date_hierarchy
instrumentation.templates.inclusion_tagsetting within that section should then be set to a space separated list of the names of the inclusion tags to monitor. If there is any confusion over the identity of the inclusion tag, the full name of the inclusion tag function, with module name, can instead be listed. For example,
data_hierarchycan also be identified using
In addition to specifying the names of the specific inclusion tags, it is also possible to specify
instrumentation.templates.inclusion_tagin order to have usage of all inclusion tags be monitored:[import-hook:django]instrumentation.templates.inclusion_tag = *
Enabling monitoring of all inclusion tags in this way is only recommended in development or test environments so as to get an initial idea of what inclusion tags are worth tracking. Once identified, the specific inclusion tags of interest should thereafter be listed individually in a production environment.
Better monitoring of Django management commands
We previously published a blog post about how the agent could be used to monitor Django management commands. This required you to manually set up the instrumentation for each specific Django management command in the agent configuration file. We have now made that easier by integrating the functionality as part of the agent itself.
Due to the limitations on what Django management commands can be monitored, you will still need to list explicitly the commands you want monitored, but it can now be done in a single location as a space separated list under the setting
import-hook:djangosection:[import-hook:django]instrumentation.scripts.django_admin = syncdb sqlflush
By default, we automatically specify the startup timeout to be
10.0seconds when monitoring the Django management commands. If you need to override the startup timeout, you can set the
instrumentation.background_task.startup_timeoutsetting within the same