For some functions, the New Relic Python agent API has several options for accomplishing the same thing. For example, tracing a function to provide more details on a New Relic-monitored transaction can theoretically be accomplished, depending on your setup, with any of the following APIs:
- A decorator. This is an import-time API. This will be the easiest option for most Python application setups.
- A context manager. This is a runtime-level API. These APIs might be used if you want to trace code that's not encapsulated in a function.
- A wrapper. The wrapper is used to create a wrapped function without the use of a decorator.
- A path-based wrapper. This would be used to wrap functions outside of the code they're declared in. For example, it can be used to instrument library code that you don't want to modify.
For an example of a Python agent API with all four of these possible, see the function_trace
call entry.