Skip to content

Commit f6a567b

Browse files
authored
support partial success of curl_setopt_array (#316)
1 parent 799985e commit f6a567b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Instrumentation/Curl/src/CurlInstrumentation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ public static function register(): void
8282
pre: null,
8383
post: static function ($obj, array $params, mixed $retVal) use ($curlHandleToAttributes) {
8484
if ($retVal != true) {
85+
if (curl_error($params[0])) {
86+
foreach ($params[1] as $option => $value) {
87+
if (!curl_setopt($params[0], $option, $value)) {
88+
break;
89+
}
90+
}
91+
}
92+
8593
return;
8694
}
8795

src/Instrumentation/Curl/tests/Integration/CurlInstrumentationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public function test_curl_setopt_array(): void
9696
$this->assertStringContainsString('resolve host', $span->getStatus()->getDescription());
9797
}
9898

99+
public function test_curl_setopt_array_partial_success(): void
100+
{
101+
$ch = curl_init();
102+
curl_setopt_array($ch, [CURLOPT_POST => 1, CURLOPT_URL => 'http://gugugaga.gugugaga/', CURLOPT_SSLVERSION => 1000 ]);
103+
curl_exec($ch);
104+
105+
$this->assertCount(1, $this->storage);
106+
$span = $this->storage->offsetGet(0);
107+
$this->assertSame('POST', $span->getName());
108+
$this->assertSame('Error', $span->getStatus()->getCode());
109+
$this->assertStringContainsString('resolve host', $span->getStatus()->getDescription());
110+
}
111+
99112
public function test_curl_copy_handle(): void
100113
{
101114
$ch = curl_init('http://gugugaga.gugugaga/');

0 commit comments

Comments
 (0)