Python custom instrumentation

Custom instrumentation allows you to expand the agent's default instrumentation to target additional functional calls. You can do so via the agent config file, or via the agent API.

Config file or API?

You can edit the Python agent config file, or you can use the agent API.

  • If you simply want to trace time spent in additional functions or methods of classes, you can identify a list of functions or methods in the agent configuration file. For more information, see Instrumentation via config file.
  • For more complex cases, or if you want to customize how the function is identified within the UI, you can make direct calls to the agent API in your code. For more information, see Instrumentation via API.

In either case, these mechanisms only target the designated function call. It is not recursive, nor does it enable full profiling below the annotated function.

Additional considerations

You must individually annotate each function call you want to trace. If you are not sure what to apply the function traces to, you can use New Relic's thread profiling or X-Ray sessions features to narrow it down.

Collecting too many metrics can impact the performance of both your application and New Relic. To avoid potential data problems, try to keep the total number of unique metrics introduced by custom instrumentation under 2000.

For more help

For more information, see:

Join the discussion about Python in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at