Skip to content

Commit

Permalink
Fixed bug that the jaeger cannot show the http code when using `trace…
Browse files Browse the repository at this point in the history
…r`. (#6321)


Co-authored-by: 李铭昕 <[email protected]>
  • Loading branch information
codesway and limingxinleo authored Nov 24, 2023
1 parent c01f1de commit 751e900
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Aspect/HttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
try {
$result = $proceedingJoinPoint->process();
if ($result instanceof ResponseInterface) {
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode());
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), (string) $result->getStatusCode());
}
} catch (Throwable $e) {
if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($e)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/RequestTraceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function handleRequestTerminated(RequestTerminated $event): void

$tracer = TracerContext::getTracer();
$span = TracerContext::getRoot();
$span->setTag($this->spanTagManager->get('response', 'status_code'), $response->getStatusCode());
$span->setTag($this->spanTagManager->get('response', 'status_code'), (string) $response->getStatusCode());

if ($event->exception && $this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($event->exception)) {
$this->appendExceptionToSpan($span, $exception = $event->exception);
Expand All @@ -93,7 +93,7 @@ protected function appendExceptionToSpan(Span $span, Throwable $exception): void
{
$span->setTag('error', true);
$span->setTag($this->spanTagManager->get('exception', 'class'), get_class($exception));
$span->setTag($this->spanTagManager->get('exception', 'code'), $exception->getCode());
$span->setTag($this->spanTagManager->get('exception', 'code'), (string) $exception->getCode());
$span->setTag($this->spanTagManager->get('exception', 'message'), $exception->getMessage());
$span->setTag($this->spanTagManager->get('exception', 'stack_trace'), (string) $exception);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if ($traceId = TracerContext::getTraceId()) {
$response = $response->withHeader('Trace-Id', $traceId);
}
$span->setTag($this->spanTagManager->get('response', 'status_code'), $response->getStatusCode());
$span->setTag($this->spanTagManager->get('response', 'status_code'), (string) $response->getStatusCode());
} catch (Throwable $exception) {
if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($exception)) {
$this->appendExceptionToSpan($span, $exception);
}
if ($exception instanceof HttpException) {
$span->setTag($this->spanTagManager->get('response', 'status_code'), $exception->getStatusCode());
$span->setTag($this->spanTagManager->get('response', 'status_code'), (string) $exception->getStatusCode());
}
throw $exception;
} finally {
Expand All @@ -76,7 +76,7 @@ protected function appendExceptionToSpan(Span $span, Throwable $exception): void
{
$span->setTag('error', true);
$span->setTag($this->spanTagManager->get('exception', 'class'), get_class($exception));
$span->setTag($this->spanTagManager->get('exception', 'code'), $exception->getCode());
$span->setTag($this->spanTagManager->get('exception', 'code'), (string) $exception->getCode());
$span->setTag($this->spanTagManager->get('exception', 'message'), $exception->getMessage());
$span->setTag($this->spanTagManager->get('exception', 'stack_trace'), (string) $exception);
}
Expand Down

0 comments on commit 751e900

Please sign in to comment.