Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pinpoint-apm/pinpoint-php-aop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 17c62dd787cd069af4dafd9ebf0274fab1079107
Choose a base ref
..
head repository: pinpoint-apm/pinpoint-php-aop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 78e0315beee4c443dd5337612acd5ecb975cd395
Choose a head ref
6 changes: 4 additions & 2 deletions lib/Pinpoint/Plugins/Common/CommonPlugin.php
Original file line number Diff line number Diff line change
@@ -18,17 +18,19 @@

namespace Pinpoint\Plugins\Common;

use function Pinpoint\Plugins\{pinpoint_add_clue};

class CommonPlugin extends PinTrace
{
public function onBefore()
{
pinpoint_add_clue(PP_SERVER_TYPE, PP_PHP_METHOD);
pinpoint_add_clues(PP_PHP_ARGS, "--placeholder---");
// pinpoint_add_clues(PP_PHP_ARGS, "--placeholder---");
}

public function onEnd(&$ret)
{
pinpoint_add_clues(PP_PHP_RETURN, "--placeholder---");
// pinpoint_add_clues(PP_PHP_RETURN, "--placeholder---");
}

public function onException($e)
1 change: 1 addition & 0 deletions lib/Pinpoint/Plugins/Sys/curl/CurlUtil.php
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
namespace Pinpoint\Plugins\Sys\curl;

use Pinpoint\Plugins\Common\TraceHelper;
use function Pinpoint\Plugins\{pinpoint_get_context, pinpoint_set_context};

class CurlUtil
{
6 changes: 3 additions & 3 deletions lib/Pinpoint/Plugins/SysV2/_curl/__init__.php
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@
******************************************************************************/
namespace Pinpoint\Plugins\SysV2\_curl;

if (!extension_loaded('curl')){
return ;
if (!extension_loaded('curl')) {
return;
}

require_once __DIR__ . "/curl7.php";
require_once __DIR__ . "/curl.php";

// author: eeliu
Original file line number Diff line number Diff line change
@@ -32,11 +32,13 @@
pinpoint_join_cut(
["curl_setopt"],
function ($ch, $option, $value) use (&$ch_res) {
if ($option == CURLOPT_HTTPHEADER && is_array($value)) {
if ($option == CURLOPT_HTTPHEADER && is_array($value) && !in_array((int) $ch, $ch_res)) {
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$nextSpan = new NextSpan($url);
$ch_res[(int) $ch] = $nextSpan;
$ch_res[(int) $ch] = true;
$value = array_merge($value, $nextSpan->genNextSpan());
// echo "--------$ch-----CURLOPT_HTTPHEADER---------------------------";
// var_dump($value);
return [$ch, $option, $value];
}
},
@@ -50,7 +52,8 @@ function ($e) {
["curl_exec"],
function ($ch) use (&$ch_res) {
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
if (!$ch_res[(int) $ch]) {
if (!in_array((int) $ch, $ch_res)) {
$ch_res[(int) $ch] = true;
curl_setopt($ch, CURLOPT_HTTPHEADER, genUrlNextSpan($url));
}
pinpoint_start_trace();
24 changes: 11 additions & 13 deletions lib/Pinpoint/Plugins/autoload/_GuzzleHttp/GuzzlePlugin.php
Original file line number Diff line number Diff line change
@@ -16,28 +16,26 @@
******************************************************************************/
namespace Pinpoint\Plugins\autoload\_GuzzleHttp;

use function Pinpoint\Plugins\{pinpoint_add_clue, pinpoint_add_clues};
use function Pinpoint\Plugins\{pinpoint_add_clue, pinpoint_add_clues, pinpoint_get_context};
use Pinpoint\Plugins\Common\PinTrace;
use Pinpoint\Plugins\Sys\curl\CurlUtil;

///@hook:GuzzleHttp\Client::request
class GuzzlePlugin extends PinTrace
{
///@hook:GuzzleHttp\Psr7\Request::__construct
function onBefore()
{
if (strpos($this->monitor_name, "GuzzleHttp\Psr7\Request::__construct") !== false) {
pinpoint_add_clue(PP_DESTINATION, CurlUtil::getHostFromURL((string) ($this->args[1])));
pinpoint_add_clues(PP_HTTP_URL, $this->args[1]);
pinpoint_add_clue(PP_SERVER_TYPE, PP_PHP_REMOTE);
var_dump($this->args);
pinpoint_add_clue(PP_DESTINATION, CurlUtil::getHostFromURL((string) ($this->args[1])));
pinpoint_add_clues(PP_HTTP_URL, $this->args[1]);
pinpoint_add_clue(PP_SERVER_TYPE, PP_PHP_REMOTE);

$n_headers = [];
if (is_array($this->args[2]) && array_key_exists('headers', $this->args[2])) {
$n_headers = $this->args[2];
}
$n_headers = array_merge($n_headers, CurlUtil::getPPHeader($this->args[1]));
$this->args[2] = $n_headers;
$pp_headers = [];
if (is_array($this->args[2]) && array_key_exists('headers', $this->args[2])) {
$pp_headers = $this->args[2];
}
$pp_headers = array_merge($pp_headers, CurlUtil::getPPHeader($this->args[1]));

$this->args[2]['headers'] = $pp_headers;
}

function onEnd(&$ret)
25 changes: 25 additions & 0 deletions lib/Pinpoint/Plugins/autoload/_GuzzleHttp/Guzzle_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Pinpoint\Plugins\autoload\_GuzzleHttp;

use Pinpoint\test\TraceTest;


class Guzzle_Test extends TraceTest
{
public function test_sync()
{
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://httpbin.org/get');

$this->assertEquals($response->getStatusCode(), 200);
$response_ar = json_decode($response->getBody()->getContents(), true);
var_dump($response_ar);
$this->assertArrayHasKey('Pinpoint-Flags', $response_ar['headers']);
$this->assertArrayHasKey('Pinpoint-Papptype', $response_ar['headers']);
$this->assertArrayHasKey('Pinpoint-Pspanid', $response_ar['headers']);
$this->assertArrayHasKey('Pinpoint-Sampled', $response_ar['headers']);
$this->assertArrayHasKey('Pinpoint-Traceid', $response_ar['headers']);
echo static::$logger_->message_;
}

}
13 changes: 9 additions & 4 deletions lib/Pinpoint/Plugins/autoload/_GuzzleHttp/__init__.php
Original file line number Diff line number Diff line change
@@ -23,13 +23,18 @@
$cls = [];

$classHandler = new AspectClassHandle(\GuzzleHttp\Client::class);
$classHandler->addJoinPoint('request', GuzzlePlugin::class);
$cls[] = $classHandler;
if (extension_loaded('curl')) {
$classHandler->addJoinPoint('request', \Pinpoint\Plugins\Common\CommonPlugin::class);
} else {
$classHandler->addJoinPoint('request', GuzzlePlugin::class);
}

$classHandler = new AspectClassHandle(\GuzzleHttp\Psr7\Request::class);
$classHandler->addJoinPoint('__construct', GuzzlePlugin::class);
$cls[] = $classHandler;

// $classHandler = new AspectClassHandle(\GuzzleHttp\Psr7\Request::class);
// $classHandler->addJoinPoint('__construct', GuzzlePlugin::class);
// $cls[] = $classHandler;


return $cls;