You are here

class ExceptionSubscriber in New Relic 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/ExceptionSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\ExceptionSubscriber
  2. 2.0.x src/EventSubscriber/ExceptionSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\ExceptionSubscriber

Provides a way to send Exceptions to the New Relic API.

Hierarchy

  • class \Drupal\new_relic_rpm\EventSubscriber\ExceptionSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ExceptionSubscriber

1 string reference to 'ExceptionSubscriber'
new_relic_rpm.services.yml in ./new_relic_rpm.services.yml
new_relic_rpm.services.yml
1 service uses ExceptionSubscriber
new_relic_rpm.exception_subscriber in ./new_relic_rpm.services.yml
Drupal\new_relic_rpm\EventSubscriber\ExceptionSubscriber

File

src/EventSubscriber/ExceptionSubscriber.php, line 14

Namespace

Drupal\new_relic_rpm\EventSubscriber
View source
class ExceptionSubscriber implements EventSubscriberInterface {

  /**
   * New Relic adapter.
   *
   * @var \Drupal\new_relic_rpm\ExtensionAdapter\NewRelicAdapterInterface
   */
  protected $adapter;

  /**
   * Constructs a subscriber.
   *
   * @param \Drupal\new_relic_rpm\ExtensionAdapter\NewRelicAdapterInterface $adapter
   *   The Adapter to use when talking to the New Relic extension.
   */
  public function __construct(NewRelicAdapterInterface $adapter) {
    $this->adapter = $adapter;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Ensure this runs just before FinalExceptionSubscriber.
    $events[KernelEvents::EXCEPTION][] = [
      'onException',
      -255,
    ];
    return $events;
  }

  /**
   * Handles errors for this subscriber.
   *
   * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
   *   The event to process.
   */
  public function onException(GetResponseForExceptionEvent $event) {

    // Don't log http exceptions.
    if ($event
      ->getException() instanceof HttpExceptionInterface) {
      return;
    }
    if (\Drupal::config('new_relic_rpm.settings')
      ->get('override_exception_handler')) {

      // Forward the exception to New Relic.
      $this->adapter
        ->logException($event
        ->getException());
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExceptionSubscriber::$adapter protected property New Relic adapter.
ExceptionSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ExceptionSubscriber::onException public function Handles errors for this subscriber.
ExceptionSubscriber::__construct public function Constructs a subscriber.