|
20 | 20 | class CodeIgniterInstrumentation |
21 | 21 | { |
22 | 22 | public const NAME = 'codeigniter'; |
23 | | - |
| 23 | + |
| 24 | + // Store the HTTP method for use in the post hook |
| 25 | + private static $httpMethod = 'unknown'; |
| 26 | + |
24 | 27 | /** @psalm-api */ |
25 | 28 | public static function register(): void |
26 | 29 | { |
@@ -58,12 +61,14 @@ public static function register(): void |
58 | 61 | ) use ($instrumentation, $requestProperty): void { |
59 | 62 | $extractedRequest = $requestProperty->getValue($igniter); |
60 | 63 | $request = ($extractedRequest instanceof RequestInterface) ? $extractedRequest : null; |
61 | | - |
| 64 | + |
| 65 | + // Get the HTTP method from the request and store it for later use |
| 66 | + self::$httpMethod = $request?->getMethod() ?? $_SERVER['REQUEST_METHOD'] ?? 'unknown'; |
62 | 67 | /** @psalm-suppress ArgumentTypeCoercion,DeprecatedMethod */ |
63 | 68 | $spanBuilder = $instrumentation |
64 | 69 | ->tracer() |
65 | 70 | /** @phan-suppress-next-line PhanDeprecatedFunction */ |
66 | | - ->spanBuilder(\sprintf('%s', $request?->getMethod() ?? 'unknown')) |
| 71 | + ->spanBuilder(\sprintf('%s', self::$httpMethod)) |
67 | 72 | ->setSpanKind(SpanKind::KIND_SERVER) |
68 | 73 | ->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, sprintf('%s::%s', $class, $function)) |
69 | 74 | ->setAttribute(TraceAttributes::CODE_FILE_PATH, $filename) |
@@ -147,6 +152,7 @@ public static function register(): void |
147 | 152 | if ($controllerClassName !== null && is_string($controllerMethod)) { |
148 | 153 | $routeName = CodeIgniterInstrumentation::normalizeRouteName($controllerClassName, $controllerMethod); |
149 | 154 | $span->setAttribute(TraceAttributes::HTTP_ROUTE, $routeName); |
| 155 | + $span->updateName(sprintf('%s %s', self::$httpMethod, $routeName)); |
150 | 156 | } |
151 | 157 |
|
152 | 158 | if ($exception) { |
|
0 commit comments