Skip to content

Commit

Permalink
Capture pymemcache host & port
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek committed Aug 16, 2024
1 parent 70e98a5 commit 8bdf533
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion newrelic/hooks/datastore_pymemcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@
)


def capture_host(self, *args, **kwargs):
if hasattr(self, "server") and self.server and len(self.server) >= 2:
return self.server[0]


def capture_port(self, *args, **kwargs):
if hasattr(self, "server") and self.server and len(self.server) >= 2:
return self.server[1]


def instrument_pymemcache_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,
)
4 changes: 2 additions & 2 deletions tests/datastore_pymemcache/test_memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import pymemcache.client
from testing_support.db_settings import memcached_settings
from testing_support.validators.validate_transaction_metrics import (
Expand Down Expand Up @@ -45,6 +43,7 @@
("Datastore/operation/Memcached/set", 1),
("Datastore/operation/Memcached/get", 1),
("Datastore/operation/Memcached/delete", 1),
("Datastore/instance/Memcached/%s/%s" % (MEMCACHED_HOST, MEMCACHED_PORT), 3),
]


Expand Down Expand Up @@ -82,6 +81,7 @@ def test_bt_set_get_delete():
("Datastore/operation/Memcached/set", 1),
("Datastore/operation/Memcached/get", 1),
("Datastore/operation/Memcached/delete", 1),
("Datastore/instance/Memcached/%s/%s" % (MEMCACHED_HOST, MEMCACHED_PORT), 3),
]


Expand Down

0 comments on commit 8bdf533

Please sign in to comment.