Commit d0e1aa8a authored by wanjilong's avatar wanjilong

add: request 增加 traceId

parent 94791b89
......@@ -21,6 +21,7 @@ namespace Api\PhpUtils\Http;
use Api\PhpUtils\Log\FileLog;
use Api\PhpUtils\Log\Tracer;
use Api\PhpUtils\Mon\MonUtil;
class HttpUtil
......@@ -58,6 +59,10 @@ class HttpUtil
*/
public static function get(string $url,array $params = [], int $timeout = 10000,int $retries = 1, array $headers = [], string $proxy = '',array $curl_opts = []): array
{
// 增加traceId
if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId();
}
$url = $url ."?". http_build_query($params);
return self::curl($url, $timeout, $retries, $headers, [], $proxy, 'GET', $curl_opts);
}
......@@ -90,6 +95,10 @@ class HttpUtil
*/
public static function post(string $url, $post,int $timeout = 10000,int $retries = 1,array $headers = [], string $proxy = '',array $curl_opts = []): array
{
// 增加traceId
if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId();
}
return self::curl($url, $timeout, $retries, $headers, $post, $proxy, 'POST', $curl_opts);
}
......
......@@ -2,6 +2,7 @@
namespace Api\PhpUtils\Http;
use Api\PhpUtils\Log\FileLog;
use Api\PhpUtils\Log\Tracer;
use Api\PhpUtils\Mon\MonUtil;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
......@@ -64,6 +65,12 @@ class Request
if (!empty($timeout)) {
$options['timeout'] = $timeout / 1000;
}
// 增加traceId
if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId();
}
if (!empty($headers)) {
$options['headers'] = $headers;
}
......@@ -140,6 +147,12 @@ class Request
if (!empty($timeout)) {
$options['timeout'] = $timeout / 1000;
}
// 增加traceId
if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId();
}
if (!empty($headers)) {
$options['headers'] = $headers;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment