Skip to content

Commit

Permalink
removed splunk logging due to correlation id bug (#137)
Browse files Browse the repository at this point in the history
* Added Splunk logging required decorator to Token handler
* Added additional None checks to potential breaking areas

---------

Co-authored-by: Scott Alexander <scott.alexander@madetech.com>
  • Loading branch information
SRAlexander and Scott Alexander authored Nov 7, 2023
1 parent 2da25a3 commit 2e19091
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lambdas/handlers/token_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
OrganisationNotFoundException,
TooManyOrgsException)
from utils.lambda_response import ApiGatewayResponse
from utils.decorators.set_audit_arg import set_request_context_for_logging

logger = LoggingService(__name__)


token_handler_ssm_service = TokenHandlerSSMService()


@set_request_context_for_logging
def lambda_handler(event, context):
oidc_service = OidcService()
ods_api_service = OdsApiService()
Expand Down
9 changes: 5 additions & 4 deletions lambdas/utils/decorators/set_audit_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def interceptor(event, context):
request_context.authorization = None
if event.get("headers"):
token = event.get("headers").get("Authorization")
decoded_token = jwt.decode(
token, algorithms=["RS256"], options={"verify_signature": False}
)
request_context.authorization = decoded_token
if token:
decoded_token = jwt.decode(
token, algorithms=["RS256"], options={"verify_signature": False}
)
request_context.authorization = decoded_token
return lambda_func(event, context)

return interceptor
14 changes: 11 additions & 3 deletions lambdas/utils/logging_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@

class LoggingFormatter(logging.Formatter):
def format(self, record: logging.LogRecord) -> str:

auth = "No Auth"
if request_context.authorization is not None:
auth = request_context.authorization

s = super().format(record)
d = {
"correlation_id": request_context.request_id,
"auth": request_context.authorization,
**record.__dict__.get("custom_args", {}),
"Message": s,
"auth": auth,
"Message": s
}

if record.__dict__.get("custom_args", {}) is not None:
d.update(record.__dict__.get("custom_args", {}))

return json.dumps(d)

0 comments on commit 2e19091

Please sign in to comment.