Skip to content

Commit

Permalink
static logging methods
Browse files Browse the repository at this point in the history
allow logging methods in LogsMessagesTrait to be called from within either a static or non-static method.
in passing, adding a missing coversNothing annotation on a complaining integration test
  • Loading branch information
brettmc committed Apr 2, 2022
1 parent 5f71d3c commit 93c0bf0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Contrib/Jaeger/JaegerTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function flush($force = false): int
// reset the process tag
$this->process = null;
} catch (TTransportException $e) {
$this->logError('jaeger: transport failure: ' . $e->getMessage());
self::logError('jaeger: transport failure: ' . $e->getMessage());

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Contrib/OtlpGrpc/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ protected function doExport(iterable $spans): int
\Grpc\STATUS_DATA_LOSS,
\Grpc\STATUS_UNAUTHENTICATED,
], true)) {
$this->logWarning('Retryable error exporting grpc span', ['error' => $error]);
self::logWarning('Retryable error exporting grpc span', ['error' => $error]);

return self::STATUS_FAILED_RETRYABLE;
}

$this->logError('Error exporting grpc span', ['error' => $error]);
self::logError('Error exporting grpc span', ['error' => $error]);

return self::STATUS_FAILED_NOT_RETRYABLE;
}
Expand Down
24 changes: 12 additions & 12 deletions src/SDK/Behavior/LogsMessagesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@

trait LogsMessagesTrait
{
private function doLog(string $level, string $message, array $context): void
private static function doLog(string $level, string $message, array $context): void
{
$context['source'] = get_class($this);
$context['source'] = get_called_class();
LoggerHolder::get()->log($level, $message, $context);
}

protected function logDebug(string $message, array $context = []): void
protected static function logDebug(string $message, array $context = []): void
{
$this->doLog(LogLevel::DEBUG, $message, $context);
self::doLog(LogLevel::DEBUG, $message, $context);
}

protected function logInfo(string $message, array $context = []): void
protected static function logInfo(string $message, array $context = []): void
{
$this->doLog(LogLevel::INFO, $message, $context);
self::doLog(LogLevel::INFO, $message, $context);
}

protected function logNotice(string $message, array $context = []): void
protected static function logNotice(string $message, array $context = []): void
{
$this->doLog(LogLevel::NOTICE, $message, $context);
self::doLog(LogLevel::NOTICE, $message, $context);
}

protected function logWarning(string $message, array $context = []): void
protected static function logWarning(string $message, array $context = []): void
{
$this->doLog(LogLevel::WARNING, $message, $context);
self::doLog(LogLevel::WARNING, $message, $context);
}

protected function logError(string $message, array $context = []): void
protected static function logError(string $message, array $context = []): void
{
$this->doLog(LogLevel::ERROR, $message, $context);
self::doLog(LogLevel::ERROR, $message, $context);
}
}
2 changes: 1 addition & 1 deletion src/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function shutdown(): bool
}

$this->running = false;
$this->logDebug('Shutting down span processor');
self::logDebug('Shutting down span processor');

if (null !== $this->exporter) {
return $this->forceFlush() && $this->exporter->shutdown();
Expand Down
6 changes: 3 additions & 3 deletions src/SDK/Trace/TracerProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ public function create(): API\TracerProviderInterface
try {
$exporter = $this->exporterFactory->fromEnvironment();
} catch (\Throwable $t) {
$this->logWarning('Unable to create exporter', ['error' => $t]);
self::logWarning('Unable to create exporter', ['error' => $t]);
$exporter = null;
}

try {
$sampler = $this->samplerFactory->fromEnvironment();
} catch (\Throwable $t) {
$this->logWarning('Unable to create sampler', ['error' => $t]);
self::logWarning('Unable to create sampler', ['error' => $t]);
$sampler = null;
}

try {
$spanProcessor = $this->spanProcessorFactory->fromEnvironment($exporter);
} catch (\Throwable $t) {
$this->logWarning('Unable to create span processor', ['error' => $t]);
self::logWarning('Unable to create span processor', ['error' => $t]);
$spanProcessor = null;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/SDK/SpanLimitsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use OpenTelemetry\SDK\Trace\SpanLimitsBuilder;
use PHPUnit\Framework\TestCase;

/**
* @coversNothing
*/
class SpanLimitsBuilderTest extends TestCase
{
use EnvironmentVariables;
Expand Down

0 comments on commit 93c0bf0

Please sign in to comment.