Skip to content

Commit ae8c2ac

Browse files
authored
fix: status_code as integer in metrics (#4)
1 parent 05d2280 commit ae8c2ac

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Middleware/MetricMiddleware.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3636
try {
3737
$response = $handler->handle($request);
3838

39-
$attributes[HttpAttributes::HTTP_RESPONSE_STATUS_CODE] = (string) $response->getStatusCode();
39+
$attributes[HttpAttributes::HTTP_RESPONSE_STATUS_CODE] = $response->getStatusCode();
4040

4141
return $response;
4242
} catch (Throwable $exception) {
4343
$attributes[ErrorAttributes::ERROR_TYPE] = get_class($exception);
44-
$attributes[HttpAttributes::HTTP_RESPONSE_STATUS_CODE] = '500';
44+
$attributes[HttpAttributes::HTTP_RESPONSE_STATUS_CODE] = 500;
4545

4646
throw $exception;
4747
} finally {

tests/Unit/Middleware/MetricMiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testProcessWithSuccessfulRequest(): void
8383
$expectedAttributes = [
8484
HttpAttributes::HTTP_ROUTE => '/users/{number}',
8585
HttpAttributes::HTTP_REQUEST_METHOD => 'GET',
86-
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => '200',
86+
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 200,
8787
];
8888

8989
$this->histogram->expects($this->once())
@@ -169,7 +169,7 @@ public function testProcessWithException(): void
169169
HttpAttributes::HTTP_ROUTE => $path,
170170
HttpAttributes::HTTP_REQUEST_METHOD => $method,
171171
ErrorAttributes::ERROR_TYPE => RuntimeException::class,
172-
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => '500',
172+
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 500,
173173
]
174174
);
175175

tests/Unit/Middleware/TraceMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testProcessWithSuccessfulRequest(): void
159159
$spanScope->expects($this->once())
160160
->method('setAttributes')
161161
->with([
162-
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => '200',
162+
HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 200,
163163
HttpIncubatingAttributes::HTTP_RESPONSE_BODY_SIZE => '1024',
164164
'http.response.header.content-type' => 'application/json',
165165
'http.response.header.content-length' => '1024',

tests/Unit/Support/SpanScopeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testSetAttributes(): void
9696

9797
$spanScope = new SpanScope($spanMock, $scopeMock, $contextMock);
9898

99-
$attributes = [HttpAttributes::HTTP_RESPONSE_STATUS_CODE => '200'];
99+
$attributes = [HttpAttributes::HTTP_RESPONSE_STATUS_CODE => 200];
100100

101101
$spanMock->expects($this->once())->method('setAttributes')->with($attributes)->willReturnSelf();
102102

0 commit comments

Comments
 (0)