Python Agent

Released on: 
Saturday, November 2, 2013 - 22:33


This release of the Python agent contains support for web applications and worker processes using 'gearman' for background task execution. The agent also switches to using the 'json' package from the standard library instead of a separate 'simplejson' package. This should result in potential reductions in base level memory usage by the agent and a reduction of CPU overhead for some environments.

The agent can be installed using easy_install/pip/distribute via the Python Package Index or can be downloaded directly from our download site.

For a list of known issues with the Python agent see our online help article on the status of the Python agent.

New Features:

  • Instrumentation now provided for the gearman package. The support covers use of both the gearman client and worker interfaces. In the case of workers, each task executed by the worker will be recorded as a background task and be displayed as such in the New Relic UI.

  • The ignore_errors argument to newrelic.agent.record_exception() can now be a callable in addition to being able to pass a sequence. When it is a callable, the callback will be called with the three arguments exc, value and tb, being the same values as returned by sys.exc_info(). The callback should return True if the exception is to be ignored. False if the exception should never be ignored regardless of any other checks, and None if subsequent checks and inbuilt rules should determine if the exception should be ignored. A callback would normally return either True or None.

Bug fixes/Improvements:

  • The bundled 'simplejson' package has now been removed and is no longer used. This was previously used due to the requirement to support Python 2.5, for which support was removed in version 2.0.0 of the agent. Instead of simplejson, the 'json' package contained in the Python standard library is now used instead. This should see the base level memory usage of the agent drop as a result. Further, in environments where a C compiler was not available and the C extension modules could not be compiled, there should now be a minimal reduction in the CPU overhead when the agent is uploading data to our back end. This is because the optimised C extension in the json package will always be available as part of the Python standard library and will always be able to be used.

  • If a WSGI application was returning an iterable such as a generator, and an exception was raised when a specific part of the response content was yielded from the generator, the details of the exceptions were not being recorded.

  • In a multithreaded web application where deferred module imports were being performed in secondary threads, agent registration could fail the first time due to concurrent changes made by the secondary threads to sys.modules. Registration would succeed on a subsequent attempt. This bug was only occurring in Python 2 and was introduced in version 2.0.0 of the agent when Python 3 support was added.

  • Custom parameters which were explicitly supplied to newrelic.agent.record_exception() were being ignored and were not appearing in the error details page in the UI. Instead, only custom parameters added using newrelic.agent.add_custom_parameters() against the web transaction or background task itself were being shown. This bug was introduced in version 1.13.0 of the agent when support for cross application tracing was added.

  • The port number used in the URL for a web external call, was not being retained when the URL was added as a parameter against the web external node for transaction traces. The port would therefore not be displayed when drilling down into the details of a web external node in a transaction trace.

  • The newrelic-admin validate-config command will now work for enterprise high security mode accounts, provided of course that no setting is otherwise specified in the agent configuration file which is in conflict with that mode. That is, features such as SSL would still need to be enabled by the ssl setting and the capture_params setting indicating whether URL query string parameters should be captured, also set to false.

  • When using CherryPy, in addition to the explicit exception type 'NotFound' being ignored as an error, raising of a 'HTTPError' exception where the status is 404 will also be ignored. Similarly, instances of the 'HTTPError' exception will be ignored as an error when they are for a HTTP error in the 30X range.