From e10ff6953b3e4ab98bcca522a6bc523fc8900c80 Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:21:54 +0300 Subject: [PATCH] feat(dotnet, node, php, python) --- packages/dotnet/ReadMe/Metrics.cs | 6 ++++++ packages/node/src/lib/log.ts | 1 + packages/php/src/Metrics.php | 4 ++++ packages/python/readme_metrics/django.py | 3 +++ packages/python/readme_metrics/flask_readme.py | 6 ++++++ 5 files changed, 20 insertions(+) diff --git a/packages/dotnet/ReadMe/Metrics.cs b/packages/dotnet/ReadMe/Metrics.cs index abfaae40a3..6bf275b585 100644 --- a/packages/dotnet/ReadMe/Metrics.cs +++ b/packages/dotnet/ReadMe/Metrics.cs @@ -21,6 +21,12 @@ public Metrics(RequestDelegate next, IConfiguration configuration) public async Task InvokeAsync(HttpContext context) { + if (context.Request.Method == HttpMethods.Options) + { + await this.next(context); + return; + } + if (!context.Request.Path.Value.Contains("favicon.ico")) { this.group = new Group() diff --git a/packages/node/src/lib/log.ts b/packages/node/src/lib/log.ts index 68a38fbc91..0809503d66 100644 --- a/packages/node/src/lib/log.ts +++ b/packages/node/src/lib/log.ts @@ -109,6 +109,7 @@ export function log( group: GroupingObject, options: Options = {}, ) { + if (req.method === 'OPTIONS') return; if (!readmeApiKey) throw new Error('You must provide your ReadMe API key'); if (!group) throw new Error('You must provide a group'); if (options.logger) { diff --git a/packages/php/src/Metrics.php b/packages/php/src/Metrics.php index 59a5035f58..7f72806dc7 100644 --- a/packages/php/src/Metrics.php +++ b/packages/php/src/Metrics.php @@ -92,6 +92,10 @@ public function __construct(public string $api_key, public string $group_handler */ public function track(Request $request, Response &$response): void { + if ($request->getMethod() === 'OPTIONS') { + return; + } + if (empty($this->base_log_url)) { $this->base_log_url = $this->getProjectBaseUrl(); } diff --git a/packages/python/readme_metrics/django.py b/packages/python/readme_metrics/django.py index 8a42609e9f..2878a7034d 100644 --- a/packages/python/readme_metrics/django.py +++ b/packages/python/readme_metrics/django.py @@ -16,6 +16,9 @@ def __init__(self, get_response, config=None): self.metrics_core = Metrics(self.config) def __call__(self, request): + if request.method == "OPTIONS": + return self.get_response(request) + try: request.rm_start_dt = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") request.rm_start_ts = int(time.time() * 1000) diff --git a/packages/python/readme_metrics/flask_readme.py b/packages/python/readme_metrics/flask_readme.py index 4cb6471421..f4ac87bba9 100644 --- a/packages/python/readme_metrics/flask_readme.py +++ b/packages/python/readme_metrics/flask_readme.py @@ -27,6 +27,9 @@ def init_app(self, app: Flask): app.after_request(self.after_request) def before_request(self): + if request.method == "OPTIONS": + return + try: request.rm_start_dt = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") request.rm_start_ts = int(time.time() * 1000) @@ -39,6 +42,9 @@ def before_request(self): self.config.LOGGER.exception(e) def after_request(self, response): + if request.method == "OPTIONS": + return response + try: response_info = ResponseInfoWrapper( response.headers,