Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"hyperf/redis": "~3.1.0",
"hyperf/rpc": "~3.1.0",
"hyperf/rpc-client": "~3.1.0",
"hyperf/rpc-multiplex": "~3.1.0",
"hyperf/rpc-server": "~3.1.0",
"hyperf/scout": "~3.1.0",
"hyperf/session": "~3.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"hyperf/amqp": "Required to use the amqp event (~3.1.9).",
"hyperf/crontab": "Required to use the crontab event (~3.1.7).",
"hyperf/database": "Required to use the crontab event (~3.1.0).",
"hyperf/rpc-multiplex": "Required to use the rpc tracing (~3.1.0).",
"phpmyadmin/sql-parser": "Required to use the sql parser (^5.9)."
},
"minimum-stability": "dev",
Expand Down
1 change: 1 addition & 0 deletions src/sentry/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __invoke(): array
Tracing\Aspect\GuzzleHttpClientAspect::class,
Tracing\Aspect\KafkaProducerAspect::class,
Tracing\Aspect\RpcAspect::class,
Tracing\Aspect\RpcEndpointAspect::class,
Tracing\Aspect\RedisAspect::class,
Tracing\Aspect\TraceAnnotationAspect::class,
Tracing\Aspect\ViewRenderAspect::class,
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Constants
{
public const TRACE_CARRIER = 'sentry.tracing.trace_carrier';

public const TRACE_RPC_SERVER_ADDRESS = 'sentry.tracing.rpc.server.address';

public const TRACE_RPC_SERVER_PORT = 'sentry.tracing.rpc.server.port';

public const CRON_CHECKIN_ID = 'sentry.crons.checkin_id';

public const DISABLE_COROUTINE_TRACING = 'sentry.tracing.disable_coroutine_tracing';
Expand Down
11 changes: 9 additions & 2 deletions src/sentry/src/Tracing/Aspect/RpcAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private function handleGenerateRpcPath(ProceedingJoinPoint $proceedingJoinPoint)
default => 'rpc',
};

// https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-spans.md
Context::set(static::SPAN_CONTEXT, SpanContext::make()
->setOp('rpc.client')
->setDescription($path)
Expand Down Expand Up @@ -112,8 +113,14 @@ function (Scope $scope) use ($proceedingJoinPoint) {
$rpcCtx->set(Constants::TRACE_CARRIER, $carrier->toJson());
}
return tap($proceedingJoinPoint->process(), function ($result) use ($span) {
if ($span && $this->feature->isTracingTagEnabled('rpc.result')) {
$span->setData(['rpc.result' => $result]);
if ($this->feature->isTracingTagEnabled('rpc.result')) {
$span?->setData(['rpc.result' => $result]);
}
if (Context::has(Constants::TRACE_RPC_SERVER_ADDRESS)) {
$span?->setData([
'server.address' => Context::get(Constants::TRACE_RPC_SERVER_ADDRESS),
'server.port' => Context::get(Constants::TRACE_RPC_SERVER_PORT),
]);
}
});
},
Expand Down
37 changes: 37 additions & 0 deletions src/sentry/src/Tracing/Aspect/RpcEndpointAspect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact huangdijia@gmail.com
*/

namespace FriendsOfHyperf\Sentry\Tracing\Aspect;

use FriendsOfHyperf\Sentry\Constants;
use Hyperf\Context\Context;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Hyperf\RpcMultiplex\Socket;

use function Hyperf\Tappable\tap;

class RpcEndpointAspect extends AbstractAspect
{
public array $classes = [
\Hyperf\RpcMultiplex\SocketFactory::class . '::get',
];

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
return tap($proceedingJoinPoint->process(), function ($socket) {
if ($socket instanceof Socket) {
Context::set(Constants::TRACE_RPC_SERVER_ADDRESS, $socket->getName());
Context::set(Constants::TRACE_RPC_SERVER_PORT, $socket->getPort());
}
});
}
}