Skip to content

Commit

Permalink
Merge branch 'master' into 3.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/redis/composer.json
#	src/validation/tests/Cases/ValidateAttributesTest.php
  • Loading branch information
limingxinleo committed Sep 14, 2023
2 parents 8e7abb6 + b56efa0 commit 2a971d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions publish/opentracing.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'db' => env('TRACER_ENABLE_DB', false),
'method' => env('TRACER_ENABLE_METHOD', false),
'exception' => env('TRACER_ENABLE_EXCEPTION', false),
'ignore_exceptions' => [],
],
'tracer' => [
'zipkin' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/RequestTraceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function handleRequestTerminated(RequestTerminated $event): void
$span = TracerContext::getRoot();
$span->setTag($this->spanTagManager->get('response', 'status_code'), $response->getStatusCode());

if ($event->exception && $this->switchManager->isEnable('exception')) {
if ($event->exception && $this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($event->exception::class)) {
$this->appendExceptionToSpan($span, $exception = $event->exception);

if ($exception instanceof HttpException) {
Expand Down
4 changes: 3 additions & 1 deletion src/Middleware/TraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
$span->setTag($this->spanTagManager->get('response', 'status_code'), $response->getStatusCode());
} catch (Throwable $exception) {
$this->switchManager->isEnable('exception') && $this->appendExceptionToSpan($span, $exception);
if ($this->switchManager->isEnable('exception') && ! $this->switchManager->isIgnoreException($exception::class)) {
$this->appendExceptionToSpan($span, $exception);
}
if ($exception instanceof HttpException) {
$span->setTag($this->spanTagManager->get('response', 'status_code'), $exception->getStatusCode());
}
Expand Down
12 changes: 12 additions & 0 deletions src/SwitchManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SwitchManager
// beta feature, please don't enable 'method' in production environment
'method' => false,
'error' => false,
'ignore_exceptions' => [],
];

/**
Expand All @@ -48,4 +49,15 @@ public function isEnable(string $identifier): bool

return $this->config[$identifier] && Context::get('tracer.root') instanceof Span;
}

public function isIgnoreException(string $className): bool
{
$ignoreExceptions = $this->config['ignore_exceptions'] ?? [];
foreach ($ignoreExceptions as $ignoreException) {
if (is_a($className, $ignoreException, true)) {
return true;
}
}
return false;
}
}

0 comments on commit 2a971d8

Please sign in to comment.