Skip to content

Commit 4a740a5

Browse files
authored
Allow return integer type when resolving attributes (open-telemetry#349)
* fix: add return type to get method and format code * fix: check correctly port when null value
1 parent ac859b2 commit 4a740a5

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Instrumentation/Doctrine/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"config": {
5050
"allow-plugins": {
5151
"php-http/discovery": false,
52-
"tbachert/spi": true
52+
"tbachert/spi": false
5353
}
5454
}
55-
}
55+
}

src/Instrumentation/Doctrine/src/AttributesResolver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class AttributesResolver
4141
'trino',
4242
];
4343

44-
public static function get(string $attributeName, array $params): string
44+
public static function get(string $attributeName, array $params): string|int|null
4545
{
4646
$method = 'get' . str_replace('.', '', ucwords($attributeName, '.'));
4747

@@ -63,9 +63,14 @@ private static function getServerAddress(array $params): string
6363
/**
6464
* Resolve attribute `server.port`
6565
*/
66-
private static function getServerPort(array $params): string
66+
private static function getServerPort(array $params): ?int
6767
{
68-
return $params[1][0]['port'] ?? 'unknown';
68+
$port = $params[1][0]['port'] ?? null;
69+
if ($port) {
70+
$port = (int) $port;
71+
}
72+
73+
return $port;
6974
}
7075

7176
/**

0 commit comments

Comments
 (0)