Syntax
newrelic.agent.web_transaction(application=None, name=None, group=None, scheme=None, host=None, port=None, request_method=None, request_path=None, query_string=None, headers=None)
Used to instrument a web transaction.
Requirements
Agent version 4.16.0.116 or higher
Description
This Python decorator can be used to instrument web transactions. Transactions marked with this decorator are shown in the APM UI under web transactions and are separate from non-web transactions.
If you cannot use the decorator, one of these call formats may be more useful:
- The wrapper: If you know in advance where the specific functions you want to track are, you can use the
web_transaction
decorator. But if you don't know all the functions that need to be traced (for example, if they're being looked up dynamically as part of a routing system), then you must use theWebTransactionWrapper
to wrap the function at the time of registration or at the time of calling. - The path-based wrapper: The path-based wrapper form is
wrap_web_transaction
.
For more on the differences between and uses of these function forms, see Variable call formats.
Parameters
Decorator parameters
newrelic.agent.web_transaction(application=None, name=None, group=None, scheme=None, host=None, port=None, request_method=None, request_path=None, query_string=None, headers=None)
Parameters for these calls:
Parameter | Description |
---|---|
Application instance | Optional. The application under which the data will be reported. If left without a value, the application specified in the agent configuration (config file or environment variable) will be used. For more on generating an application object, see the |
string | Optional. The name of the transaction. By default, the name will be the name of the function the decorator has been applied to but you can override this by supplying this name. |
string | Optional. The If not supplied, the group defaults to |
string | Optional. The scheme portion of the request URL |
string | Optional. The host portion of the request URL |
integer | Optional. The port portion of the request URL |
string | Optional. The HTTP request method, such as GET or POST |
string | Optional. The remainder of the request URL's path |
string | Optional. The portion of the request URL that follows the question mark |
iterable or dict | Optional. The HTTP request headers An iterable of [name, value] two-item iterables or dict of |
Wrapper parameters:
newrelic.agent.WebTransactionWrapper(wrapped, application=None, name=None, group=None, scheme=None, host=None, port=None, request_method=None, request_path=None, query_string=None, headers=None)
WebTransactionWrapper
takes the same parameters as the web_transaction
decorator and this additional wrapped
parameter:
Parameter | Description |
---|---|
method | Required. The method to be traced. |
Path-based parameters:
newrelic.agent.wrap_web_transaction(module, object_path, application=None, name=None, group=None, scheme=None, host=None, port=None, request_method=None, request_path=None, query_string=None, headers=None)
wrap_web_transaction
takes the same parameters as the web_transaction
decorator plus these additional parameters:
Parameter | Description |
---|---|
module or string | Required. The module containing the web function/activity you are instrumenting. |
string | Required. The path to the module. |
Examples
web_transaction
decorator example
Here's an example of using the web_transaction decorator:
@newrelic.agent.web_transaction()def get(): ...
WebTransactionWrapper
example
An example of using the WebTransactionWrapper
:
task = newrelic.agent.WebTransactionWrapper(get_next_task())result = task(*args, **kwargs)