Skip to content

Beautiful Open-Source Form Builder

Add telemetry metrics collection and event tracking

JhumanJ57dfb92371e3
diff --git a/api/app/Console/Commands/SendTelemetryPing.php b/api/app/Console/Commands/SendTelemetryPing.php
index 23fd62635..6cde76bf9 100644
--- a/api/app/Console/Commands/SendTelemetryPing.php
+++ b/api/app/Console/Commands/SendTelemetryPing.php
@@ -2,6 +2,10 @@
namespace App\Console\Commands;
+use App\Models\User;
+use App\Models\Workspace;
+use App\Models\Forms\Form;
+use App\Models\Forms\FormSubmission;
use App\Service\Telemetry\TelemetryEvent;
use App\Service\Telemetry\TelemetryService;
use Illuminate\Console\Command;
@@ -49,11 +53,36 @@ class SendTelemetryPing extends Command
return Command::SUCCESS;
}
- // Send ping event
- telemetry(TelemetryEvent::INSTANCE_PING);
+ // Collect metrics
+ $properties = $this->collectMetrics();
+
+ // Update instance identification with latest metrics and send ping event
+ $client = $telemetryService->createClient();
+ $version = $telemetryService->getAppVersion();
+ $client->identifyInstance($instanceId, $version, $properties);
+
+ // Send ping event directly using the client (without properties - identification already updated)
+ $client->sendEvent(TelemetryEvent::INSTANCE_PING->value(), [], $instanceId);
$this->info('Telemetry ping sent successfully');
return Command::SUCCESS;
}
+
+ /**
+ * Collect telemetry metrics.
+ *
+ * @return array
+ */
+ protected function collectMetrics(): array
+ {
+ $properties = [];
+
+ $properties['users_count'] = User::count();
+ $properties['workspaces_count'] = Workspace::count();
+ $properties['forms_count'] = Form::count();
+ $properties['submissions_count'] = FormSubmission::count();
+
+ return $properties;
+ }
}
diff --git a/api/app/Http/Controllers/Settings/OidcConnectionController.php b/api/app/Http/Controllers/Settings/OidcConnectionController.php
index fd7253ba9..3aff663b0 100644
--- a/api/app/Http/Controllers/Settings/OidcConnectionController.php
+++ b/api/app/Http/Controllers/Settings/OidcConnectionController.php
@@ -7,6 +7,7 @@ use App\Enterprise\Oidc\Requests\StoreOidcConnectionRequest;
use App\Enterprise\Oidc\Requests\UpdateOidcConnectionRequest;
use App\Http\Controllers\Controller;
use App\Models\Workspace;
+use App\Service\Telemetry\TelemetryEvent;
class OidcConnectionController extends Controller
{
@@ -58,6 +59,8 @@ class OidcConnectionController extends Controller
}
$connection = IdentityConnection::create($data);
+
+ telemetry(TelemetryEvent::SSO_CREATED);
return response()->json($this->formatConnection($connection), 201);
}
diff --git a/api/app/Http/Controllers/Settings/TwoFactorController.php b/api/app/Http/Controllers/Settings/TwoFactorController.php
index 6d6c38b51..8c4578228 100644
--- a/api/app/Http/Controllers/Settings/TwoFactorController.php
+++ b/api/app/Http/Controllers/Settings/TwoFactorController.php
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Settings;
use App\Http\Controllers\Controller;
+use App\Service\Telemetry\TelemetryEvent;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;
@@ -58,6 +59,8 @@ class TwoFactorController extends Controller
]);
}
+ telemetry(TelemetryEvent::TWO_FACTOR_ENABLED);
+
return response()->json([
'message' => 'Two-factor authentication has been enabled successfully.',
'recovery_codes' => $user->getRecoveryCodes()->toArray(),
diff --git a/api/app/Service/Telemetry/TelemetryEvent.php b/api/app/Service/Telemetry/TelemetryEvent.php
index 78120df49..14238ef78 100644
--- a/api/app/Service/Telemetry/TelemetryEvent.php
+++ b/api/app/Service/Telemetry/TelemetryEvent.php
@@ -10,6 +10,8 @@ enum TelemetryEvent: string
case FORM_CREATED = 'form.created';
case WORKSPACE_CREATED = 'workspace.created';
case FORM_SUBMISSION = 'form.submission';
+ case TWO_FACTOR_ENABLED = 'two_factor.enabled';
+ case SSO_CREATED = 'sso.created';
public function value(): string
{