Skip to content

Commit

Permalink
Add ignore path capability (#20)
Browse files Browse the repository at this point in the history
Add ignore_path configuration
  • Loading branch information
flavioheleno authored Oct 10, 2024
1 parent dbc5b40 commit c435545
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Middleware/MetricMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
namespace Hyperf\Metric\Middleware;

use Hyperf\Contract\ConfigInterface;
use Hyperf\HttpServer\Router\Dispatched;
use Hyperf\Metric\Metric;
use Hyperf\Metric\Support\Uri;
Expand All @@ -23,6 +24,14 @@

class MetricMiddleware implements MiddlewareInterface
{
protected array $config;

public function __construct(
ConfigInterface $config,
) {
$this->config = $config->get('metric');
}

/**
* Process an incoming server request.
* Processes an incoming server request in order to produce a response.
Expand All @@ -31,6 +40,10 @@ class MetricMiddleware implements MiddlewareInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (! empty($this->config['ignore_path']) && preg_match($this->config['ignore_path'], $request->getUri()->getPath())) {
return $handler->handle($request);
}

$labels = [
'request_status' => '500',
'request_path' => $this->getPath($request),
Expand Down

0 comments on commit c435545

Please sign in to comment.