From de4d374c01fddd503ff235d52d746d02314e096a Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Sat, 21 Mar 2026 15:25:22 +0530 Subject: [PATCH] Add telemetry for custom SMTP validation --- app/controllers/api/projects.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 2fc20ba83f..e97c2a914b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -32,6 +32,7 @@ use Utopia\Emails\Validator\Email; use Utopia\Http\Http; use Utopia\Locale\Locale; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; use Utopia\Validator\Hostname; @@ -1409,7 +1410,8 @@ Http::patch('/v1/projects/:projectId/smtp') ->param('secure', '', new WhiteList(['tls', 'ssl'], true), 'Does SMTP server use secure connection', true) ->inject('response') ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, string $senderName, string $senderEmail, string $replyTo, string $host, int $port, string $username, string $password, string $secure, Response $response, Database $dbForPlatform) { + ->inject('telemetry') + ->action(function (string $projectId, bool $enabled, string $senderName, string $senderEmail, string $replyTo, string $host, int $port, string $username, string $password, string $secure, Response $response, Database $dbForPlatform, Telemetry $telemetry) { $project = $dbForPlatform->getDocument('projects', $projectId); @@ -1443,6 +1445,8 @@ Http::patch('/v1/projects/:projectId/smtp') $mail->SMTPAutoTLS = false; $mail->Timeout = 5; + $validationStartTime = microtime(true); + $smtpVerificationDuration = $telemetry->createHistogram('project.smtp.validation.duration', 's'); try { $valid = $mail->SmtpConnect(); @@ -1451,6 +1455,9 @@ Http::patch('/v1/projects/:projectId/smtp') } } catch (Throwable $error) { throw new Exception(Exception::PROJECT_SMTP_CONFIG_INVALID, $error->getMessage()); + } finally { + $duration = microtime(true) - $validationStartTime; + $smtpVerificationDuration->record($duration, ['projectId' => $projectId]); } }