diff --git a/src/Instrumentation/Curl/src/CurlInstrumentation.php b/src/Instrumentation/Curl/src/CurlInstrumentation.php index 299639f1..27bef127 100644 --- a/src/Instrumentation/Curl/src/CurlInstrumentation.php +++ b/src/Instrumentation/Curl/src/CurlInstrumentation.php @@ -82,6 +82,14 @@ public static function register(): void pre: null, post: static function ($obj, array $params, mixed $retVal) use ($curlHandleToAttributes) { if ($retVal != true) { + if (curl_error($params[0])) { + foreach ($params[1] as $option => $value) { + if (!curl_setopt($params[0], $option, $value)) { + break; + } + } + } + return; } diff --git a/src/Instrumentation/Curl/tests/Integration/CurlInstrumentationTest.php b/src/Instrumentation/Curl/tests/Integration/CurlInstrumentationTest.php index 4ff18f10..90f928be 100644 --- a/src/Instrumentation/Curl/tests/Integration/CurlInstrumentationTest.php +++ b/src/Instrumentation/Curl/tests/Integration/CurlInstrumentationTest.php @@ -96,6 +96,19 @@ public function test_curl_setopt_array(): void $this->assertStringContainsString('resolve host', $span->getStatus()->getDescription()); } + public function test_curl_setopt_array_partial_success(): void + { + $ch = curl_init(); + curl_setopt_array($ch, [CURLOPT_POST => 1, CURLOPT_URL => 'http://gugugaga.gugugaga/', CURLOPT_SSLVERSION => 1000 ]); + curl_exec($ch); + + $this->assertCount(1, $this->storage); + $span = $this->storage->offsetGet(0); + $this->assertSame('POST', $span->getName()); + $this->assertSame('Error', $span->getStatus()->getCode()); + $this->assertStringContainsString('resolve host', $span->getStatus()->getDescription()); + } + public function test_curl_copy_handle(): void { $ch = curl_init('http://gugugaga.gugugaga/');