Skip to content

Commit 00890fa

Browse files
luizmanhanihuangdijialimingxinleoassert6crayxn
authored
Updating from main package (#24)
* [3.1]Bumps dependencies (#5796) Co-authored-by: 李铭昕 <[email protected]> * Upgrade hyperf packages to version `~3.1.0` (#5801) * Bumps `phpunit` to `10.x` (#5802) Co-authored-by: 李铭昕 <[email protected]> * Support swow psr7-plus interface for all components. (#5839) * Support aspect to `GuzzleHttp\Client::request()` (#5996) * Fixed the bug that `no_aspect` is overridden (#6013) * Allow using the tracer instance from context, append `Trace-Id` to Response Header (#6023) * Optimized the tracing in coroutine (#6027) Co-authored-by: 李铭昕 <[email protected]> * Make `Hyperf\Coroutine\Traits\Container` as deprecated. (#6044) Co-authored-by: 李铭昕 <[email protected]> * Using the tracer instance from coroutine context (#6046) * Supplement the missing tag configuration items (#6060) * Supplement the missing tag configuration items * Update CHANGELOG-3.0.md * Added `Kafka` reporter for zipkin (#6069) * Optimize kafka reporter (#6075) * Fix error that using non-zipkin driver of tracer (#6097) Co-authored-by: Deeka Wong <[email protected]> * Optimize kafka reporter of tracer (#6098) * Optimize the HttpClientFactory of tracer (#6100) * Allowed output log when an exception occurs (#6111) * Adds `RequestTraceListener` for `hyperf/tracer` (#6062) * Added `ignore_exceptions` for tracer (#6143) Co-authored-by: Deeka Wong <[email protected]> * Record the exception message only by opening the exception switch and closing the ignore switch when using `trace`. (#6157) Co-authored-by: 李铭昕 <[email protected]> * Upgrade actions/checkout to v4 (#6159) * Optimize `KafkaClientFactory` of `hyperf/tracer` (#6167) * Added RpcAspect and use it instead of JsonRpcAspect (#6198) * Added switch for `ElasticserachAspect` and `CoroutineAspect`. (#6200) * Added `Hyperf\Tracer\Aspect\GrpcAspect` (#6203) Co-authored-by: Deeka Wong <[email protected]> * Optimize the tracer component by replacing the direct instantiation with a closure at Context::getOrSet. (#6315) Co-authored-by: 李铭昕 <[email protected]> * Changed the `branch-alias` of all components to `3.1-dev`. (#6320) * Fixed bug that the jaeger cannot show the http code when using `tracer`. (#6321) Co-authored-by: 李铭昕 <[email protected]> * Use `Hyperf\Coroutine\Coroutine` instead of `Hyperf\Engine\Coroutine` (#6513) * Release v3.1.8 (#6515) Co-authored-by: Sharif <[email protected]> Co-authored-by: guandeng <[email protected]> Co-authored-by: Luffy <[email protected]> * Added default config of noop driver for `hyperf/opentracing`. (#6550) * fix: noop tracer test (#6552) * Fixed implicitly nullable params (#6616) * Format code by the latest `cs-fixer`. (#6617) * chore: Update phpstan.neon.dist to level 6 (#6780) Co-authored-by: 李铭昕 <[email protected]> * Added the request body and response body to the tracer (#6793) * Added composer.json normalize support (#6887) * Improve actions (#7088) * update github actions for all components. (#7090) * remove hyperf/utils compoent (#7411) * Fixed error versions for `hyperf/engine`. (#7429) * merge from main lib; resolving conflicts * bring recursive get root to TracerContext; resolving conflicts. * revert traceId with uuid creation; fix Typo; Removing workflow not needed; fix docblocks. * Fix Elasticsearch Typo (#7468) * fix import * fix http client aspect; fix import. * Update src/Aspect/HttpClientAspect.php Co-authored-by: Leonardo Teixeira <[email protected]> --------- Co-authored-by: Deeka Wong <[email protected]> Co-authored-by: 李铭昕 <[email protected]> Co-authored-by: 张城铭 <[email protected]> Co-authored-by: crayxn <[email protected]> Co-authored-by: Deeka Wong <[email protected]> Co-authored-by: 宣言就是Siam <[email protected]> Co-authored-by: lixinhan <[email protected]> Co-authored-by: CodeWay <[email protected]> Co-authored-by: Sharif <[email protected]> Co-authored-by: guandeng <[email protected]> Co-authored-by: Luffy <[email protected]> Co-authored-by: Weslen Teche <[email protected]> Co-authored-by: jonas-elias <[email protected]> Co-authored-by: Leonardo Teixeira <[email protected]>
1 parent c8ffef9 commit 00890fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1304
-254
lines changed

class_map/GlobalTracer.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf + OpenCodeCo
6+
*
7+
* @link https://opencodeco.dev
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
11+
*/
12+
13+
namespace OpenTracing;
14+
15+
use Hyperf\Tracer\TracerContext;
16+
17+
final class GlobalTracer
18+
{
19+
/**
20+
* @var Tracer
21+
*/
22+
private static $instance;
23+
24+
/**
25+
* @var bool
26+
*/
27+
private static $isRegistered = false;
28+
29+
/**
30+
* GlobalTracer::set sets the [singleton] Tracer returned by get().
31+
* Those who use GlobalTracer (rather than directly manage a Tracer instance)
32+
* should call GlobalTracer::set as early as possible in bootstrap, prior to
33+
* start a new span. Prior to calling GlobalTracer::set, any Spans started
34+
* via the `Tracer::startActiveSpan` (etc) globals are noops.
35+
*/
36+
public static function set(Tracer $tracer): void
37+
{
38+
TracerContext::setTracer($tracer);
39+
self::$isRegistered = true;
40+
}
41+
42+
/**
43+
* GlobalTracer::get returns the global singleton `Tracer` implementation.
44+
* Before `GlobalTracer::set` is called, the `GlobalTracer::get` is a noop
45+
* implementation that drops all data handed to it.
46+
*/
47+
public static function get(): Tracer
48+
{
49+
return TracerContext::getTracer();
50+
}
51+
52+
/**
53+
* Returns true if a global tracer has been registered, otherwise returns false.
54+
*/
55+
public static function isRegistered(): bool
56+
{
57+
return self::$isRegistered;
58+
}
59+
}

class_map/Map.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @contact [email protected]
1010
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
1111
*/
12+
1213
namespace Zipkin\Propagation;
1314

1415
use ArrayAccess;

class_map/ThriftUdpTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function loop(): void
173173
}
174174
$closure->call($this);
175175
} catch (Throwable $e) {
176-
$this->logger->error('ThriftUdpTransport error:' . $e->getMessage());
176+
$this->logger->error('ThriftUdpTransport error:' . $e->getMessage());
177177
@socket_close($this->socket);
178178
$this->socket = null;
179179
break;

composer.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@
1111
],
1212
"homepage": "https://hyperf.io",
1313
"support": {
14-
"docs": "https://hyperf.wiki",
1514
"issues": "https://github.com/hyperf/hyperf/issues",
16-
"pull-request": "https://github.com/hyperf/hyperf/pulls",
17-
"source": "https://github.com/hyperf/hyperf"
15+
"source": "https://github.com/hyperf/hyperf",
16+
"docs": "https://hyperf.wiki",
17+
"pull-request": "https://github.com/hyperf/hyperf/pulls"
1818
},
1919
"require": {
20-
"php": ">=8.0",
21-
"hyperf/contract": "^3.0",
22-
"hyperf/di": "^3.0",
23-
"hyperf/guzzle": "^3.0",
24-
"hyperf/support": "^3.0",
25-
"hyperf/utils": "^3.0",
20+
"php": ">=8.1",
21+
"hyperf/collection": "~3.1.0",
22+
"hyperf/context": "~3.1.0",
23+
"hyperf/contract": "~3.1.0",
24+
"hyperf/coordinator": "~3.1.0",
25+
"hyperf/coroutine": "~3.1.0",
26+
"hyperf/di": "~3.1.0",
27+
"hyperf/engine": "^2.0",
28+
"hyperf/guzzle": "~3.1.0",
29+
"hyperf/stringable": "~3.1.0",
30+
"hyperf/support": "~3.1.0",
2631
"jcchavezs/zipkin-opentracing": "^2.0",
2732
"jonahgeorge/jaeger-client-php": "^1.4",
2833
"opentracing/opentracing": "^1.0",
@@ -40,7 +45,8 @@
4045
},
4146
"suggest": {
4247
"hyperf/event": "Required to use DbQueryExecutedListener.",
43-
"jonahgeorge/jaeger-client-php": "Required (^0.6) to use jaeger tracing."
48+
"jonahgeorge/jaeger-client-php": "Required (^0.6) to use jaeger tracing.",
49+
"longlang/phpkafka": "Required (^1.2) to use Kafka Producer."
4450
},
4551
"autoload": {
4652
"psr-4": {
@@ -67,7 +73,7 @@
6773
},
6874
"extra": {
6975
"branch-alias": {
70-
"dev-master": "3.0-dev"
76+
"dev-master": "3.1-dev"
7177
},
7278
"hyperf": {
7379
"config": "Hyperf\\Tracer\\ConfigProvider"

publish/opentracing.php

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,74 @@
99
* @contact [email protected]
1010
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
1111
*/
12+
use Hyperf\Tracer\Adapter\JaegerTracerFactory;
13+
use Hyperf\Tracer\Adapter\NoopTracerFactory;
14+
use Hyperf\Tracer\Adapter\Reporter\Kafka;
15+
use Hyperf\Tracer\Adapter\ZipkinTracerFactory;
16+
use Zipkin\Reporters\Http;
17+
use Zipkin\Reporters\Noop;
1218
use Zipkin\Samplers\BinarySampler;
1319

1420
use function Hyperf\Support\env;
1521

1622
return [
23+
// To disable hyperf/opentracing temporarily, set default driver to noop.
1724
'default' => env('TRACER_DRIVER', 'zipkin'),
1825
'enable' => [
19-
'guzzle' => env('TRACER_ENABLE_GUZZLE', false),
20-
'redis' => env('TRACER_ENABLE_REDIS', false),
26+
'coroutine' => env('TRACER_ENABLE_COROUTINE', false),
2127
'db' => env('TRACER_ENABLE_DB', false),
22-
'method' => env('TRACER_ENABLE_METHOD', false),
28+
'elasticserach' => env('TRACER_ENABLE_ELASTICSERACH', false),
2329
'exception' => env('TRACER_ENABLE_EXCEPTION', false),
30+
'grpc' => env('TRACER_ENABLE_GRPC', false),
31+
'guzzle' => env('TRACER_ENABLE_GUZZLE', false),
32+
'method' => env('TRACER_ENABLE_METHOD', false),
33+
'redis' => env('TRACER_ENABLE_REDIS', false),
34+
'rpc' => env('TRACER_ENABLE_RPC', false),
35+
'ignore_exceptions' => [],
2436
],
2537
'tracer' => [
2638
'zipkin' => [
27-
'driver' => Hyperf\Tracer\Adapter\ZipkinTracerFactory::class,
39+
'driver' => ZipkinTracerFactory::class,
2840
'app' => [
2941
'name' => env('APP_NAME', 'skeleton'),
3042
// Hyperf will detect the system info automatically as the value if ipv4, ipv6, port is null
3143
'ipv4' => '127.0.0.1',
3244
'ipv6' => null,
3345
'port' => 9501,
3446
],
35-
'options' => [
36-
'endpoint_url' => env('ZIPKIN_ENDPOINT_URL', 'http://localhost:9411/api/v2/spans'),
37-
'timeout' => env('ZIPKIN_TIMEOUT', 1),
47+
'reporter' => env('ZIPKIN_REPORTER', 'http'), // kafka, http
48+
'reporters' => [
49+
// options for http reporter
50+
'http' => [
51+
'class' => Http::class,
52+
'constructor' => [
53+
'options' => [
54+
'endpoint_url' => env('ZIPKIN_ENDPOINT_URL', 'http://localhost:9411/api/v2/spans'),
55+
'timeout' => env('ZIPKIN_TIMEOUT', 1),
56+
],
57+
],
58+
],
59+
// options for kafka reporter
60+
'kafka' => [
61+
'class' => Kafka::class,
62+
'constructor' => [
63+
'options' => [
64+
'topic' => env('ZIPKIN_KAFKA_TOPIC', 'zipkin'),
65+
'bootstrap_servers' => env('ZIPKIN_KAFKA_BOOTSTRAP_SERVERS', '127.0.0.1:9092'),
66+
'acks' => (int) env('ZIPKIN_KAFKA_ACKS', -1),
67+
'connect_timeout' => (int) env('ZIPKIN_KAFKA_CONNECT_TIMEOUT', 1),
68+
'send_timeout' => (int) env('ZIPKIN_KAFKA_SEND_TIMEOUT', 1),
69+
],
70+
],
71+
],
72+
'noop' => [
73+
'class' => Noop::class,
74+
],
3875
],
3976
'sampler' => BinarySampler::createAsAlwaysSample(),
4077
],
4178
'jaeger' => [
42-
'driver' => Hyperf\Tracer\Adapter\JaegerTracerFactory::class,
79+
'driver' => JaegerTracerFactory::class,
4380
'name' => env('APP_NAME', 'skeleton'),
4481
'options' => [
4582
/*
@@ -58,6 +95,9 @@
5895
],
5996
],
6097
],
98+
'noop' => [
99+
'driver' => NoopTracerFactory::class,
100+
],
61101
],
62102
'tags' => [
63103
'http_client' => [
@@ -82,14 +122,21 @@
82122
],
83123
'request' => [
84124
'path' => 'request.path',
125+
'uri' => 'request.uri',
85126
'method' => 'request.method',
86127
'header' => 'request.header',
128+
// 'body' => 'request.body',
87129
],
88130
'coroutine' => [
89131
'id' => 'coroutine.id',
90132
],
91133
'response' => [
92134
'status_code' => 'response.status_code',
135+
// 'body' => 'response.body',
136+
],
137+
'rpc' => [
138+
'path' => 'rpc.path',
139+
'status' => 'rpc.status',
93140
],
94141
],
95142
];

src/Adapter/HttpClientFactory.php

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,12 @@
99
* @contact [email protected]
1010
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
1111
*/
12-
namespace Hyperf\Tracer\Adapter;
1312

14-
use Hyperf\Guzzle\ClientFactory as GuzzleClientFactory;
15-
use RuntimeException;
16-
use Zipkin\Reporters\Http\ClientFactory;
13+
namespace Hyperf\Tracer\Adapter;
1714

18-
class HttpClientFactory implements ClientFactory
15+
/**
16+
* @deprecated v3.0, will remove in v3.1, use \Hyperf\Tracer\Adapter\Reporter\HttpClientFactory instead.
17+
*/
18+
class HttpClientFactory extends Reporter\HttpClientFactory
1919
{
20-
public function __construct(private GuzzleClientFactory $guzzleClientFactory)
21-
{
22-
}
23-
24-
public function build(array $options): callable
25-
{
26-
return function (string $payload) use ($options): void {
27-
$url = $options['endpoint_url'];
28-
unset($options['endpoint_url']);
29-
$client = $this->guzzleClientFactory->create($options);
30-
$additionalHeaders = $options['headers'] ?? [];
31-
$requiredHeaders = [
32-
'Content-Type' => 'application/json',
33-
'Content-Length' => strlen($payload),
34-
'b3' => '0',
35-
];
36-
$headers = array_merge($additionalHeaders, $requiredHeaders);
37-
$response = $client->post($url, [
38-
'body' => $payload,
39-
'headers' => $headers,
40-
// If 'no_aspect' option is true, then the HttpClientAspect will not modify the client options.
41-
'no_aspect' => true,
42-
]);
43-
$statusCode = $response->getStatusCode();
44-
if ($statusCode !== 202) {
45-
throw new RuntimeException(
46-
sprintf('Reporting of spans failed, status code %d', $statusCode)
47-
);
48-
}
49-
};
50-
}
5120
}

src/Adapter/NoOpTracerFactory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
13+
namespace Hyperf\Tracer\Adapter;
14+
15+
use Hyperf\Tracer\Contract\NamedFactoryInterface;
16+
use OpenTracing\NoopTracer;
17+
use OpenTracing\Tracer;
18+
19+
class NoOpTracerFactory implements NamedFactoryInterface
20+
{
21+
public function make(string $name): Tracer
22+
{
23+
return new NoopTracer();
24+
}
25+
}

src/Adapter/NoopTracerFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @contact [email protected]
1010
* @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
1111
*/
12+
1213
namespace Hyperf\Tracer\Adapter;
1314

1415
use Hyperf\Tracer\Contract\NamedFactoryInterface;

0 commit comments

Comments
 (0)