dongshu4755 2017-06-22 20:27
浏览 56

如何在Application Insights图表和分析中显示“失败的请求”?

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度