From 69aa59a1d65f3582e28c1075c8e17079e14d94ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 27 Feb 2023 11:24:21 +0100 Subject: [PATCH] Add more log details to execution --- app/config/collections.php | 33 +++++++++++++++++++++++++++++++ app/controllers/api/functions.php | 10 ++++++++++ app/workers/functions.php | 10 ++++++++++ 3 files changed, 53 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index 3d9433fb11..1a510b20ae 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2920,6 +2920,39 @@ $collections = [ 'default' => null, 'filters' => [], ], + [ + 'array' => false, + '$id' => ID::custom('method'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 128, + 'signed' => true, + 'required' => false, + 'default' => null, + 'filters' => [], + ], + [ + 'array' => false, + '$id' => ID::custom('path'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'default' => null, + 'filters' => [], + ], + [ + 'array' => false, + '$id' => ID::custom('agent'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'default' => null, + 'filters' => [], + ], [ '$id' => ID::custom('status'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ffa112f795..5480dd4021 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1170,6 +1170,13 @@ App::post('/v1/functions/:functionId/executions') $executionId = ID::unique(); + $agent = ''; + foreach ($headers as $header => $value) { + if(\strtolower($header) === 'user-agent') { + $agent = $value; + } + } + $execution = new Document([ '$id' => $executionId, '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], @@ -1184,6 +1191,9 @@ App::post('/v1/functions/:functionId/executions') 'logs' => '', 'duration' => 0.0, 'search' => implode(' ', [$functionId, $executionId]), + 'path' => $path, + 'method' => $method, + 'agent' => $agent ]); if($function->getAttribute('logging')) { diff --git a/app/workers/functions.php b/app/workers/functions.php index 02e109a1dc..ae9fcab757 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -80,6 +80,13 @@ Server::setResource('execute', function () { /** Create execution or update execution status */ $execution = $dbForProject->getDocument('executions', $executionId ?? ''); if ($execution->isEmpty()) { + $agent = ''; + foreach ($headers as $header => $value) { + if(\strtolower($header) === 'user-agent') { + $agent = $value; + } + } + $executionId = ID::unique(); $execution = new Document([ '$id' => $executionId, @@ -93,6 +100,9 @@ Server::setResource('execute', function () { 'logs' => '', 'duration' => 0.0, 'search' => implode(' ', [$functionId, $executionId]), + 'path' => $path, + 'method' => $method, + 'agent' => $agent ]); if($function->getAttribute('logging')) {