如何使我的“失败的请求”出现在 Application Insights 图表和分析中?
我在WordPress中有一个带有multisite的网站,在Microsoft Azure的服务器内,并使用插件Application Insights:
github:微软/ApplicationInsights-WordPress/
github:微软/ApplicationInsights-WordPress/pull/5/files
我试图添加echo
以检查是否正在调用两个“函数”之一,但我没有收到任何返回。
/**
* 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();
}
}
}
我是一名编程学生,所以我对如何调试代码知之甚少,我总是以失败告终并收到错误 500。如果你能帮助我,我非常感谢你!