declare(strict_types=1); if (!function_exists('\\OpenTelemetry\\Instrumentation\\hook')) { return; } if (!class_exists('\\OpenTelemetry\\API\\Globals')) { return; } use OpenTelemetry\API\Context\Context; use OpenTelemetry\API\Globals; use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\API\Trace\Span; use OpenTelemetry\Instrumentation\hook; final class Protero_Otel_Redis { private static array $scopes = []; private static array $methods = [ 'get', 'set', 'setex', 'setnx', 'getSet', 'mget', 'mset', 'msetnx', 'delete', 'del', 'exists', 'expire', 'pexpire', 'ttl', 'pttl', 'incr', 'incrBy', 'decr', 'decrBy', 'hGet', 'hSet', 'hGetAll', 'hDel', 'hExists', 'sAdd', 'sRem', 'sMembers', 'sIsMember', 'zAdd', 'zRange', 'zRevRange', 'zRem', 'lPush', 'rPush', 'lPop', 'rPop', 'lRange', 'eval', 'evalSha', ]; public static function register(): void { foreach (self::$methods as $method) { hook( \Redis::class, $method, pre: static function ( \Redis $redis, array $params, string $class, string $function ): void { self::start($redis, $function, $params); }, post: static function ( \Redis $redis, array $params, mixed $returnValue, ?\Throwable $exception, string $class = '', string $function = '' ): void { self::finish($redis, $function, $exception); } ); } } private static function start( \Redis $redis, string $method, array $params ): void { $tracer = Globals::tracerProvider() ->getTracer('protero.redis'); $operation = strtoupper($method); $span = $tracer ->spanBuilder('redis ' . $operation) ->startSpan(); $span->setAttribute('db.system', 'redis'); $span->setAttribute('db.operation.name', strtoupper($method)); $span->setAttribute('server.address', '/run/valkey/valkey.sock'); $span->setAttribute('network.transport', 'unix'); $span->setAttribute('db.namespace', '1'); // Aggregate metadata only. Never record keys, values, or arguments. $span->setAttribute('db.redis.argument_count', count($params)); $scope = $span->storeInContext(Context::getCurrent()); Context::storage()->attach($scope); $id = spl_object_id($redis) . ':' . $method; self::$scopes[$id][] = [$span, $scope]; } private static function finish( \Redis $redis, string $method, ?\Throwable $exception ): void { $id = spl_object_id($redis) . ':' . $method; if (empty(self::$scopes[$id])) { return; } [$span, $scope] = array_pop(self::$scopes[$id]); $scope->detach(); if ($exception !== null) { $span->recordException($exception); $span->setStatus(StatusCode::STATUS_ERROR); } $span->end(); } } Protero_Otel_Redis::register(); 790 – PROTERO

Viser alle 2 resultater

-25%
Opprinnelig pris var: kr 5 900,00.Nåværende pris er: kr 4 425,00. Ink. mva
Sammenlign
-25%
Opprinnelig pris var: kr 5 900,00.Nåværende pris er: kr 4 425,00. Ink. mva
Sammenlign