summaryrefslogtreecommitdiff
path: root/backend.php
diff options
context:
space:
mode:
Diffstat (limited to 'backend.php')
-rw-r--r--backend.php46
1 files changed, 43 insertions, 3 deletions
diff --git a/backend.php b/backend.php
index e246ea088..c322e1e55 100644
--- a/backend.php
+++ b/backend.php
@@ -30,11 +30,16 @@
$op = (string)clean($op);
$method = (string)clean($method);
+ $scope = Tracer::start(__FILE__, ['tags' => json_encode($_REQUEST)]);
+
startup_gettext();
$script_started = microtime(true);
- if (!init_plugins()) return;
+ if (!init_plugins()) {
+ $scope->close();
+ return;
+ }
header("Content-Type: text/json; charset=utf-8");
@@ -46,6 +51,9 @@
if (!\Sessions\validate_session()) {
header("Content-Type: text/json");
print Errors::to_json(Errors::E_UNAUTHORIZED);
+
+ $scope->getSpan()->setTag('error', Errors::E_UNAUTHORIZED);
+ $scope->close();
return;
}
UserHelper::load_user_plugins($_SESSION["uid"]);
@@ -53,6 +61,9 @@
if (Config::is_migration_needed()) {
print Errors::to_json(Errors::E_SCHEMA_MISMATCH);
+
+ $scope->getSpan()->setTag('error', Errors::E_SCHEMA_MISMATCH);
+ $scope->close();
return;
}
@@ -114,10 +125,14 @@
user_error("Refusing to invoke method $method of handler $op which starts with underscore.", E_USER_WARNING);
header("Content-Type: text/json");
print Errors::to_json(Errors::E_UNAUTHORIZED);
+
+ $scope->getSpan()->setTag('error', Errors::E_UNAUTHORIZED);
+ $scope->close();
return;
}
if ($override) {
+ /** @var Plugin|IHandler|ICatchall $handler */
$handler = $override;
} else {
$reflection = new ReflectionClass($op);
@@ -125,10 +140,18 @@
}
if (implements_interface($handler, 'IHandler')) {
+ $h_scope = Tracer::start("construct/$op");
$handler->__construct($_REQUEST);
+ $h_scope->close();
if (validate_csrf($csrf_token) || $handler->csrf_ignore($method)) {
- if ($handler->before($method)) {
+
+ $b_scope = Tracer::start("before/$method");
+ $before = $handler->before($method);
+ $b_scope->close();
+
+ if ($before) {
+ $m_scope = Tracer::start("method/$method");
if ($method && method_exists($handler, $method)) {
$reflection = new ReflectionMethod($handler, $method);
@@ -137,6 +160,8 @@
} else {
user_error("Refusing to invoke method $method of handler $op which has required parameters.", E_USER_WARNING);
header("Content-Type: text/json");
+
+ $m_scope->getSpan()->setTag('error', Errors::E_UNAUTHORIZED);
print Errors::to_json(Errors::E_UNAUTHORIZED);
}
} else {
@@ -144,20 +169,34 @@
$handler->catchall($method);
} else {
header("Content-Type: text/json");
+
+ $m_scope->getSpan()->setTag('error', Errors::E_UNKNOWN_METHOD);
print Errors::to_json(Errors::E_UNKNOWN_METHOD, ["info" => get_class($handler) . "->$method"]);
}
}
+ $m_scope->close();
+
+ $a_scope = Tracer::start("after/$method");
$handler->after();
+ $a_scope->close();
+
+ $scope->close();
return;
} else {
header("Content-Type: text/json");
print Errors::to_json(Errors::E_UNAUTHORIZED);
+
+ $scope->getSpan()->setTag('error', Errors::E_UNAUTHORIZED);
+ $scope->close();
return;
}
} else {
user_error("Refusing to invoke method $method of handler $op with invalid CSRF token.", E_USER_WARNING);
header("Content-Type: text/json");
print Errors::to_json(Errors::E_UNAUTHORIZED);
+
+ $scope->getSpan()->setTag('error', Errors::E_UNAUTHORIZED);
+ $scope->close();
return;
}
}
@@ -166,4 +205,5 @@
header("Content-Type: text/json");
print Errors::to_json(Errors::E_UNKNOWN_METHOD, [ "info" => (isset($handler) ? get_class($handler) : "UNKNOWN:".$op) . "->$method"]);
-?>
+ $scope->getSpan()->setTag('error', Errors::E_UNKNOWN_METHOD);
+ $scope->close();