From 37a8c8efa17f42dd4e441c3d290729aff2a44369 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 14 Jul 2022 00:16:18 +1000 Subject: [PATCH] logging more errors (#764) --- src/Contrib/Jaeger/JaegerTransport.php | 2 +- src/SDK/Trace/Behavior/HttpSpanExporterTrait.php | 8 ++++++++ src/SDK/Trace/TracerProviderFactory.php | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Contrib/Jaeger/JaegerTransport.php b/src/Contrib/Jaeger/JaegerTransport.php index 587b71302..d14ad4273 100644 --- a/src/Contrib/Jaeger/JaegerTransport.php +++ b/src/Contrib/Jaeger/JaegerTransport.php @@ -94,7 +94,7 @@ public function flush($force = false): int // reset the process tag $this->process = null; } catch (TTransportException $e) { - self::logError('jaeger: transport failure: ' . $e->getMessage()); + self::logError('jaeger: transport failure', ['exception' => $e]); return 0; } diff --git a/src/SDK/Trace/Behavior/HttpSpanExporterTrait.php b/src/SDK/Trace/Behavior/HttpSpanExporterTrait.php index 4fcda9f3e..ee73ec2df 100644 --- a/src/SDK/Trace/Behavior/HttpSpanExporterTrait.php +++ b/src/SDK/Trace/Behavior/HttpSpanExporterTrait.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use JsonException; +use OpenTelemetry\SDK\Behavior\LogsMessagesTrait; use OpenTelemetry\SDK\Trace\SpanExporterInterface; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; @@ -24,6 +25,7 @@ */ trait HttpSpanExporterTrait { + use LogsMessagesTrait; use SpanExporterTrait; protected string $endpointUrl; @@ -46,14 +48,20 @@ protected function doExport(iterable $spans): int try { $response = $this->dispatchSpans($spans); } catch (ClientExceptionInterface $e) { + self::logError('Unable to export span(s)', ['exception' => $e]); + return $e instanceof RequestExceptionInterface ? SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE : SpanExporterInterface::STATUS_FAILED_RETRYABLE; } catch (Throwable $e) { + self::logError('Unable to export span(s)', ['exception' => $e]); + return SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE; } if ($response->getStatusCode() >= 400) { + self::logError('Unable to export span(s)', ['code' => $response->getStatusCode()]); + return $response->getStatusCode() < 500 ? SpanExporterInterface::STATUS_FAILED_NOT_RETRYABLE : SpanExporterInterface::STATUS_FAILED_RETRYABLE; diff --git a/src/SDK/Trace/TracerProviderFactory.php b/src/SDK/Trace/TracerProviderFactory.php index e2f75d5a7..e171e0251 100644 --- a/src/SDK/Trace/TracerProviderFactory.php +++ b/src/SDK/Trace/TracerProviderFactory.php @@ -30,21 +30,21 @@ public function create(): TracerProviderInterface try { $exporter = $this->exporterFactory->fromEnvironment(); } catch (\Throwable $t) { - self::logWarning('Unable to create exporter', ['error' => $t]); + self::logWarning('Unable to create exporter', ['exception' => $t]); $exporter = null; } try { $sampler = $this->samplerFactory->fromEnvironment(); } catch (\Throwable $t) { - self::logWarning('Unable to create sampler', ['error' => $t]); + self::logWarning('Unable to create sampler', ['exception' => $t]); $sampler = null; } try { $spanProcessor = $this->spanProcessorFactory->fromEnvironment($exporter); } catch (\Throwable $t) { - self::logWarning('Unable to create span processor', ['error' => $t]); + self::logWarning('Unable to create span processor', ['exception' => $t]); $spanProcessor = null; }