Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont throw on log push failure #43

Merged
merged 12 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-ql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:

- name: Run CodeQL
run: |
docker run --rm -v $PWD:/app composer sh -c \
docker run --rm -v $PWD:/app composer:2.6 sh -c \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required to make codeql job pass, otherwise it runs in php 8.4 and fails with phpstan version

"composer install --profile --ignore-platform-reqs && composer check"
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ jobs:

- name: Run Linter
run: |
docker run --rm -v $PWD:/app composer sh -c \
docker run --rm -v $PWD:/app composer:2.6 sh -c \
"composer install --profile --ignore-platform-reqs && composer lint"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/.idea/
.env
.phpunit.result.cache
.phpunit.result.cache
.DS_Store
56 changes: 28 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/Logger/Adapter/AppSignal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Utopia\Logger\Adapter;

use Exception;
use Utopia\Logger\Adapter;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
Expand Down Expand Up @@ -42,8 +41,6 @@ public static function getName(): string
*
* @param Log $log
* @return int
*
* @throws Exception
*/
public function push(Log $log): int
{
Expand Down Expand Up @@ -125,17 +122,22 @@ public function push(Log $log): int
\curl_setopt_array($ch, $optArray);

// execute request and get response
$result = \curl_exec($ch);
$response = \curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$error = \curl_error($ch);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$curlError = \curl_errno($ch);
\curl_close($ch);

if ($curlError !== CURLE_OK || $httpCode === 0) {
error_log("AppSignal push failed with curl error ({$curlError}): {$response}");

if ($response >= 400 || $response === 0) {
throw new Exception("Log could not be pushed with status code {$response}: {$result} ({$error})");
return 500;
}

\curl_close($ch);
if ($httpCode >= 400) {
error_log("AppSignal push failed with status code {$httpCode}: {$curlError} ({$response})");
}

return $response;
return $httpCode;
}

public function getSupportedTypes(): array
Expand Down
22 changes: 12 additions & 10 deletions src/Logger/Adapter/LogOwl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Utopia\Logger\Adapter;

use Exception;
use Utopia\Logger\Adapter;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
Expand Down Expand Up @@ -75,8 +74,6 @@ public static function getAdapterVersion(): string
*
* @param Log $log
* @return int
*
* @throws Exception
*/
public function push(Log $log): int
{
Expand Down Expand Up @@ -144,17 +141,22 @@ public function push(Log $log): int
\curl_setopt_array($ch, $optArray);

// execute request and get response
$result = curl_exec($ch);
$response = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$error = \curl_error($ch);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$curlError = \curl_errno($ch);
\curl_close($ch);

if ($curlError !== CURLE_OK || $httpCode === 0) {
error_log("LogOwl push failed with curl error ({$curlError}): {$response}");

if ($response >= 400 || $response === 0) {
throw new Exception("Log could not be pushed with status code {$response}: {$result} ({$error})");
return 500;
}

\curl_close($ch);
if ($httpCode >= 400) {
error_log("LogOwl push failed with status code {$httpCode}: {$curlError} ({$response})");
}

return $response;
return $httpCode;
}

public function getSupportedTypes(): array
Expand Down
22 changes: 12 additions & 10 deletions src/Logger/Adapter/Raygun.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Utopia\Logger\Adapter;

use Exception;
use Utopia\Logger\Adapter;
use Utopia\Logger\Log;
use Utopia\Logger\Logger;
Expand Down Expand Up @@ -42,8 +41,6 @@ public static function getName(): string
*
* @param Log $log
* @return int
*
* @throws Exception
*/
public function push(Log $log): int
{
Expand Down Expand Up @@ -110,17 +107,22 @@ public function push(Log $log): int
\curl_setopt_array($ch, $optArray);

// execute request and get response
$result = \curl_exec($ch);
$response = \curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$error = \curl_error($ch);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$curlError = \curl_errno($ch);
\curl_close($ch);

if ($curlError !== CURLE_OK || $httpCode === 0) {
error_log("Raygun push failed with curl error ({$curlError}): {$response}");

if ($response >= 400 || $response === 0) {
throw new Exception("Log could not be pushed with status code {$response}: {$result} ({$error})");
return 500;
}

\curl_close($ch);
if ($httpCode >= 400) {
error_log("Raygun push failed with status code {$httpCode}: {$curlError} ({$response})");
}

return $response;
return $httpCode;
}

public function getSupportedTypes(): array
Expand Down
21 changes: 12 additions & 9 deletions src/Logger/Adapter/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public static function getName(): string
*
* @param Log $log
* @return int
*
* @throws Exception
*/
public function push(Log $log): int
{
Expand Down Expand Up @@ -151,17 +149,22 @@ public function push(Log $log): int
\curl_setopt_array($ch, $optArray);

// execute request and get response
$result = curl_exec($ch);
$response = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$error = \curl_error($ch);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, \CURLINFO_HTTP_CODE);
$curlError = \curl_errno($ch);
\curl_close($ch);

if ($curlError !== CURLE_OK || $httpCode === 0) {
error_log("Sentry push failed with curl error ({$curlError}): {$response}");

if ($response >= 400 || $response === 0) {
throw new Exception("Log could not be pushed with status code {$response}: {$result} ({$error})");
return 500;
}

\curl_close($ch);
if ($httpCode >= 400) {
error_log("Sentry push failed with status code {$httpCode}: {$curlError} ({$response})");
}

return $response;
return $httpCode;
}

public function getSupportedTypes(): array
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/Adapter/AppSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ protected function setUp(): void
parent::setUp();
$appSignalKey = \getenv('TEST_APPSIGNAL_KEY');
$this->adapter = new AppSignal($appSignalKey ? $appSignalKey : '');
$this->invalidAdapter = new AppSignal('');
}
}
1 change: 1 addition & 0 deletions tests/e2e/Adapter/LogOwlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ protected function setUp(): void
parent::setUp();
$logOwlKey = \getenv('TEST_LOGOWL_KEY');
$this->adapter = new LogOwl($logOwlKey ? $logOwlKey : '');
$this->invalidAdapter = new LogOwl('abc', 'https://api.invalid.io/logging/');
}
}
Loading
Loading