Skip to content

Commit 4d37b4d

Browse files
committed
Curl instrumentation fix
1 parent e0804bb commit 4d37b4d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Instrumentation/Curl/src/CurlInstrumentation.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public static function register(): void
8484
pre: null,
8585
post: static function ($_obj, array $params, mixed $retVal) use ($curlHandleToAttributes) {
8686
if ($retVal != true) {
87-
if (curl_error($params[0])) {
88-
foreach ($params[1] as $option => $value) {
89-
if (!curl_setopt($params[0], $option, $value)) {
90-
break;
91-
}
87+
foreach ($params[1] as $option => $value) {
88+
if (!curl_setopt($params[0], $option, $value)) {
89+
break;
9290
}
9391
}
9492

@@ -341,7 +339,7 @@ public static function register(): void
341339
foreach ($handles as $cHandle => &$metadata) {
342340
if ($metadata['finished'] == false) {
343341
$metadata['finished'] = true;
344-
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
342+
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
345343
}
346344
}
347345

@@ -381,15 +379,19 @@ public static function register(): void
381379

382380
/** @psalm-suppress PossiblyNullArrayAccess */
383381
$currentHandle['finished'] = true;
384-
self::finishMultiSpan($retVal['result'], $retVal['handle'], $curlHandleToAttributes, $currentHandle['span']->get());
382+
self::finishMultiSpan($retVal['result'], $retVal['handle'], $curlHandleToAttributes, $currentHandle['span']?->get());
385383
}
386384
}
387385
}
388386
);
389387
}
390388

391-
private static function finishMultiSpan(int $curlResult, CurlHandle $curlHandle, $curlHandleToAttributes, SpanInterface $span)
389+
private static function finishMultiSpan(int $curlResult, CurlHandle $curlHandle, $curlHandleToAttributes, ?SpanInterface $span)
392390
{
391+
if ($span === null) {
392+
return;
393+
}
394+
393395
$scope = Context::storage()->scope();
394396
$scope?->detach();
395397

0 commit comments

Comments
 (0)