Skip to content

Commit

Permalink
Add support for aiomcache
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek committed Sep 4, 2024
1 parent fe5a962 commit ea4039a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
25 changes: 24 additions & 1 deletion newrelic/hooks/datastore_aiomcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,30 @@
)


def capture_host(self, *args, **kwargs):
print(dir(self))
if hasattr(self, "servers"):
for s in self.servers:
if hasattr(s, "host"):
return s.host


def capture_port(self, *args, **kwargs):
if hasattr(self, "servers"):
for s in self.servers:
if hasattr(s, "port"):
return s.port


def instrument_aiomcache_client(module):
for name in _memcache_client_methods:
if hasattr(module.Client, name):
wrap_datastore_trace(module, "Client.%s" % name, product="Memcached", target=None, operation=name)
wrap_datastore_trace(
module,
"Client.%s" % name,
product="Memcached",
target=None,
operation=name,
host=capture_host,
port_path_or_id=capture_port,
)
7 changes: 4 additions & 3 deletions tests/datastore_aiomcache/test_aiomcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@

import aiomcache
from testing_support.db_settings import memcached_settings
from testing_support.fixture.event_loop import event_loop as loop
from testing_support.validators.validate_transaction_metrics import (
validate_transaction_metrics,
)

from newrelic.api.background_task import background_task
from newrelic.api.transaction import set_background_task

from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
from testing_support.fixture.event_loop import event_loop as loop

DB_SETTINGS = memcached_settings()[0]

MEMCACHED_HOST = DB_SETTINGS["host"]
MEMCACHED_PORT = DB_SETTINGS["port"]
MEMCACHED_NAMESPACE = str(os.getpid())
INSTANCE_METRIC_NAME = "Datastore/instance/Memcached/%s/%s" % (MEMCACHED_HOST, MEMCACHED_PORT)

_test_bt_set_get_delete_scoped_metrics = [
("Datastore/operation/Memcached/set", 1),
Expand All @@ -43,6 +42,7 @@
("Datastore/allOther", 3),
("Datastore/Memcached/all", 3),
("Datastore/Memcached/allOther", 3),
(INSTANCE_METRIC_NAME, 3),
("Datastore/operation/Memcached/set", 1),
("Datastore/operation/Memcached/get", 1),
("Datastore/operation/Memcached/delete", 1),
Expand Down Expand Up @@ -81,6 +81,7 @@ def test_bt_set_get_delete(loop):
("Datastore/allWeb", 3),
("Datastore/Memcached/all", 3),
("Datastore/Memcached/allWeb", 3),
(INSTANCE_METRIC_NAME, 3),
("Datastore/operation/Memcached/set", 1),
("Datastore/operation/Memcached/get", 1),
("Datastore/operation/Memcached/delete", 1),
Expand Down

0 comments on commit ea4039a

Please sign in to comment.