samuelnogueira/cache-datastore-newrelic

Reports calls to any psr/simple-cache or psr/cache implementation as a custom New Relic Datastore

1.1.0 2024-04-03 20:38 UTC

This package is auto-updated.

Last update: 2024-11-05 09:32:36 UTC


README

Latest Stable Version PHP Version Require

Report calls to any psr/simple-cache or psr/cache implementation as a custom New Relic Datastore.

Uses the newrelic_record_datastore_segment function to record calls to an unsupported database.

Requirements

Requires New Relic PHP Agent version >= 7.5.0.

Usage

Decorate your existing:

  1. \Psr\Cache\CacheItemPoolInterface
  2. \Psr\SimpleCache\CacheInterface

with respectively:

  1. \Samuelnogueira\CacheDatastoreNewrelic\CacheItemPoolDecorator
  2. \Samuelnogueira\CacheDatastoreNewrelic\SimpleCacheDecorator

Example with PSR-6: Caching Interface:

use Psr\Cache\CacheItemPoolInterface;
use Samuelnogueira\CacheDatastoreNewrelic\CacheItemPoolDecorator;
use Samuelnogueira\CacheDatastoreNewrelic\DatastoreParams;

/** @var CacheItemPoolInterface $cache */

return new CacheItemPoolDecorator(
    $cache, // your cache adapter
    new DatastoreParams('My Database Product'),
);

Example with PSR-16: Common Interface for Caching Libraries (aka Simple Cache):

use Psr\SimpleCache\CacheInterface;
use Samuelnogueira\CacheDatastoreNewrelic\SimpleCacheDecorator;
use Samuelnogueira\CacheDatastoreNewrelic\DatastoreParams;

/** @var CacheInterface $cache */

return new SimpleCacheDecorator(
    $cache, // your cache adapter
    new DatastoreParams('My Database Product'),
);