Syntax
newrelic.agent.message_transaction(library, destination_type, destination_name, application, routing_key=None, exchange_type=None, headers=None, queue_name=None, reply_to=None, correlation_id=None)
Report message functions as transactions.
Requirements
Agent version 2.88.0.72 or higher.
Description
This decorator returns a partial of MessageTransactionWrapper
that can be used as a decorator for a messaging function. When used, the returned decorator records a message transaction and its message-related attributes.
If the decorator will not work in your application, you can use one of the following:
- The context manager: The context manager form is
MessageTransaction
. It takes the same parameters as the decorator. - The wrapper: The wrapper form is
MessageTransactionWrapper
. It can be used to return a wrapped function without the use of a decorator. - The path-based wrapper: The path-based wrapper form is
wrap_message_transaction
. This applies theMessageTransactionWrapper
to a given object through monkey patching. This takes the same parameters as the decorator plus an additionalmodule
andobject_path
parameter.
For an explanation of when these different calls should be used, see Different call formats. See Examples for call examples.
Parameters
Parameters for message_transaction and MessageTransaction
newrelic.agent.message_transaction(library, destination_type, destination_name, application, routing_key=None, exchange_type=None, headers=None, queue_name=None, reply_to=None, correlation_id=None)
newrelic.agent.MessageTransaction(library, destination_type, destination_name, application, routing_key=None, exchange_type=None, headers=None, queue_name=None, reply_to=None, correlation_id=None)
The decorator and context manager use these parameters:
Parameter | Description |
---|---|
string or function | Required. The name (or type) of message broker in use. Pass either a string which defines it or a function which returns it. |
string or function | Required. The type of destination targeted by the operation. Pass either a string which defines it or a function which returns it. This is typically |
string or function | Required. The name of the destination being targeted by the operation. Pass either a string which defines it or a function which returns it. |
Application | Required. An application instance, as returned by |
string or function | Optional. The routing key of the message. |
string or function | Optional. The exchange type of the message. |
dictionary or function | Optional. The headers of the message. |
string or function | Optional. The queue name property of the message. |
string or function | Optional. The |
string or function | Optional. The |
Parameters for MessageTransactionWrapper
newrelic.agent.MessageTransactionWrapper(wrapped, library, destination_type, destination_name, application, routing_key=None, exchange_type=None, headers=None, queue_name=None, reply_to=None, correlation_id=None)
The MessageTransactionWrapper
takes all of the same parameters as the decorator in addition to this wrapped
parameter:
Parameter | Description |
---|---|
function | Required. The messaging function to attribute to the message broker time. |
Parameters for wrap_message_transaction
newrelic.agent.wrap_message_transaction(module, object_path, library, destination_type, destination_name, application, routing_key=None, exchange_type=None, headers=None, queue_name=None, reply_to=None, correlation_id=None)
This takes all of the parameters that the decorator does in addition to a module
parameter and an object_path
parameter:
Parameter | Description |
---|---|
object | Required. The module containing the object to be wrapped. |
string | Required. The path to the object to be wrapped. |
Return values
The decorator message_transaction
returns a MessageTransactionWrapper
partial.
Examples
message_transaction example
An example of the decorator:
mt = message_transaction('library', 'Exchange', 'x', routing_key='foo.bar')
@mtdef foo(): pass
MessageTransaction example
An example using the context manager:
def callback(method, properties, body): with MessageTransaction('library', 'Exchange', 'x', application=app): pass
MessageTransactionWrapper example
An example using the wrapper:
basic_consume_wrapper = newrelic.agent.MessageTransactionWrapper(basic_consume_register_callback, 'library', 'Queue', 'x')
method_frame, header_frame, body = basic_consume_wrapper('queue')
wrap_message_transaction example
An example using the path-based wrapper:
wrap_message_transaction('module', 'Foo.bar', 'library', 'Exchange', 'x')