diff --git a/src/sentry/src/ConfigProvider.php b/src/sentry/src/ConfigProvider.php index e9c1efe0e..5a24ed040 100644 --- a/src/sentry/src/ConfigProvider.php +++ b/src/sentry/src/ConfigProvider.php @@ -41,6 +41,7 @@ public function __invoke(): array Tracing\Aspect\KafkaProducerAspect::class, Tracing\Aspect\RpcAspect::class, Tracing\Aspect\RpcEndpointAspect::class, + Tracing\Aspect\RedisConnectionAspect::class, Tracing\Aspect\RedisAspect::class, Tracing\Aspect\TraceAnnotationAspect::class, Tracing\Aspect\ViewRenderAspect::class, diff --git a/src/sentry/src/Constants.php b/src/sentry/src/Constants.php index a2d937381..40e8dff2a 100644 --- a/src/sentry/src/Constants.php +++ b/src/sentry/src/Constants.php @@ -15,6 +15,10 @@ class Constants { public const TRACE_CARRIER = 'sentry.tracing.trace_carrier'; + public const TRACE_REDIS_SERVER_ADDRESS = 'sentry.tracing.redis.server.address'; + + public const TRACE_REDIS_SERVER_PORT = 'sentry.tracing.redis.server.port'; + public const TRACE_RPC_SERVER_ADDRESS = 'sentry.tracing.rpc.server.address'; public const TRACE_RPC_SERVER_PORT = 'sentry.tracing.rpc.server.port'; diff --git a/src/sentry/src/Tracing/Aspect/RedisConnectionAspect.php b/src/sentry/src/Tracing/Aspect/RedisConnectionAspect.php new file mode 100644 index 000000000..9763e67fa --- /dev/null +++ b/src/sentry/src/Tracing/Aspect/RedisConnectionAspect.php @@ -0,0 +1,45 @@ +process(), function ($result) use ($proceedingJoinPoint) { + $redisConnection = $proceedingJoinPoint->getInstance(); + $connection = (fn () => $this->connection ?? null)->call($redisConnection); + + if ($connection instanceof Redis) { // Redis or RedisSentinel + Context::set(Constants::TRACE_REDIS_SERVER_ADDRESS, $connection->getHost()); + Context::set(Constants::TRACE_REDIS_SERVER_PORT, $connection->getPort()); + } + + if ($connection instanceof RedisCluster) { // RedisCluster + // TODO: support RedisCluster + } + }); + } +} diff --git a/src/sentry/src/Tracing/Listener/EventHandleListener.php b/src/sentry/src/Tracing/Listener/EventHandleListener.php index 490b3b993..0a4159229 100644 --- a/src/sentry/src/Tracing/Listener/EventHandleListener.php +++ b/src/sentry/src/Tracing/Listener/EventHandleListener.php @@ -497,6 +497,8 @@ function (Scope $scope) use ($event) { 'db.redis.pool.idle' => $pool->getConnectionsInChannel(), 'db.redis.pool.using' => $pool->getCurrentConnections(), 'duration' => $event->time * 1000, + 'server.address' => (string) Context::get(Constants::TRACE_REDIS_SERVER_ADDRESS, 'localhost'), + 'server.port' => (int) Context::get(Constants::TRACE_REDIS_SERVER_PORT, 6379), ]) ->setStartTimestamp(microtime(true) - $event->time / 1000) );