1

How do I make my "failed requests" appear in the Application Insights charts and analysis?

Microsoft Azure | Application Insights print1

Microsoft Azure | Application Insights print2

I have a website in WordPress with multisite, inside a server in Microsoft Azure and use the plugin Application Insights:

github : Microsoft/ApplicationInsights-WordPress/

github : Microsoft/ApplicationInsights-WordPress/pull/5/files

I tried to add echo to check if one of the two 'functions' was being called, but I did not receive any return.

   /**
    *  Does server-side instrumentation using the PHP SDK for Application Insights
    */
   class Server_Instrumentation
   {
      private $_telemetryClient;

      public function __construct()
      {
          /* Necessary check for Multisite instalation */
          if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
                require_once( ABSPATH . '/wp-admin/includes/plugin.php' );

         }   
         if ( is_multisite() && is_plugin_active_for_network("application-insights/ApplicationInsightsPlugin.php") ) 
         {
                $application_insights_options = get_site_option("applicationinsights_options");
         } else {
                $application_insights_options = get_option("applicationinsights_options");
         } 
         $this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
         $this->_telemetryClient->getContext()->setInstrumentationKey($application_insights_options["instrumentation_key"]);
         $key = $application_insights_options["instrumentation_key"];
         if (version_compare(phpversion(), '7.0.0', '>=')) {
               // PHP Version maior que 
                set_exception_handler(array($this, 'throwableHandler'));
         } else
         {
                set_exception_handler(array($this, 'exceptionHandler'));

        //ativo
         }   
   }

   function endRequest()
   {
      if (is_page() || is_single() || is_category() || is_home() || is_archive())
      {
         $url = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
         $requestName = $this->getRequestName();
         $startTime = $_SERVER["REQUEST_TIME"];
         $duration = timer_stop(0, 3) * 1000;
         $this->_telemetryClient->trackRequest($requestName, $url, $startTime, $duration);

               // Flush all telemetry items
         $this->_telemetryClient->flush(); 
   }
   }

   function getRequestName()
   {
      if (is_home() == false)
      {
         return get_the_title();
   }
   else
   {
         return 'Home';
   }
   }

   function exceptionHandler(\Exception $exception)
   {
      echo ('throwableHandler load');
      if ($exception != NULL)
      {
         $this->_telemetryClient->trackException($exception);
         $this->_telemetryClient->flush();
   }
   }
   function throwableHandler(\Throwable $exception)
   {
      echo ('throwableHandler load');

      if ($exception != NULL)
      {
         $this->_telemetryClient->trackThrowable($exception);
         $this->_telemetryClient->flush();

   }
   }
   }

I am a programming student so I do not have much knowledge of how I can debug the code, I always end up breaking and I get error 500. If you can help me I thank you very much!

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
Kaue Alves
  • 123
  • 5
  • For debug the PHP code, I would recommend checking out this thread: [How to debug PHP in MS Azure](https://stackoverflow.com/questions/33241711/how-to-debug-php-in-ms-azure/33276962#33276962). – Aaron Chen Jun 23 '17 at 09:57

0 Answers0