我正在使用自托管 Sentry 来监控我的 wordpress 网站。我在我的哨兵主机面板中收到错误和异常日志并监控问题,但我没有收到任何性能报告。
我在 index.php 的末尾添加了这个片段代码,但没有用。
\Sentry\init([
'dsn' => 'SENTRY_DSN',
'traces_sampler' => static function (\Sentry\Tracing\SamplingContext $context): float {
if (false !== strpos($context->getTransactionContext()->getName(), 'health')) {
// Discard transactions that have 'health' in their name
return 0.0;
}
// Sample rate for all other transactions
return 1.0;
},
]);
谁能帮我配置 wordpress 以在哨兵中使用性能监控?
答案 0 :(得分:0)
由于 Wordpress 的触发顺序,您应该将其添加为 mu 插件:https://codex.wordpress.org/Plugin_API/Action_Reference
通过将 wp-sentry 插件与自定义 mu 插件集成,我设法实现了一些功能。在此处查看我的答案,随着时间的推移可能会变得更好:https://github.com/stayallive/wp-sentry/issues/68
安装 wp-sentry 插件并将其添加到 /wp-content/mu-plugins 中的文件中。确保之前删除 wp-sentry 的 mu-plugin。
awk ' ##Starting awk program from here.
(FNR==1 || FNR==2 || FNR==3 ){ ##Checking condition if line is 1 2 or 3 here.
if(++count<=3){ print } ##If count is lesser or equals to 3 then print it.
next ##next will skip all further statements from here.
}
FNR==NR{ ##Checking condition which will be TRUE when 1st time Input_file is being read.
arr[$1,$3]++ ##Creating arr with index of $1,$3 and keep increasing its value by 1 here.
next ##next will skip all further statements from here.
}
arr[$1,$3]>1 && $0!~/^#/ && $3=="CANON"{ ##Checking condition if arr with 1st,3rd field value is greater than 1 AND line not starting with # AND 3rd column is CANON then do following.
$3="CANON_DUPL" ##Set 3rd field to CANON_DUPL here.
}
1 ##printing current line here.
' Input_file Input_file ##Mentioning Input_file names here.
添加后,请确保在 wp-config.php 中定义 WP_SENTRY_TRACES_SAMPLE_RATE 的值介于 0 和 1 之间。0,3 用于生产是个好主意。