Skip to content

Commit f57aada

Browse files
authored
Drop support for PHP 7.4 and 8.0, introduce support for PHP 8.4, fix semconv deprecations (#315)
* Fixed a bit of warnings and deprecations * Dropped support for PHP 7.4 and 8.0. Introduced support for PHP 8.4 * Set revision psalm to 6.4.0, more suppressions * Curl instrumentation fix * updated packages generating deprecated warnings
1 parent 1d85f8d commit f57aada

8 files changed

+29
-29
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"minimum-stability": "dev",
1010
"prefer-stable": true,
1111
"require": {
12-
"php": "^8.0",
12+
"php": "^8.1",
1313
"ext-opentelemetry": "*",
1414
"open-telemetry/api": "^1.0",
1515
"open-telemetry/sem-conv": "^1.30",
@@ -26,10 +26,10 @@
2626
"php-http/mock-client": "*",
2727
"phpstan/phpstan": "^1.1",
2828
"phpstan/phpstan-phpunit": "^1.0",
29-
"psalm/plugin-phpunit": "^0.18.4",
29+
"psalm/plugin-phpunit": "^0.19.2",
3030
"open-telemetry/sdk": "^1.0",
3131
"phpunit/phpunit": "^9.5",
32-
"vimeo/psalm": "^5.0",
32+
"vimeo/psalm": "6.4.0",
3333
"symfony/http-client": "^5.4||^6.0",
3434
"symfony/messenger": "^5.4||^6.0",
3535
"open-telemetry/opentelemetry-propagation-traceresponse": "*",

src/HttpClientInstrumentation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
/**
2020
* @phan-file-suppress PhanTypeInvalidCallableArraySize
21+
* @psalm-suppress UnusedClass
2122
*/
2223
final class HttpClientInstrumentation
2324
{
@@ -43,6 +44,7 @@ public static function register(): void
4344
'https://opentelemetry.io/schemas/1.30.0',
4445
);
4546

47+
/** @psalm-suppress UnusedFunctionCall */
4648
hook(
4749
HttpClientInterface::class,
4850
'request',

src/MessengerInstrumentation.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ final class MessengerInstrumentation
3232
const ATTRIBUTE_MESSENGER_MESSAGE = 'symfony.messenger.message';
3333
const ATTRIBUTE_MESSENGER_TRANSPORT = 'symfony.messenger.transport';
3434

35+
/** @psalm-suppress PossiblyUnusedMethod */
3536
public static function register(): void
3637
{
3738
$instrumentation = new CachedInstrumentation(
@@ -42,7 +43,9 @@ public static function register(): void
4243

4344
/**
4445
* MessageBusInterface dispatches messages to the handlers.
45-
*/
46+
*
47+
* @psalm-suppress UnusedFunctionCall
48+
*/
4649
hook(
4750
MessageBusInterface::class,
4851
'dispatch',
@@ -107,7 +110,9 @@ public static function register(): void
107110

108111
/**
109112
* SenderInterface sends messages to a transport.
110-
*/
113+
*
114+
* @psalm-suppress UnusedFunctionCall
115+
*/
111116
hook(
112117
SenderInterface::class,
113118
'send',

src/ResponsePropagationSetter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public static function instance(): self
2020
return $instance ??= new self();
2121
}
2222

23-
/** @psalm-suppress InvalidReturnType */
23+
/** @psalm-suppress InvalidReturnType
24+
* @psalm-suppress PossiblyUnusedMethod
25+
*/
2426
public function keys($carrier): array
2527
{
2628
assert($carrier instanceof Response);

src/SymfonyInstrumentation.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpKernel\HttpKernel;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
2020

21+
/** @psalm-suppress UnusedClass */
2122
final class SymfonyInstrumentation
2223
{
2324
public const NAME = 'symfony';
@@ -30,6 +31,7 @@ public static function register(): void
3031
'https://opentelemetry.io/schemas/1.30.0',
3132
);
3233

34+
/** @psalm-suppress UnusedFunctionCall */
3335
hook(
3436
HttpKernel::class,
3537
'handle',
@@ -146,16 +148,17 @@ public static function register(): void
146148
}
147149
);
148150

151+
/** @psalm-suppress UnusedFunctionCall */
149152
hook(
150153
HttpKernel::class,
151154
'handleThrowable',
152155
pre: static function (
153-
HttpKernel $kernel,
156+
HttpKernel $_kernel,
154157
array $params,
155-
string $class,
156-
string $function,
157-
?string $filename,
158-
?int $lineno,
158+
string $_class,
159+
string $_function,
160+
?string $_filename,
161+
?int $_lineno,
159162
): array {
160163
/** @var \Throwable $throwable */
161164
$throwable = $params[0];

tests/Integration/HttpClientInstrumentationTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration;
66

77
use OpenTelemetry\API\Trace\StatusCode;
8-
use OpenTelemetry\SDK\Trace\EventInterface;
9-
use OpenTelemetry\SDK\Trace\ImmutableSpan;
108
use OpenTelemetry\SemConv\TraceAttributes;
119
use Symfony\Component\HttpClient\CurlHttpClient;
1210
use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
@@ -21,7 +19,7 @@ public static function setUpBeforeClass(): void
2119
TestHttpServer::start();
2220
}
2321

24-
protected function getHttpClient(string $testCase): HttpClientInterface
22+
protected function getHttpClient(string $_testCase): HttpClientInterface
2523
{
2624
return new CurlHttpClient(['verify_peer' => false, 'verify_host' => false]);
2725
}
@@ -38,7 +36,6 @@ public function test_send_request(string $method, string $uri, int $statusCode,
3836
$response->getStatusCode();
3937
$this->assertCount(1, $this->storage);
4038

41-
/** @var ImmutableSpan $span */
4239
$span = $this->storage[0];
4340

4441
$this->assertStringContainsString($method, $span->getName());
@@ -65,7 +62,7 @@ public function test_throw_exception(): void
6562
$this->assertCount(0, $this->storage);
6663

6764
try {
68-
$response = $client->request('GET', 'http://localhost:8057', [
65+
$client->request('GET', 'http://localhost:8057', [
6966
'bindto' => '127.0.0.1:9876',
7067
'auth_ntlm' => [],
7168
]);
@@ -74,9 +71,7 @@ public function test_throw_exception(): void
7471

7572
$this->assertCount(1, $this->storage);
7673

77-
/** @var ImmutableSpan $span */
7874
$span = $this->storage[0];
79-
/** @var EventInterface $event */
8075
$event = $span->getEvents()[0];
8176

8277
$this->assertTrue($span->getAttributes()->has(TraceAttributes::URL_FULL));

tests/Integration/MessengerInstrumentationTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use OpenTelemetry\API\Trace\SpanKind;
88
use OpenTelemetry\Contrib\Instrumentation\Symfony\MessengerInstrumentation;
9-
use OpenTelemetry\SDK\Trace\ImmutableSpan;
109
use Symfony\Component\Messenger\Envelope;
1110
use Symfony\Component\Messenger\MessageBus;
1211
use Symfony\Component\Messenger\MessageBusInterface;
@@ -23,6 +22,7 @@ public function __construct(string $message)
2322
$this->message = $message;
2423
}
2524

25+
/** @psalm-suppress PossiblyUnusedMethod */
2626
public function getMessage(): string
2727
{
2828
return $this->message;
@@ -61,7 +61,6 @@ public function test_dispatch_message($message, string $spanName, int $kind, arr
6161

6262
$this->assertCount(1, $this->storage);
6363

64-
/** @var ImmutableSpan $span */
6564
$span = $this->storage[0];
6665

6766
$this->assertEquals($spanName, $span->getName());
@@ -87,7 +86,6 @@ public function test_send_message($message, string $spanName, int $kind, array $
8786

8887
$this->assertCount(1, $this->storage);
8988

90-
/** @var ImmutableSpan $span */
9189
$span = $this->storage[0];
9290

9391
$this->assertEquals($spanName, $span->getName());
@@ -112,9 +110,7 @@ public function dispatch(object $message, array $stamps = []): Envelope
112110
$bus->dispatch(new SendEmailMessage('Hello Again'));
113111
} catch (\Throwable $e) {
114112
$this->assertCount(1, $this->storage);
115-
116-
/** @var ImmutableSpan $span */
117-
$span = $this->storage[0];
113+
$this->assertArrayHasKey(0, $this->storage);
118114
}
119115
}
120116

@@ -146,8 +142,7 @@ public function send(Envelope $envelope): Envelope
146142
$transport->send(new Envelope(new SendEmailMessage('Hello Again')));
147143
} catch (\Throwable $e) {
148144
$this->assertCount(1, $this->storage);
149-
150-
$span = $this->storage[0];
145+
$this->assertArrayHasKey(0, $this->storage);
151146
}
152147
}
153148

tests/Integration/SymfonyInstrumentationTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use OpenTelemetry\API\Trace\StatusCode;
99
use OpenTelemetry\Contrib\Propagation\ServerTiming\ServerTimingPropagator;
1010
use OpenTelemetry\Contrib\Propagation\TraceResponse\TraceResponsePropagator;
11-
use OpenTelemetry\SDK\Trace\ImmutableSpan;
1211
use OpenTelemetry\SemConv\TraceAttributes;
1312
use Symfony\Component\EventDispatcher\EventDispatcher;
1413
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -200,13 +199,12 @@ public function test_http_kernel_handle_subrequest(): void
200199
$kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
201200
$this->assertCount(1, $this->storage);
202201

203-
/** @var ImmutableSpan $span */
204202
$span = $this->storage[0];
205203
$this->assertSame('GET ErrorController', $span->getName());
206204
$this->assertSame(SpanKind::KIND_INTERNAL, $span->getKind());
207205
}
208206

209-
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = []): HttpKernel
207+
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, ?RequestStack $requestStack = null, array $arguments = []): HttpKernel
210208
{
211209
$controller ??= fn () => new Response('Hello');
212210

0 commit comments

Comments
 (0)