Skip to content

Commit

Permalink
add to delight log
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-ganesh committed Sep 9, 2024
1 parent 32736f0 commit 4b0fd79
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions libs/infinity_emb/infinity_emb/log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,42 @@ async def list_to_async_iterator(body_list):
yield part

@staticmethod
def log_response_info(path, response, content, passed, duration):
def log_response_info(request, response, content, passed, duration):
if sla_breached(duration):
passed = 0
response_info = {
"st": response.status_code,
"hdr": json.dumps(
{k.decode(): v.decode() for k, v in response.raw_headers}
),
"path": path,
"path": request.url.path,
"lg": "http",
"pass": passed,
"body": (b"".join(content)).decode(),
"d": duration,
"m": request.method,
}
if response.status_code >= 400:
logging.error("RESPONSE", extra=response_info)
else:
logging.info("RESPONSE", extra=response_info)

# for every successful non-health request
if not any(map(request.url.path.__contains__, ("health", "metrics"))):
logging.info(
None, extra={
"st": response.status_code,
"hdr": json.dumps(
{k.decode(): v.decode() for k, v in response.raw_headers}
),
"path": request.url.path,
"lg": "delight",
"pass": passed,
"d": duration,
"m": request.method,
}
)

async def dispatch(self, request: Request, call_next):
StructuredLogging.request_time.set(perf_counter())
request_id = request.headers.get(
Expand Down Expand Up @@ -255,13 +272,7 @@ async def dispatch(self, request: Request, call_next):
passed = 0

duration = int(1000 * (perf_counter() - StructuredLogging.request_time.get()))
self.log_response_info(request.url.path, response, content, passed, duration)

# for every successful non-health request
if not any(map(request.url.path.__contains__, ("health", "metrics"))):
logging.info(
None, extra={"lg": "delight", "d": duration, "path": request.url.path}
)
self.log_response_info(request, response, content, passed, duration)

return response

Expand Down

0 comments on commit 4b0fd79

Please sign in to comment.