mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 18:41:08 +00:00
Submit feedback using another platform
This commit is contained in:
@@ -34,10 +34,10 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Session\TokenMismatchException;
|
use Illuminate\Session\TokenMismatchException;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Validation\ValidationException as LaravelValidationException;
|
use Illuminate\Validation\ValidationException as LaravelValidationException;
|
||||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
|
||||||
use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthException;
|
use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +58,7 @@ class Handler extends ExceptionHandler
|
|||||||
OAuthServerException::class,
|
OAuthServerException::class,
|
||||||
LaravelOAuthException::class,
|
LaravelOAuthException::class,
|
||||||
TokenMismatchException::class,
|
TokenMismatchException::class,
|
||||||
HttpException::class
|
HttpException::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,6 +138,15 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function report(Throwable $e)
|
public function report(Throwable $e)
|
||||||
{
|
{
|
||||||
|
// do sentry (telemetry)
|
||||||
|
if (!(false === config('firefly.send_telemetry') || false === config('firefly.feature_flags.telemetry'))) {
|
||||||
|
if (app()->bound('sentry') && $this->shouldReport($e)) {
|
||||||
|
app('sentry')->captureException($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// do email the user (no telemetry)
|
||||||
$doMailError = config('firefly.send_error_message');
|
$doMailError = config('firefly.send_error_message');
|
||||||
if ($this->shouldntReportLocal($e) || !$doMailError) {
|
if ($this->shouldntReportLocal($e) || !$doMailError) {
|
||||||
parent::report($e);
|
parent::report($e);
|
||||||
|
@@ -38,6 +38,9 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Sentry\State\Scope;
|
||||||
|
use function Sentry\captureMessage;
|
||||||
|
use function Sentry\configureScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SubmitTelemetryData
|
* Class SubmitTelemetryData
|
||||||
@@ -78,40 +81,58 @@ class SubmitTelemetryData implements ShouldQueue
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = $this->parseJson($telemetry);
|
// submit to Sentry one by one:
|
||||||
try {
|
/** @var Telemetry $entry */
|
||||||
$body = json_encode($json, JSON_THROW_ON_ERROR);
|
foreach($telemetry as $entry) {
|
||||||
} catch (JsonException $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
Log::error('Could not parse JSON.');
|
|
||||||
throw new FireflyException(sprintf('Could not parse telemetry JSON: %s', $e->getMessage()), 0, $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client;
|
configureScope(function (Scope $scope) use ($entry): void {
|
||||||
$options = [
|
$scope->setContext('telemetry', [
|
||||||
'body' => $body,
|
'installation_id' => $entry->installation_id,
|
||||||
'headers' => [
|
'collected_at' => $entry->created_at->format('r'),
|
||||||
'Content-Type' => 'application/json',
|
'type' => $entry->type,
|
||||||
'Accept' => 'application/json',
|
'key' => $entry->key,
|
||||||
'connect_timeout' => 3.14,
|
'value' => $entry->value,
|
||||||
'User-Agent' => sprintf('FireflyIII/%s', config('firefly.version')),
|
]);
|
||||||
],
|
});
|
||||||
];
|
|
||||||
try {
|
captureMessage('Telemetry submission');
|
||||||
$result = $client->post($url, $options);
|
|
||||||
} catch (GuzzleException | Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
Log::error($e->getTraceAsString());
|
|
||||||
Log::error('Could not submit telemetry.');
|
|
||||||
throw new FireflyException(sprintf('Could not submit telemetry: %s', $e->getMessage()), 0, $e);
|
|
||||||
}
|
}
|
||||||
$body = (string)$result->getBody();
|
|
||||||
$statusCode = $result->getStatusCode();
|
|
||||||
Log::info(sprintf('Result of submission [%d]: %s', $statusCode, $body));
|
|
||||||
if (200 === $statusCode) {
|
|
||||||
// mark as submitted:
|
|
||||||
$this->markAsSubmitted($telemetry);
|
$this->markAsSubmitted($telemetry);
|
||||||
}
|
|
||||||
|
// $json = $this->parseJson($telemetry);
|
||||||
|
// try {
|
||||||
|
// $body = json_encode($json, JSON_THROW_ON_ERROR);
|
||||||
|
// } catch (JsonException $e) {
|
||||||
|
// Log::error($e->getMessage());
|
||||||
|
// Log::error('Could not parse JSON.');
|
||||||
|
// throw new FireflyException(sprintf('Could not parse telemetry JSON: %s', $e->getMessage()), 0, $e);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $client = new Client;
|
||||||
|
// $options = [
|
||||||
|
// 'body' => $body,
|
||||||
|
// 'headers' => [
|
||||||
|
// 'Content-Type' => 'application/json',
|
||||||
|
// 'Accept' => 'application/json',
|
||||||
|
// 'connect_timeout' => 3.14,
|
||||||
|
// 'User-Agent' => sprintf('FireflyIII/%s', config('firefly.version')),
|
||||||
|
// ],
|
||||||
|
// ];
|
||||||
|
// try {
|
||||||
|
// $result = $client->post($url, $options);
|
||||||
|
// } catch (GuzzleException | Exception $e) {
|
||||||
|
// Log::error($e->getMessage());
|
||||||
|
// Log::error($e->getTraceAsString());
|
||||||
|
// Log::error('Could not submit telemetry.');
|
||||||
|
// throw new FireflyException(sprintf('Could not submit telemetry: %s', $e->getMessage()), 0, $e);
|
||||||
|
// }
|
||||||
|
// $body = (string)$result->getBody();
|
||||||
|
// $statusCode = $result->getStatusCode();
|
||||||
|
// Log::info(sprintf('Result of submission [%d]: %s', $statusCode, $body));
|
||||||
|
// if (200 === $statusCode) {
|
||||||
|
// // mark as submitted:
|
||||||
|
// $this->markAsSubmitted($telemetry);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -101,6 +101,7 @@
|
|||||||
"predis/predis": "^1.1",
|
"predis/predis": "^1.1",
|
||||||
"ramsey/uuid": "^4.1",
|
"ramsey/uuid": "^4.1",
|
||||||
"rcrowe/twigbridge": "^0.12.1",
|
"rcrowe/twigbridge": "^0.12.1",
|
||||||
|
"sentry/sentry-laravel": "^2.6",
|
||||||
"spatie/data-transfer-object": "^3.1"
|
"spatie/data-transfer-object": "^3.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
1003
composer.lock
generated
1003
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user