Skip to content

Commit

Permalink
logging more errors (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc authored Jul 13, 2022
1 parent 82b0135 commit 37a8c8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Contrib/Jaeger/JaegerTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions src/SDK/Trace/Behavior/HttpSpanExporterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,7 @@
*/
trait HttpSpanExporterTrait
{
use LogsMessagesTrait;
use SpanExporterTrait;

protected string $endpointUrl;
Expand All @@ -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;
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 @@ -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;
}

Expand Down

0 comments on commit 37a8c8e

Please sign in to comment.