From 6471eb5c1c3c5e593f1c6d39594770f6113e6f79 Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 7 Sep 2023 10:28:21 +0200 Subject: [PATCH 1/2] add account ID and region to AWS trace log output --- localstack/aws/handlers/logging.py | 6 ++++++ localstack/logging/format.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/localstack/aws/handlers/logging.py b/localstack/aws/handlers/logging.py index 96a756b4fb828..57ec71046dc0c 100644 --- a/localstack/aws/handlers/logging.py +++ b/localstack/aws/handlers/logging.py @@ -98,6 +98,9 @@ def _log(self, context: RequestContext, response: Response): response.status_code, context.service_exception.code, extra={ + # context + "account_id": context.account_id, + "region": context.region, # request "input_type": context.operation.input_shape.name if context.operation.input_shape @@ -117,6 +120,9 @@ def _log(self, context: RequestContext, response: Response): context.operation.name, response.status_code, extra={ + # context + "account_id": context.account_id, + "region": context.region, # request "input_type": context.operation.input_shape.name if context.operation.input_shape diff --git a/localstack/logging/format.py b/localstack/logging/format.py index 7cd8fa74e3e10..e5a2b62e428c8 100644 --- a/localstack/logging/format.py +++ b/localstack/logging/format.py @@ -107,8 +107,9 @@ def compress_logger_name(name: str, length: int) -> str: class TraceLoggingFormatter(logging.Formatter): aws_trace_log_format = ( - LOG_FORMAT - + "; %(input_type)s(%(input)s, headers=%(request_headers)s); %(output_type)s(%(output)s, headers=%(response_headers)s)" + LOG_FORMAT + "; %(account_id)s/%(region)s - " + "%(input_type)s(%(input)s, headers=%(request_headers)s); " + "%(output_type)s(%(output)s, headers=%(response_headers)s)" ) def __init__(self): From c3a6ed2afa45a1147b96c62b546611c1aeaa174b Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Thu, 7 Sep 2023 12:44:19 +0200 Subject: [PATCH 2/2] Update localstack/logging/format.py Co-authored-by: Viren Nadkarni --- localstack/logging/format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localstack/logging/format.py b/localstack/logging/format.py index e5a2b62e428c8..e27d35758e3d3 100644 --- a/localstack/logging/format.py +++ b/localstack/logging/format.py @@ -107,7 +107,7 @@ def compress_logger_name(name: str, length: int) -> str: class TraceLoggingFormatter(logging.Formatter): aws_trace_log_format = ( - LOG_FORMAT + "; %(account_id)s/%(region)s - " + LOG_FORMAT + "; %(account_id)s/%(region)s; " "%(input_type)s(%(input)s, headers=%(request_headers)s); " "%(output_type)s(%(output)s, headers=%(response_headers)s)" )