mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Pass logging DSN directly
This commit is contained in:
@@ -279,7 +279,7 @@ return [
|
||||
],
|
||||
[
|
||||
'name' => '_APP_LOGGING_CONFIG',
|
||||
'description' => 'This variable enables error logging using a provider DSN. This value is empty by default. Currently, Appwrite supports Sentry DSNs using the format `sentry://PROJECT_ID:SENTRY_API_KEY@SENTRY_HOST/`.',
|
||||
'description' => 'This variable enables error logging using a provider DSN. This value is empty by default. Currently, Appwrite supports Sentry DSNs using the format `https://SENTRY_PUBLIC_KEY@SENTRY_HOST/PROJECT_ID`.',
|
||||
'introduction' => '0.12.0',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
@@ -288,7 +288,7 @@ return [
|
||||
],
|
||||
[
|
||||
'name' => '_APP_EXPERIMENT_LOGGING_CONFIG',
|
||||
'description' => 'This variable enables experimental error logging using a provider DSN. This value is empty by default. Currently, Appwrite supports Sentry DSNs using the format `sentry://PROJECT_ID:SENTRY_API_KEY@SENTRY_HOST/?sample=0.01`.',
|
||||
'description' => 'This variable enables experimental error logging using a provider DSN. This value is empty by default. Currently, Appwrite supports Sentry DSNs using the format `https://SENTRY_PUBLIC_KEY@SENTRY_HOST/PROJECT_ID?sample=0.01`.',
|
||||
'introduction' => '1.9.0',
|
||||
'default' => '',
|
||||
'required' => false,
|
||||
|
||||
+1
-32
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Utopia\Console;
|
||||
use Utopia\DSN\DSN;
|
||||
use Utopia\Span\Exporter;
|
||||
@@ -12,42 +11,12 @@ use Utopia\System\System;
|
||||
Span::setStorage(new Storage\Coroutine());
|
||||
|
||||
$loggingConfig = System::getEnv('_APP_LOGGING_CONFIG', '');
|
||||
$legacyRealtimeLoggingConfig = System::getEnv('_APP_LOGGING_CONFIG_REALTIME', '');
|
||||
|
||||
if (!empty($legacyRealtimeLoggingConfig)) {
|
||||
Console::warning('_APP_LOGGING_CONFIG_REALTIME is no longer supported. Realtime errors use _APP_LOGGING_CONFIG.');
|
||||
}
|
||||
|
||||
if (!empty($loggingConfig) && \str_contains($loggingConfig, ';')) {
|
||||
Console::warning('Legacy semicolon-delimited _APP_LOGGING_CONFIG values are no longer supported. Set _APP_LOGGING_CONFIG to a provider DSN.');
|
||||
}
|
||||
|
||||
$addSentryExporter = function (string $loggingConfig, ?callable $sampler = null): void {
|
||||
try {
|
||||
$loggingProvider = new DSN($loggingConfig);
|
||||
$providerName = $loggingProvider->getScheme();
|
||||
|
||||
if ($providerName !== 'sentry') {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Logging provider not supported. Logging is disabled');
|
||||
}
|
||||
|
||||
$projectId = $loggingProvider->getUser();
|
||||
$apiKey = $loggingProvider->getPassword();
|
||||
$host = $loggingProvider->getHost();
|
||||
$port = $loggingProvider->getPort();
|
||||
$path = $loggingProvider->getPath();
|
||||
|
||||
if (empty($projectId) || empty($apiKey) || empty($host)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Invalid Sentry DSN. Logging is disabled');
|
||||
}
|
||||
|
||||
$host = $host . (empty($port) ? '' : ':' . $port);
|
||||
$path = empty($path) ? '' : \trim($path, '/') . '/';
|
||||
$dsn = 'https://' . $apiKey . '@' . $host . '/' . $path . $projectId;
|
||||
|
||||
Span::addExporter(
|
||||
new Exporter\Sentry(
|
||||
dsn: $dsn,
|
||||
dsn: $loggingConfig,
|
||||
environment: System::getEnv('_APP_ENV', 'development') === 'production' ? 'production' : 'staging',
|
||||
release: System::getEnv('_APP_VERSION', 'UNKNOWN'),
|
||||
serverName: System::getEnv('_APP_LOGGING_SERVICE_IDENTIFIER', \gethostname()),
|
||||
|
||||
@@ -131,10 +131,10 @@ class Doctor extends Action
|
||||
|
||||
$providerName = $loggingProvider->getScheme();
|
||||
|
||||
if ($providerName !== 'sentry') {
|
||||
if (!\in_array($providerName, ['http', 'https'])) {
|
||||
Console::log('🔴 Logging adapter is unsupported (' . $providerName . ')');
|
||||
} else {
|
||||
Console::log('🟢 Logging adapter is enabled (' . $providerName . ')');
|
||||
Console::log('🟢 Logging adapter is enabled (sentry)');
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
Console::log('🔴 Logging adapter is misconfigured');
|
||||
|
||||
Reference in New Issue
Block a user