Skip to content

Commit

Permalink
Merge pull request #33 from open-runtimes/fix-logger-backwards-compat…
Browse files Browse the repository at this point in the history
…ibility

Fix: Backwards compatible logger
  • Loading branch information
Meldiron authored Sep 20, 2024
2 parents 1c281f3 + cc683dd commit 4de447d
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 75 deletions.
34 changes: 29 additions & 5 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Utopia\Balancer\Group;
use Utopia\Balancer\Option;
use Utopia\CLI\Console;
use Utopia\DSN\DSN;
use Utopia\Fetch\Client;
use Utopia\Http\Adapter\Swoole\Server;
use Utopia\Http\Http;
Expand Down Expand Up @@ -57,17 +58,40 @@
return $state;
});

/**
* Create logger for cloud logging
*/
$register->set('logger', function () {
$providerName = Http::getEnv('OPR_PROXY_LOGGING_PROVIDER', '');
$providerConfig = Http::getEnv('OPR_PROXY_LOGGING_CONFIG', '');

try {
$loggingProvider = new DSN($providerConfig ?? '');

$providerName = $loggingProvider->getScheme();
$providerConfig = match ($providerName) {
'sentry' => ['key' => $loggingProvider->getPassword(), 'projectId' => $loggingProvider->getUser() ?? '', 'host' => 'https://' . $loggingProvider->getHost()],
'logowl' => ['ticket' => $loggingProvider->getUser() ?? '', 'host' => $loggingProvider->getHost()],
default => ['key' => $loggingProvider->getHost()],
};
} catch (Throwable) {
$configChunks = \explode(";", ($providerConfig ?? ''));

$providerConfig = match ($providerName) {
'sentry' => ['key' => $configChunks[0], 'projectId' => $configChunks[1] ?? '', 'host' => '',],
'logowl' => ['ticket' => $configChunks[0] ?? '', 'host' => ''],
default => ['key' => $providerConfig],
};
}

$logger = null;

if (!empty($providerName) && !empty($providerConfig) && Logger::hasProvider($providerName)) {
if (!empty($providerName) && is_array($providerConfig) && Logger::hasProvider($providerName)) {
$adapter = match ($providerName) {
'sentry' => new Sentry($providerConfig),
'raygun' => new Raygun($providerConfig),
'logowl' => new LogOwl($providerConfig),
'appsignal' => new AppSignal($providerConfig),
'sentry' => new Sentry($providerConfig['projectId'] ?? '', $providerConfig['key'] ?? '', $providerConfig['host'] ?? ''),
'logowl' => new LogOwl($providerConfig['ticket'] ?? '', $providerConfig['host'] ?? ''),
'raygun' => new Raygun($providerConfig['key'] ?? ''),
'appsignal' => new AppSignal($providerConfig['key'] ?? ''),
default => throw new Exception('Provider "' . $providerName . '" not supported.')
};

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"utopia-php/framework": "0.34.*",
"utopia-php/registry": "0.6.*",
"utopia-php/cli": "0.13.*",
"utopia-php/logger": "0.5.*",
"utopia-php/logger": "0.6.*",
"utopia-php/balancer": "0.4.*",
"utopia-php/fetch": "^0.1.0"
"utopia-php/fetch": "^0.1.0",
"utopia-php/dsn": "0.1.*"
},
"require-dev": {
"swoole/ide-helper": "4.8.5",
Expand Down
Loading

0 comments on commit 4de447d

Please sign in to comment.