Skip to content

Commit

Permalink
support partial success of curl_setopt_array (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmovcan authored Nov 23, 2024
1 parent 799985e commit f6a567b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Instrumentation/Curl/src/CurlInstrumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
Expand Down

0 comments on commit f6a567b

Please sign in to comment.