From f6a567b1fa3545b68218d80b0a2702d8e551069f Mon Sep 17 00:00:00 2001 From: "Viktor M." Date: Sat, 23 Nov 2024 23:41:50 +0000 Subject: [PATCH] support partial success of curl_setopt_array (#316) --- .../Curl/src/CurlInstrumentation.php | 8 ++++++++ .../tests/Integration/CurlInstrumentationTest.php | 13 +++++++++++++ 2 files changed, 21 insertions(+) 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/');