. */ declare(strict_types=1); namespace FireflyIII\Support; use Carbon\Carbon; use FireflyIII\Support\System\GeneratesInstallationId; use Sentry\Severity; use Sentry\State\Scope; use function Sentry\captureMessage; use function Sentry\configureScope; /** * Class Telemetry */ class Telemetry { use GeneratesInstallationId; /** * Feature telemetry stores a $value for the given $feature. * Will only store the given $feature / $value combination once. * * * Examples: * - execute-cli-command [value] * - use-help-pages * - has-created-bill * - first-time-install * - more * * Its use should be limited to exotic and strange use cases in Firefly III. * Because time and date are logged as well, useful to track users' evolution in Firefly III. * * Any meta-data stored is strictly non-financial. * * @param string $key * @param string $value */ public function feature(string $key, string $value): void { if (false === config('firefly.send_telemetry') || false === config('firefly.feature_flags.telemetry')) { // hard stop if not allowed to do telemetry. // do nothing! return; } // send to Sentry. $this->generateInstallationId(); $installationId = app('fireflyconfig')->get('installation_id'); // add some context: configureScope( function (Scope $scope) use ($installationId, $key, $value): void { $scope->setContext( 'telemetry', [ 'installation_id' => $installationId->data, 'version' => config('firefly.version'), 'collected_at' => Carbon::now()->format('r'), 'key' => $key, 'value' => $value, ] ); } ); captureMessage(sprintf('FIT: %s/%s', $key, $value), Severity::info()); } }