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 src/sentry/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __invoke(): array
Tracing\Aspect\CoordinatorAspect::class,
Tracing\Aspect\CoroutineAspect::class,
Tracing\Aspect\DbAspect::class,
Tracing\Aspect\DbConnectionAspect::class,
Tracing\Aspect\ElasticsearchAspect::class,
Tracing\Aspect\ElasticsearchRequestAspect::class,
Tracing\Aspect\FilesystemAspect::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_DB_SERVER_ADDRESS = 'sentry.tracing.db.server.address';

public const TRACE_DB_SERVER_PORT = 'sentry.tracing.db.server.port';

public const TRACE_REDIS_SERVER_ADDRESS = 'sentry.tracing.redis.server.address';

public const TRACE_REDIS_SERVER_PORT = 'sentry.tracing.redis.server.port';
Expand Down
42 changes: 42 additions & 0 deletions src/sentry/src/Tracing/Aspect/DbConnectionAspect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 PDO;

use function Hyperf\Tappable\tap;

class DbConnectionAspect extends AbstractAspect
{
public array $classes = [
'Hyperf\Database\Connection::getPdoForSelect',
'Hyperf\Database\Connection::getPdo',
];

public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
return tap($proceedingJoinPoint->process(), function ($pdo) {
Context::getOrSet(self::class, function () use ($pdo) {
$connectionStatus = $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);
[$host] = explode(' ', $connectionStatus);

Context::set(Constants::TRACE_DB_SERVER_ADDRESS, $host);

return true;
});
});
}
}
2 changes: 2 additions & 0 deletions src/sentry/src/Tracing/Listener/EventHandleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ protected function handleDbQueryExecuted(DbEvent\QueryExecuted $event): void
'db.pool.max_idle_time' => $pool->getOption()->getMaxIdleTime(),
'db.pool.idle' => $pool->getConnectionsInChannel(),
'db.pool.using' => $pool->getCurrentConnections(),
'server.address' => (string) Context::get(Constants::TRACE_DB_SERVER_ADDRESS, 'localhost'),
'server.port' => (int) Context::get(Constants::TRACE_DB_SERVER_PORT, 3306),
];

if ($this->feature->isTracingTagEnabled('db.sql.bindings', true)) {
Expand Down