Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 undefined;
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":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get here in the request lifecycle when it's an OPTIONS call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gratcliff @erunion i've added some tests for this feature and made some minor changes

return response

try:
response_info = ResponseInfoWrapper(
response.headers,
Expand Down