Skip to content

Commit

Permalink
fix: log and tag Throwable in a span (#3011)
Browse files Browse the repository at this point in the history
* fix: log and tag Throwable in a span

* Update CHANGELOG-2.0.md

Co-authored-by: 李铭昕 <[email protected]>
  • Loading branch information
Reasno and limingxinleo committed Dec 27, 2020
1 parent adbf877 commit 0e5ac07
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Aspect/HttpClientAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
if ($result instanceof ResponseInterface) {
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode());
}
} catch (\Throwable $e) {
$span->setTag('error', true);
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
throw $e;
} finally {
$span->finish();
}
Expand Down
7 changes: 7 additions & 0 deletions src/Aspect/JsonRpcAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
if ($proceedingJoinPoint->methodName === 'send') {
try {
$result = $proceedingJoinPoint->process();
} catch (\Throwable $e) {
if ($span = CT::get('tracer.span.' . static::class)) {
$span->setTag('error', true);
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
CT::set('tracer.span.' . static::class, $span);
}
throw $e;
} finally {
/** @var Span $span */
if ($span = CT::get('tracer.span.' . static::class)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Aspect/MethodAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$span = $this->startSpan($key);
try {
$result = $proceedingJoinPoint->process();
} catch (\Throwable $e) {
$span->setTag('error', true);
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
throw $e;
} finally {
$span->finish();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Aspect/RedisAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
try {
$result = $proceedingJoinPoint->process();
$span->setTag($this->spanTagManager->get('redis', 'result'), json_encode($result));
} catch (\Throwable $e) {
$span->setTag('error', true);
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
throw $e;
} finally {
$span->finish();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Aspect/TraceAnnotationAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
$span->setTag($tag, $source);
try {
$result = $proceedingJoinPoint->process();
} catch (\Throwable $e) {
$span->setTag('error', true);
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
throw $e;
} finally {
$span->finish();
}
Expand Down

0 comments on commit 0e5ac07

Please sign in to comment.