Skip to content

Commit

Permalink
fixed incorrect elapsed time duration, and bump up version (#72)
Browse files Browse the repository at this point in the history
* fixed incorrect elapsed time duration, and bump up version
* update configuration version
* fix elapsed time duration for pre19
  • Loading branch information
HzANut committed Oct 3, 2022
1 parent 66dcc35 commit 6e46cf6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
17 changes: 11 additions & 6 deletions moesifdjango/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, get_response):
# below comment for setting moesif base_uri to a test server.
if self.middleware_settings.get('LOCAL_DEBUG', False):
Configuration.BASE_URI = self.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL')
Configuration.version = 'moesifdjango-python/2.1.5'
Configuration.version = 'moesifdjango-python/2.2.0'
if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False):
try:
if self.DEBUG:
Expand Down Expand Up @@ -170,11 +170,13 @@ def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.

# Initialize Transaction Id
transaction_id = None

# Request Time
req_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]
if self.DEBUG:
print("event request time: ", req_time)

# Initialize Transaction Id
transaction_id = None

try:
request._mo_body = request.body
Expand All @@ -190,6 +192,11 @@ def __call__(self, request):
# Code to be executed for each request/response after
# the view is called.

# Response Time
rsp_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]
if self.DEBUG:
print("event response time: ", rsp_time)

# Check if need to skip logging event
skip_event_response = self.logger_helper.skip_event(request, response, self.middleware_settings, self.DEBUG)
if skip_event_response:
Expand Down Expand Up @@ -224,8 +231,6 @@ def __call__(self, request):
# Prepare Response Body
rsp_body, rsp_body_transfer_encoding = self.logger_helper.prepare_response_body(response, rsp_headers, self.LOG_BODY,
self.middleware_settings)
# Response Time
rsp_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]

# Prepare Event Request Model
event_req = self.event_mapper.to_request(req_time, uri,request.method, self.api_version, ip_address,
Expand Down
12 changes: 8 additions & 4 deletions moesifdjango/middleware_pre19.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
# below comment for setting moesif base_uri to a test server.
if self.middleware_settings.get('LOCAL_DEBUG', False):
Configuration.BASE_URI = self.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL')
Configuration.version = 'moesifdjango-python/2.1.5'
Configuration.version = 'moesifdjango-python/2.2.0'
if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False):
try:
if self.DEBUG:
Expand Down Expand Up @@ -156,14 +156,21 @@ def process_response(self, request, response):
# Code to be executed for each request before
# the view (and later middleware) are called.

# Request time
req_time = request.moesif_req_time
if self.DEBUG:
print("event request time: ", req_time)

if self.DEBUG:
print("raw body before getting response")

# response = get_response(request)
# Code to be executed for each request/response after
# the view is called.
# Response Time
rsp_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]
if self.DEBUG:
print("event response time: ", rsp_time)

# Check if need to skip logging event
skip_event_response = self.logger_helper.skip_event(request, response, self.middleware_settings, self.DEBUG)
Expand Down Expand Up @@ -201,9 +208,6 @@ def process_response(self, request, response):
self.LOG_BODY,
self.middleware_settings)

# Response Time
rsp_time = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3]

# Prepare Event Request Model
event_req = self.event_mapper.to_request(req_time, uri, request.method, self.api_version,
ip_address, req_headers, req_body, req_body_transfer_encoding)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='2.1.6',
version='2.2.0',

description='Moesif Middleware for Python Django',
long_description=long_description,
Expand Down

0 comments on commit 6e46cf6

Please sign in to comment.