No transaction traces for the background tasks in Tornado 4 application

Please paste the permalink to the page in question below:

Please share your agent version and other relevant versions below:

python 2.7

Please share your question/describe your issue below. Include any screenshots that may help us understand your question:

Hi there,

I’m trying to instrument newrelic agent for a non-web, background-only, tornado 4 service.

The architecture of the service is very simple:
the service is a rabbitmq consumer implemented using pika (

The on_message handler is wrapped in @gen.coroutine.

My goal is to track each on_message execution as a separate transaction.

I’ve tried the following:

  1. In my newrelic.ini I added the following line
feature_flag = tornado.instrumentation.r3 
  1. Also, disabled motor hook as it was throwing errors
enabled = false
  1. Enabled debugging
log_file = stderr
log_level = debug
  1. In my code I instrumented newrelic agent as follows
        def on_message(self, channel, method, props, message):
            """Process a task."""
            application = newrelic.agent.application()
            if getattr(props, 'content_type', None) == 'application/json':
                    message = json.loads(message)
                except ValueError:
                    LOGGER.warn('Invalid message format: %r', message)

            with newrelic.agent.BackgroundTask(application, name=message['method'],
                    self.count_receive(message, props)
                    yield self.process(message, props)
                except HttpAccessTokenRefreshError:
                    # Client has revoked his token, in that case remove the task from queue

                except Exception as exc:  # noqa
                    self.retry(message, method, props)
  1. I run the service using the newrelic-admin cli tool like this
    NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-python -m service
  2. I can see the basic stats reported to the newrelic dashboard (host CPU/Memory usage) but not the transaction traces. There are no errors in the log output

Here is some more technical information:

  1. newrelic agent logs
  2. pip freeze output
  3. python version 2.7.13

Any help appreciated!

Per the documentation on the BackgroundTask generator (linked below), it appears you are missing the register_application call. If using the generator, the register_application code is required in order to ensure the agent is started up.

This might look like the following pseudo code. Note the application = newrelic.agent.register_application(timeout=10) addition.

import newrelic.agent

import tornado.ioloop
from tornado import gen

def run_all():

if __name__=='__main__':
    application = newrelic.agent.register_application(timeout=10)
    with newrelic.agent.BackgroundTask(application, 'Hello World'):

Give that a try and let us know if things still are not reporting as expected.

Thanks for the reply. I’ll give it a try and will let you know if it helped.