How to start tracking the redis operations at newrelic for python application?

Viewed 123

When we start our flask application, we initialise the newrelic agent as below.

import newrelic.agent
newrelic.agent.initialize('newrelic.ini')

And it starts tracking the different transactions happening in the flask application. That includes, third-party external calls, MySQL/PostgreSQL/ElasticSearch operations.

Though it is not tracking the redis operations done using rejson package. I read somewhere that newrelic's python agent tracks the py-redis operations.

Are there any specific requirements/way to track redis operations in newrelic with python agent?

1 Answers

It looks like rejson has been depreciated with features merged into the redis library. Have you tried changing the redis operations from rejson to redis? I used the Getting Started example in https://pypi.org/project/redis/

Here's a Flask application I created that shows redis operations: First, I set up redis on Ubuntu.

sudo apt-get install redis
redis-server
redis-cli ping

Then I run my flask application

import newrelic.agent
newrelic.agent.initialize('newrelic.ini')

import redis

# Flask Web Application
flaskapp = Flask(__name__, static_url_path="/")

# Navigation
@flaskapp.route("/")
def index():
    r = redis.Redis(host='localhost', port=6379, db=0)
    r.set('foo', 'bar')
    return r.get('foo')

# Run Flask Web Application
if __name__ == "__main__":
    flaskapp.run()

Going to http://127.0.0.1:5000/ just shows bar as expected.

Then, in New Relic APM, I can see my Redis set and Redis get operations under Transactions, Databases, and Distributed Tracing. As well, Redis shows up in the service map. Redis Service Map

Redis Transaction

Redis Database

Redis Distributed Tracing

So to answer the original question, the New Relic python agent DOES track operations in the redis-py library. Nothing specific was used to configure the python agent other than the application name and the license key.

Related