Skip to content

Commit c435545

Browse files
authored
Add ignore path capability (#20)
Add ignore_path configuration
1 parent dbc5b40 commit c435545

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Middleware/MetricMiddleware.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Hyperf\Metric\Middleware;
1313

14+
use Hyperf\Contract\ConfigInterface;
1415
use Hyperf\HttpServer\Router\Dispatched;
1516
use Hyperf\Metric\Metric;
1617
use Hyperf\Metric\Support\Uri;
@@ -23,6 +24,14 @@
2324

2425
class MetricMiddleware implements MiddlewareInterface
2526
{
27+
protected array $config;
28+
29+
public function __construct(
30+
ConfigInterface $config,
31+
) {
32+
$this->config = $config->get('metric');
33+
}
34+
2635
/**
2736
* Process an incoming server request.
2837
* Processes an incoming server request in order to produce a response.
@@ -31,6 +40,10 @@ class MetricMiddleware implements MiddlewareInterface
3140
*/
3241
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
3342
{
43+
if (! empty($this->config['ignore_path']) && preg_match($this->config['ignore_path'], $request->getUri()->getPath())) {
44+
return $handler->handle($request);
45+
}
46+
3447
$labels = [
3548
'request_status' => '500',
3649
'request_path' => $this->getPath($request),

0 commit comments

Comments
 (0)