You are here

function new_relic_rpm_init in New Relic 7

Implements hook_init().

Sets New Relic error and exceptions handler and handles transaction naming.

File

./new_relic_rpm.module, line 117
Drupal module implementing New Relic.

Code

function new_relic_rpm_init() {
  if (extension_loaded('newrelic')) {
    if (variable_get('new_relic_rpm_disable_autorum', FALSE)) {
      newrelic_disable_autorum();
    }
    if (variable_get('new_relic_rpm_override_exception_handler', FALSE)) {
      set_exception_handler('_new_relic_rpm_exception_handler');
    }
    if (variable_get('new_relic_rpm_use_menu_item_as_transaction', FALSE)) {
      $menu_item = menu_get_item();
      if (!empty($menu_item['path'])) {
        $name = $menu_item['path'];
        if (variable_get('new_relic_rpm_add_node_type_to_node_page_paths', FALSE)) {
          $parts = explode('/', $name);
          if (isset($parts[0]) && $parts[0] === 'node' && isset($parts[1]) && $parts[1] === '%') {
            $node = menu_get_object();
            if (!empty($node->type)) {
              $parts[1] .= $node->type;
              $name = implode('/', $parts);

              // Node Type
              newrelic_add_custom_parameter('type', $node->type);
            }

            // Node Op (operation)
            if (isset($parts[2])) {
              newrelic_add_custom_parameter('node_operation', check_plain($parts[2]));
            }

            // Node ID
            if (!empty($node->nid)) {
              newrelic_add_custom_parameter('nid', $node->nid);
            }

            // Revision ID
            if (!empty($node->vid)) {
              newrelic_add_custom_parameter('vid', $node->vid);
            }
          }
        }
        newrelic_name_transaction($name);
      }
    }

    // This cannot be in hook_boot because we need user_has_role().
    $ignored_roles = variable_get('new_relic_rpm_ignored_roles', array());
    if (!empty($ignored_roles)) {
      foreach ($ignored_roles as $role_id) {
        if (user_has_role($role_id)) {
          new_relic_rpm_set_job_state('ignore');
          return;
        }
      }
    }
  }
}