Skip to content

Commit bf3a09a

Browse files
authored
Merge pull request #16 from Moesif/fix-non-blocking-when-debug
Refactor: Send events async in debug mode
2 parents 621b6d4 + f856f86 commit bf3a09a

File tree

5 files changed

+7
-18
lines changed

5 files changed

+7
-18
lines changed

eventV1.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"protocol": "HTTP/1.1",
6969
"requestId": "id=",
7070
"requestTime": "04/Mar/2020:19:15:17 +0000",
71-
"requestTimeEpoch": 1583349317135,
71+
"requestTimeEpoch": 1698901826000,
7272
"resourceId": null,
7373
"resourcePath": "/my/path",
7474
"stage": "$default"

eventV2.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"routeKey": "$default",
5656
"stage": "$default",
5757
"time": "12/Mar/2020:19:03:58 +0000",
58-
"timeEpoch": 1583348638390
58+
"timeEpoch": 1698901826000
5959
},
6060
"body": "Hello from Lambda",
6161
"pathParameters": {

moesif_aws_lambda/middleware.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,10 @@ def after(self, retval):
428428
event_model.weight = 1 if gv.sampling_percentage == 0 else math.floor(
429429
100 / gv.sampling_percentage)
430430

431-
if self.DEBUG:
432-
start_time_sending_event_w_rsp = datetime.utcnow()
431+
if datetime.utcnow() > gv.last_updated_time + timedelta(seconds=gv.refresh_config_time_seconds):
433432
event_send = self.api_client.create_event(event_model)
434-
end_time_sending_event_w_rsp = datetime.utcnow()
435-
print("[moesif] sampling_percentage" + str(
436-
gv.sampling_percentage) + " and random percentage: " + str(random_percentage))
437-
print("[moesif] Time took in sending event to moesif in millisecond - " + str(
438-
get_time_took_in_ms(start_time_sending_event_w_rsp, end_time_sending_event_w_rsp)))
439-
print('[moesif] Event Sent successfully ' + str(event_send))
440-
441433
else:
442-
if datetime.utcnow() > gv.last_updated_time + timedelta(seconds=gv.refresh_config_time_seconds):
443-
event_send = self.api_client.create_event(event_model)
444-
else:
445-
self.api_client.create_event(event_model)
434+
self.api_client.create_event(event_model)
446435

447436
try:
448437
# Check if we need to update config

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
moesifapi==1.4.0
1+
moesifapi==1.4.1
22
lambda_decorators==0.3.0
3-
moesifpythonrequest==0.3.0
3+
moesifpythonrequest==0.3.1

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Versions should comply with PEP440. For a discussion on single-sourcing
2929
# the version across setup.py and the project code, see
3030
# https://packaging.python.org/en/latest/single_source_version.html
31-
version='1.2.0',
31+
version='1.2.1',
3232

3333
description='Moesif Middleware to automatically log API calls from AWS Lambda functions',
3434
long_description=long_description,

0 commit comments

Comments
 (0)