From 89bc8ddad40fae02df6b2193e583d293b6ab6da8 Mon Sep 17 00:00:00 2001 From: cyve Date: Mon, 11 Sep 2023 23:08:13 +0200 Subject: [PATCH] chore: remove Symfony 6.3 deprecation messages --- .../Messenger/TraceContextStampSpec.php | 3 +- src/Http/TracingHttpClient.php | 2 +- src/InstrumentationBundle.php | 4 +++ src/Logging/Logging.php | 2 +- ...erverRequestAttributeProviderInterface.php | 2 +- .../RoutePath/RouteCacheWarmer.php | 4 +-- .../MessengerEventSubscriber.php | 2 +- .../Serializer/Normalizer/ErrorNormalizer.php | 28 ++++++++++++++----- 8 files changed, 33 insertions(+), 14 deletions(-) diff --git a/spec/Tracing/Propagation/Messenger/TraceContextStampSpec.php b/spec/Tracing/Propagation/Messenger/TraceContextStampSpec.php index 93616ec..a3bea91 100644 --- a/spec/Tracing/Propagation/Messenger/TraceContextStampSpec.php +++ b/spec/Tracing/Propagation/Messenger/TraceContextStampSpec.php @@ -10,6 +10,7 @@ use Instrumentation\Tracing\Propagation\Exception\ContextPropagationException; use OpenTelemetry\API\Trace\NonRecordingSpan; use OpenTelemetry\API\Trace\SpanContext; +use OpenTelemetry\API\Trace\TraceFlags; use OpenTelemetry\API\Trace\TraceState; use PhpSpec\ObjectBehavior; use Symfony\Component\Messenger\Stamp\StampInterface; @@ -48,7 +49,7 @@ public function it_creates_stamp_with_state(): void $span = new NonRecordingSpan(SpanContext::create( 'b23f37322b169de7bcaf63b9f84b1427', '3c17130d40834256', - SpanContext::TRACE_FLAG_DEFAULT, + TraceFlags::DEFAULT, (new TraceState())->with('key', 'value'), )); $scope = $span->activate(); diff --git a/src/Http/TracingHttpClient.php b/src/Http/TracingHttpClient.php index 0acaa94..67103f3 100644 --- a/src/Http/TracingHttpClient.php +++ b/src/Http/TracingHttpClient.php @@ -37,7 +37,7 @@ final class TracingHttpClient implements HttpClientInterface * @param HttpClientInterface|array|null $client */ public function __construct( - HttpClientInterface|array|null $client = null, + HttpClientInterface|array $client = null, ClientRequestOperationNameResolverInterface $operationNameResolver = null, ClientRequestAttributeProviderInterface $attributeProvider = null, int $maxHostConnections = 6, diff --git a/src/InstrumentationBundle.php b/src/InstrumentationBundle.php index a2d640c..6a64ebf 100644 --- a/src/InstrumentationBundle.php +++ b/src/InstrumentationBundle.php @@ -22,6 +22,10 @@ public function getContainerExtensionClass(): string public function boot(): void { + if (null === $this->container) { + return; + } + $this->container->get(Logging\Logging::class); /** @var TracerProviderInterface $tracerProvider */ diff --git a/src/Logging/Logging.php b/src/Logging/Logging.php index b31013c..6506b5a 100644 --- a/src/Logging/Logging.php +++ b/src/Logging/Logging.php @@ -9,7 +9,7 @@ namespace Instrumentation\Logging; -use OpenTelemetry\API\Common\Log\LoggerHolder; +use OpenTelemetry\API\LoggerHolder; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; diff --git a/src/Semantics/Attribute/ServerRequestAttributeProviderInterface.php b/src/Semantics/Attribute/ServerRequestAttributeProviderInterface.php index 2896244..a59dabf 100644 --- a/src/Semantics/Attribute/ServerRequestAttributeProviderInterface.php +++ b/src/Semantics/Attribute/ServerRequestAttributeProviderInterface.php @@ -15,7 +15,7 @@ interface ServerRequestAttributeProviderInterface { /** - * @return array> + * @return array> */ public function getAttributes(Request $request): array; } diff --git a/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php b/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php index 31580e5..313d505 100644 --- a/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php +++ b/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php @@ -18,12 +18,12 @@ public function __construct(private RouterInterface $router) { } - public function isOptional() + public function isOptional(): bool { return true; } - public function warmUp(string $cacheDir) + public function warmUp(string $cacheDir): array { $routes = []; foreach ($this->router->getRouteCollection() as $name => $route) { diff --git a/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php b/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php index ff3f62d..0e9512a 100644 --- a/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php +++ b/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php @@ -23,7 +23,7 @@ class MessengerEventSubscriber implements EventSubscriberInterface private LoggerInterface $logger; private ?ScopeInterface $scope = null; - public function __construct(LoggerInterface|null $logger = null) + public function __construct(LoggerInterface $logger = null) { $this->logger = $logger ?? new NullLogger(); } diff --git a/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php b/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php index 900cc59..7ba34b4 100644 --- a/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php +++ b/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php @@ -11,15 +11,34 @@ use Instrumentation\Tracing\TraceUrlGeneratorInterface; use OpenTelemetry\SDK\Trace\Span; -use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface; +use Symfony\Component\ErrorHandler\Exception\FlattenException; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; +use Symfony\Component\Serializer\SerializerAwareInterface; +use Symfony\Component\Serializer\SerializerInterface; -class ErrorNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface +class ErrorNormalizer implements NormalizerInterface, SerializerAwareInterface { public function __construct(private NormalizerInterface $decorated, private bool $addUrl = false, private ?TraceUrlGeneratorInterface $traceUrlGenerator = null) { } + public function setSerializer(SerializerInterface $serializer) + { + if ($this->decorated instanceof SerializerAwareInterface) { + $this->decorated->setSerializer($serializer); + } + } + + /** + * @return array + */ + public function getSupportedTypes(?string $format): array + { + return [ + FlattenException::class => __CLASS__ === self::class, + ]; + } + /** * @param array $context * @@ -52,9 +71,4 @@ public function supportsNormalization($data, string $format = null, array $conte // @phpstan-ignore-next-line return $this->decorated->supportsNormalization($data, $format, $context); } - - public function hasCacheableSupportsMethod(): bool - { - return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); - } }