Skip to content

Commit

Permalink
feat(dotnet, node, php, python)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiAndreiev committed Aug 29, 2024
1 parent cb2dfc9 commit e10ff69
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/dotnet/ReadMe/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/php/src/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/python/readme_metrics/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions packages/python/readme_metrics/flask_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit e10ff69

Please sign in to comment.