diff --git a/src/Instrumentation/CodeIgniter/src/CodeIgniterInstrumentation.php b/src/Instrumentation/CodeIgniter/src/CodeIgniterInstrumentation.php index 5508ae0d0..04acea57d 100644 --- a/src/Instrumentation/CodeIgniter/src/CodeIgniterInstrumentation.php +++ b/src/Instrumentation/CodeIgniter/src/CodeIgniterInstrumentation.php @@ -20,7 +20,10 @@ class CodeIgniterInstrumentation { public const NAME = 'codeigniter'; - + + // Store the HTTP method for use in the post hook + private static $httpMethod = 'unknown'; + /** @psalm-api */ public static function register(): void { @@ -58,12 +61,14 @@ public static function register(): void ) use ($instrumentation, $requestProperty): void { $extractedRequest = $requestProperty->getValue($igniter); $request = ($extractedRequest instanceof RequestInterface) ? $extractedRequest : null; - + + // Get the HTTP method from the request and store it for later use + self::$httpMethod = $request?->getMethod() ?? $_SERVER['REQUEST_METHOD'] ?? 'unknown'; /** @psalm-suppress ArgumentTypeCoercion,DeprecatedMethod */ $spanBuilder = $instrumentation ->tracer() /** @phan-suppress-next-line PhanDeprecatedFunction */ - ->spanBuilder(\sprintf('%s', $request?->getMethod() ?? 'unknown')) + ->spanBuilder(\sprintf('%s', self::$httpMethod)) ->setSpanKind(SpanKind::KIND_SERVER) ->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function)) ->setAttribute(TraceAttributes::CODE_FILE_PATH, $filename) @@ -147,6 +152,7 @@ public static function register(): void if ($controllerClassName !== null && is_string($controllerMethod)) { $routeName = CodeIgniterInstrumentation::normalizeRouteName($controllerClassName, $controllerMethod); $span->setAttribute(TraceAttributes::HTTP_ROUTE, $routeName); + $span->updateName(sprintf('%s %s', self::$httpMethod, $routeName)); } if ($exception) { diff --git a/src/Instrumentation/CodeIgniter/tests/Integration/CodeIgniterInstrumentationTest.php b/src/Instrumentation/CodeIgniter/tests/Integration/CodeIgniterInstrumentationTest.php index 5512397f8..39f254031 100644 --- a/src/Instrumentation/CodeIgniter/tests/Integration/CodeIgniterInstrumentationTest.php +++ b/src/Instrumentation/CodeIgniter/tests/Integration/CodeIgniterInstrumentationTest.php @@ -25,7 +25,7 @@ public function test_success() $attributes = $this->storage[0]->getAttributes(); $this->assertCount(1, $this->storage); - $this->assertEqualsIgnoringCase('GET', $this->storage[0]->getName()); + $this->assertEqualsIgnoringCase('GET Home.index', $this->storage[0]->getName()); $this->assertStringMatchesFormat('http://%s/home', $attributes->get(TraceAttributes::URL_FULL)); $this->assertEqualsIgnoringCase('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD)); $this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME)); @@ -55,7 +55,7 @@ public function test_exception() $attributes = $this->storage[0]->getAttributes(); $this->assertCount(1, $this->storage); - $this->assertEqualsIgnoringCase('GET', $this->storage[0]->getName()); + $this->assertEqualsIgnoringCase('GET Closure.index', $this->storage[0]->getName()); $this->assertStringMatchesFormat('http://%s/exception', $attributes->get(TraceAttributes::URL_FULL)); $this->assertEqualsIgnoringCase('GET', $attributes->get(TraceAttributes::HTTP_REQUEST_METHOD)); $this->assertEquals('http', $attributes->get(TraceAttributes::URL_SCHEME));