From 95fea86d06fc994f702a37ff6fbb7ecc9d909a38 Mon Sep 17 00:00:00 2001 From: Shawn Maddock Date: Mon, 19 May 2025 11:29:00 -0500 Subject: [PATCH 1/4] openaiphp phpunit failure fix --- src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php b/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php index 8be64d0db..8511a583f 100644 --- a/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php +++ b/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php @@ -193,7 +193,7 @@ private static function hookApi(CachedInstrumentation $instrumentation, $class, private static function recordUsage(SpanInterface $span, object $response, ContextInterface $context) { - if (!property_exists($response, 'usage') || !method_exists($response->usage, 'toArray')) { + if (!property_exists($response, 'usage') || !isset($response->usage) || !method_exists($response->usage, 'toArray')) { return; } From 9ab130937d59ff5152fbd23893b4ca4793a01670 Mon Sep 17 00:00:00 2001 From: Shawn Maddock Date: Mon, 19 May 2025 13:49:06 -0500 Subject: [PATCH 2/4] curl intermittent phpunit failure fix --- src/Instrumentation/Curl/src/CurlInstrumentation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Instrumentation/Curl/src/CurlInstrumentation.php b/src/Instrumentation/Curl/src/CurlInstrumentation.php index 7e04d120e..f6c11e520 100644 --- a/src/Instrumentation/Curl/src/CurlInstrumentation.php +++ b/src/Instrumentation/Curl/src/CurlInstrumentation.php @@ -35,7 +35,7 @@ public static function register(): void * 'handles'=> * WeakMap[CurlHandle] => { * 'finished' => bool, - * 'span' => WeakReference + * 'span' => SpanInterface * } * ) */ @@ -327,7 +327,7 @@ public static function register(): void } $curlSetOptInstrumentationSuppressed = false; - $metadata['span'] = WeakReference::create($span); + $metadata['span'] = $span; } $mHandle['started'] = true; } @@ -339,7 +339,7 @@ public static function register(): void foreach ($handles as $cHandle => &$metadata) { if ($metadata['finished'] == false) { $metadata['finished'] = true; - self::finishMultiSpan(CURLE_OK, $cHandle, $curlHandleToAttributes, $metadata['span']?->get()); // there is no way to get information if it was OK or not without calling curl_multi_info_read + self::finishMultiSpan(CURLE_OK, $cHandle, $curlHandleToAttributes, $metadata['span']); // there is no way to get information if it was OK or not without calling curl_multi_info_read } } @@ -379,7 +379,7 @@ public static function register(): void /** @psalm-suppress PossiblyNullArrayAccess */ $currentHandle['finished'] = true; - self::finishMultiSpan($retVal['result'], $retVal['handle'], $curlHandleToAttributes, $currentHandle['span']?->get()); + self::finishMultiSpan($retVal['result'], $retVal['handle'], $curlHandleToAttributes, $currentHandle['span']); } } } From 7b2788fd110e6d5eb06da39d5fc9199cc12d518d Mon Sep 17 00:00:00 2001 From: Shawn Maddock Date: Mon, 19 May 2025 13:58:25 -0500 Subject: [PATCH 3/4] php-cs-fixer --- src/Instrumentation/Curl/src/CurlInstrumentation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Instrumentation/Curl/src/CurlInstrumentation.php b/src/Instrumentation/Curl/src/CurlInstrumentation.php index f6c11e520..b6d4d2647 100644 --- a/src/Instrumentation/Curl/src/CurlInstrumentation.php +++ b/src/Instrumentation/Curl/src/CurlInstrumentation.php @@ -18,7 +18,6 @@ use OpenTelemetry\SemConv\TraceAttributes; use OpenTelemetry\SemConv\Version; use WeakMap; -use WeakReference; class CurlInstrumentation { From 4874f3d092f6a9d8ab6818e52e9b16972de542e7 Mon Sep 17 00:00:00 2001 From: Shawn Maddock Date: Wed, 21 May 2025 07:33:26 -0500 Subject: [PATCH 4/4] revert 95fea86 --- src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php b/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php index 8511a583f..8be64d0db 100644 --- a/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php +++ b/src/Instrumentation/OpenAIPHP/src/OpenAIPHPInstrumentation.php @@ -193,7 +193,7 @@ private static function hookApi(CachedInstrumentation $instrumentation, $class, private static function recordUsage(SpanInterface $span, object $response, ContextInterface $context) { - if (!property_exists($response, 'usage') || !isset($response->usage) || !method_exists($response->usage, 'toArray')) { + if (!property_exists($response, 'usage') || !method_exists($response->usage, 'toArray')) { return; }