Skip to content

Commit 0e5ac07

Browse files
Reasnolimingxinleo
andauthored
fix: log and tag Throwable in a span (#3011)
* fix: log and tag Throwable in a span * Update CHANGELOG-2.0.md Co-authored-by: 李铭昕 <715557344@qq.com>
1 parent adbf877 commit 0e5ac07

5 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/Aspect/HttpClientAspect.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
9797
if ($result instanceof ResponseInterface) {
9898
$span->setTag($this->spanTagManager->get('http_client', 'http.status_code'), $result->getStatusCode());
9999
}
100+
} catch (\Throwable $e) {
101+
$span->setTag('error', true);
102+
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
103+
throw $e;
100104
} finally {
101105
$span->finish();
102106
}

src/Aspect/JsonRpcAspect.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
9292
if ($proceedingJoinPoint->methodName === 'send') {
9393
try {
9494
$result = $proceedingJoinPoint->process();
95+
} catch (\Throwable $e) {
96+
if ($span = CT::get('tracer.span.' . static::class)) {
97+
$span->setTag('error', true);
98+
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
99+
CT::set('tracer.span.' . static::class, $span);
100+
}
101+
throw $e;
95102
} finally {
96103
/** @var Span $span */
97104
if ($span = CT::get('tracer.span.' . static::class)) {

src/Aspect/MethodAspect.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
6060
$span = $this->startSpan($key);
6161
try {
6262
$result = $proceedingJoinPoint->process();
63+
} catch (\Throwable $e) {
64+
$span->setTag('error', true);
65+
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
66+
throw $e;
6367
} finally {
6468
$span->finish();
6569
}

src/Aspect/RedisAspect.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
7777
try {
7878
$result = $proceedingJoinPoint->process();
7979
$span->setTag($this->spanTagManager->get('redis', 'result'), json_encode($result));
80+
} catch (\Throwable $e) {
81+
$span->setTag('error', true);
82+
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
83+
throw $e;
8084
} finally {
8185
$span->finish();
8286
}

src/Aspect/TraceAnnotationAspect.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)
6060
$span->setTag($tag, $source);
6161
try {
6262
$result = $proceedingJoinPoint->process();
63+
} catch (\Throwable $e) {
64+
$span->setTag('error', true);
65+
$span->log(['message', $e->getMessage(), 'code' => $e->getCode(), 'stacktrace' => $e->getTraceAsString()]);
66+
throw $e;
6367
} finally {
6468
$span->finish();
6569
}

0 commit comments

Comments
 (0)