mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Tighten span logging validation
This commit is contained in:
+9
-1
@@ -22,7 +22,15 @@ $addSentryExporter = function (string $loggingConfig, ?callable $sampler = null)
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Logging provider not supported. Logging is disabled');
|
||||
}
|
||||
|
||||
$dsn = 'https://' . $loggingProvider->getPassword() . '@' . $loggingProvider->getHost() . '/' . ($loggingProvider->getUser() ?? '');
|
||||
$projectId = $loggingProvider->getUser();
|
||||
$apiKey = $loggingProvider->getPassword();
|
||||
$host = $loggingProvider->getHost();
|
||||
|
||||
if (empty($projectId) || empty($apiKey) || empty($host)) {
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Invalid Sentry DSN. Logging is disabled');
|
||||
}
|
||||
|
||||
$dsn = 'https://' . $apiKey . '@' . $host . '/' . $projectId;
|
||||
|
||||
Span::addExporter(
|
||||
new Exporter\Sentry(
|
||||
|
||||
@@ -40,4 +40,57 @@ class SpanTest extends TestCase
|
||||
$this->assertSame('worker.error', $exporter->exported[0]->getAction());
|
||||
$this->assertSame($error, $exporter->exported[0]->getError());
|
||||
}
|
||||
|
||||
public function testSamplerSkipsUnmatchedSpan(): void
|
||||
{
|
||||
$exporter = new class () implements Exporter {
|
||||
/**
|
||||
* @var array<Span>
|
||||
*/
|
||||
public array $exported = [];
|
||||
|
||||
public function export(Span $span): void
|
||||
{
|
||||
$this->exported[] = $span;
|
||||
}
|
||||
};
|
||||
|
||||
Span::addExporter(
|
||||
exporter: $exporter,
|
||||
sampler: fn (Span $span): bool => $span->get('appwrite.error.publish') === true,
|
||||
);
|
||||
|
||||
$span = new Span('worker.error');
|
||||
$span->set('appwrite.error.publish', false);
|
||||
$span->finish();
|
||||
|
||||
$this->assertCount(0, $exporter->exported);
|
||||
}
|
||||
|
||||
public function testSamplerExportsMatchedSpan(): void
|
||||
{
|
||||
$exporter = new class () implements Exporter {
|
||||
/**
|
||||
* @var array<Span>
|
||||
*/
|
||||
public array $exported = [];
|
||||
|
||||
public function export(Span $span): void
|
||||
{
|
||||
$this->exported[] = $span;
|
||||
}
|
||||
};
|
||||
|
||||
Span::addExporter(
|
||||
exporter: $exporter,
|
||||
sampler: fn (Span $span): bool => $span->get('appwrite.error.publish') === true,
|
||||
);
|
||||
|
||||
$span = new Span('worker.error');
|
||||
$span->set('appwrite.error.publish', true);
|
||||
$span->finish();
|
||||
|
||||
$this->assertCount(1, $exporter->exported);
|
||||
$this->assertSame('worker.error', $exporter->exported[0]->getAction());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user