Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: Instrumenting third party python library packages/modules


#1

Sometimes, you will notice that most of the time is spent in your app occurring in 3rd party packages . For instances you might see in your transaction traces a lot of time spent in “Application code” :
Application code () :

When you want to instrument/configure your Python app to get a deeper visibility into your application function, kindly follow the steps below:

  1. Add function traces to those 3rd party packages using the transaction_tracer.function_trace setting in the newrelic.ini file. As long as the values are module:Class.function the agent will be able to instrument it!

  2. Use the Thread profiler to get 3rd party abstracted calls. This will show you how much time is being spent in each method as a percentage of total-time across all transactions.

  3. Use the newrelic.agent.profile_trace decorator. This api is experimental and undocumented. It will add function traces to all functions called by one decorated up to a given depth. This could add additional unneeded overhead. Therefore, we would highly suggest removing the decorator once the performance problem has been located. Here’s an example usage:

    @newrelic.agent.profile_trace(depth=3)
    def save():
        # 3rd party function calls from packages/libs
    

Let us know if you have any thoughts or questions.