Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 ? $request->getMethod() : '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)
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
Loading