Last active
December 16, 2015 21:29
-
-
Save GrahamDumpleton/5500025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this on module path in file newrelic_django_nap.py. | |
# | |
# In agent configuration file add: | |
# | |
# [import-hook:nap.publisher] | |
# enabled = true | |
# execute = newrelic_django_nap:instrument_django_nap_publisher | |
from newrelic.agent import (current_transaction, set_transaction_name, | |
FunctionTrace, callable_name, wrap_function_wrapper) | |
def _nr_wrapper_nap_publisher_BasePublisher_execute_(wrapped, instance, args, kwargs): | |
transaction = current_transaction() | |
if transaction is None: | |
return wrapped(*args, **kwargs) | |
def _bind_params(handler, *args, **kwargs): | |
return handler | |
handler = _bind_params(*args, **kwargs) | |
name = callable_name(handler) | |
set_transaction_name(name) | |
with FunctionTrace(transaction, name): | |
return wrapped(*args, *kwargs) | |
def instrument_django_nap_publisher(module): | |
wrap_function_wrapper(module, 'BasePublisher.execute', | |
_nr_wrapper_nap_publisher_BasePublisher_execute_) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment