Skip to content

Log stack traces only in debug mode #12989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def __call__(self, chain: HandlerChain, context: RequestContext, response: Respo
try:
dto = MappingProxyType(load_dto(header))
except Exception as e:
LOG.exception("Error loading request parameters '%s', Error: %s", header, e)
LOG.error(
"Error loading request parameters '%s', Error: %s",
header,
e,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return

context.internal_request_params = dto
5 changes: 3 additions & 2 deletions localstack-core/localstack/aws/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ def get_service_catalog() -> ServiceCatalog:
index = build_service_index_cache(cache_catalog_file)
return ServiceCatalog(index)
except Exception:
LOG.exception(
"error while processing service catalog index cache, falling back to lazy-loaded index"
LOG.error(
"error while processing service catalog index cache, falling back to lazy-loaded index",
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return ServiceCatalog()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ def _is_body_valid(self, resource) -> bool:
# try to get the resolved model first
resolved_schema = model_resolver.get_resolved_model()
if not resolved_schema:
LOG.exception(
"An exception occurred while trying to validate the request: could not find the model"
LOG.error(
"An exception occurred while trying to validate the request: could not find the model",
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return False

Expand Down Expand Up @@ -334,7 +335,7 @@ def invoke_rest_api_integration(invocation_context: ApiInvocationContext):
return e.to_response()
except Exception as e:
msg = f"Error invoking integration for API Gateway ID '{invocation_context.api_id}': {e}"
LOG.exception(msg)
LOG.error(msg, exc_info=LOG.isEnabledFor(logging.DEBUG))
return make_error_response(msg, 400)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def validate_request(
# check if there is a validator for this request
if not (validator := rest_api.validators.get(request_validator_id)):
# TODO Should we raise an exception instead?
LOG.exception("No validator were found with matching id: '%s'", request_validator_id)
LOG.error(
"No validator were found with matching id: '%s'",
request_validator_id,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return

if self.should_validate_request(validator) and (
Expand Down Expand Up @@ -87,9 +91,10 @@ def _is_body_valid(
# try to get the resolved model first
resolved_schema = model_resolver.get_resolved_model()
if not resolved_schema:
LOG.exception(
LOG.error(
"An exception occurred while trying to validate the request: could not resolve the model '%s'",
model_name,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,10 +1479,11 @@ def delete_stack(self):
# correct order yet.
continue
case OperationStatus.FAILED:
LOG.exception(
LOG.error(
"Failed to delete resource with id %s. Reason: %s",
resource_id,
event.message or "unknown",
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
case OperationStatus.IN_PROGRESS:
# the resource provider executor should not return this state, so
Expand All @@ -1494,10 +1495,11 @@ def delete_stack(self):
raise Exception(f"Use of unsupported status found: {other_status}")

except Exception as e:
LOG.exception(
LOG.error(
"Failed to delete resource with id %s. Final exception: %s",
resource_id,
e,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)

# update status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def create_stack(self, context: RequestContext, request: CreateStackInput) -> Cr
except Exception as e:
stack.set_stack_status("CREATE_FAILED")
msg = 'Unable to create stack "%s": %s' % (stack.stack_name, e)
LOG.exception("%s")
LOG.error("%s", exc_info=LOG.isEnabledFor(logging.DEBUG))
raise ValidationError(msg) from e

return CreateStackOutput(StackId=stack.stack_id)
Expand Down Expand Up @@ -423,7 +423,7 @@ def update_stack(
except Exception as e:
stack.set_stack_status("UPDATE_FAILED")
msg = f'Unable to update stack "{stack_name}": {e}'
LOG.exception("%s", msg)
LOG.error("%s", msg, exc_info=LOG.isEnabledFor(logging.DEBUG))
raise ValidationError(msg) from e

return UpdateStackOutput(StackId=stack.stack_id)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def validate_template(
Description=valid_template.get("Description"), Parameters=parameters
)
except Exception as e:
LOG.exception("Error validating template")
LOG.error("Error validating template", exc_info=LOG.isEnabledFor(logging.DEBUG))
raise ValidationError("Template Validation Error") from e

# =======================================
Expand Down
2 changes: 1 addition & 1 deletion localstack-core/localstack/services/dynamodb/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def check_dynamodb(self, expect_shutdown: bool = False) -> None:
aws_secret_access_key=DEFAULT_AWS_ACCOUNT_ID,
).dynamodb.list_tables()
except Exception:
LOG.exception("DynamoDB health check failed")
LOG.error("DynamoDB health check failed", exc_info=LOG.isEnabledFor(logging.DEBUG))
if expect_shutdown:
assert out is None
else:
Expand Down
18 changes: 14 additions & 4 deletions localstack-core/localstack/services/firehose/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,11 @@ def _put_records(
try:
requests.post(url, json=record_to_send, headers=headers)
except Exception as e:
LOG.exception("Unable to put Firehose records to HTTP endpoint %s.", url)
LOG.error(
"Unable to put Firehose records to HTTP endpoint %s.",
url,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
raise e
if "RedshiftDestinationDescription" in destination:
s3_dest_desc = destination["RedshiftDestinationDescription"][
Expand Down Expand Up @@ -782,7 +786,11 @@ def _put_to_search_db(
try:
db_connection.create(index=search_db_index, id=obj_id, body=body)
except Exception as e:
LOG.exception("Unable to put record to stream %s.", delivery_stream_name)
LOG.error(
"Unable to put record to stream %s.",
delivery_stream_name,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
raise e

def _add_missing_record_attributes(self, records: list[dict]) -> None:
Expand Down Expand Up @@ -860,9 +868,10 @@ def _put_records_to_s3_bucket(
LOG.debug("Publishing to S3 destination: %s. Data: %s", bucket, batched_data)
s3.put_object(Bucket=bucket, Key=obj_path, Body=batched_data)
except Exception as e:
LOG.exception(
LOG.error(
"Unable to put records %s to s3 bucket.",
records,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
raise e

Expand Down Expand Up @@ -917,9 +926,10 @@ def _put_to_redshift(
)
redshift_data.execute_statement(Parameters=row_to_insert, **execute_statement)
except Exception as e:
LOG.exception(
LOG.error(
"Unable to put records %s to redshift cluster.",
row_to_insert,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
raise e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,11 @@ def update_version_state(
] = new_version_state

except Exception:
LOG.exception("Failed to update function version for arn %s", function_arn)
LOG.error(
"Failed to update function version for arn %s",
function_arn,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)

def update_alias(self, old_alias: VersionAlias, new_alias: VersionAlias, function: Function):
# if pointer changed, need to restart provisioned
Expand Down
4 changes: 2 additions & 2 deletions localstack-core/localstack/services/lambda_/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def on_after_state_load(self):
LOG.warning(
"Failed to restore function version %s",
fn_version.id.qualified_arn(),
exc_info=True,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
# restore provisioned concurrency per function considering both versions and aliases
for (
Expand Down Expand Up @@ -344,7 +344,7 @@ def on_after_state_load(self):
"Failed to restore provisioned concurrency %s for function %s",
provisioned_config,
fn_arn,
exc_info=True,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)

for esm in state.event_source_mappings.values():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,11 @@ def on_after_state_load(self):
preferred_port=preferred_port,
)
except Exception:
LOG.exception(
LOG.error(
"Could not restore domain %s in region %s.",
domain_name,
region,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)

def on_before_state_reset(self):
Expand Down
6 changes: 5 additions & 1 deletion localstack-core/localstack/services/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,8 @@ def eager_load_services():
except ServiceDisabled as e:
LOG.debug("%s", e)
except Exception:
LOG.exception("could not load service plugin %s", api)
LOG.error(
"could not load service plugin %s",
api,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
25 changes: 18 additions & 7 deletions localstack-core/localstack/services/s3/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,14 @@ def _verify_target(self, target_arn: str, verification_ctx: BucketVerificationCo
queue_url = sqs_client.get_queue_url(
QueueName=arn_data["resource"], QueueOwnerAWSAccountId=arn_data["account"]
)["QueueUrl"]
except ClientError:
LOG.exception("Could not validate the notification destination %s", target_arn)
except ClientError as e:
code = e.response["Error"]["Code"]
LOG.error(
"Could not validate the notification destination %s: %s",
target_arn,
code,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
raise _create_invalid_argument_exc(
"Unable to validate the following destination configurations",
name=target_arn,
Expand Down Expand Up @@ -454,10 +460,11 @@ def notify(self, ctx: S3EventNotificationContext, config: QueueConfiguration):
MessageSystemAttributes=system_attributes,
)
except Exception:
LOG.exception(
LOG.error(
'Unable to send notification for S3 bucket "%s" to SQS queue "%s"',
ctx.bucket_name,
parsed_arn["resource"],
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


Expand Down Expand Up @@ -536,10 +543,11 @@ def notify(self, ctx: S3EventNotificationContext, config: TopicConfiguration):
Subject="Amazon S3 Notification",
)
except Exception:
LOG.exception(
LOG.error(
'Unable to send notification for S3 bucket "%s" to SNS topic "%s"',
ctx.bucket_name,
topic_arn,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


Expand Down Expand Up @@ -604,10 +612,11 @@ def notify(self, ctx: S3EventNotificationContext, config: LambdaFunctionConfigur
Payload=payload,
)
except Exception:
LOG.exception(
LOG.error(
'Unable to send notification for S3 bucket "%s" to Lambda function "%s".',
ctx.bucket_name,
lambda_arn,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


Expand Down Expand Up @@ -729,8 +738,10 @@ def notify(self, ctx: S3EventNotificationContext, config: EventBridgeConfigurati
try:
events_client.put_events(Entries=[entry])
except Exception:
LOG.exception(
'Unable to send notification for S3 bucket "%s" to EventBridge', ctx.bucket_name
LOG.error(
'Unable to send notification for S3 bucket "%s" to EventBridge',
ctx.bucket_name,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


Expand Down
6 changes: 4 additions & 2 deletions localstack-core/localstack/services/s3/website_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def __call__(
return Response(response_body, status=e.response["ResponseMetadata"]["HTTPStatusCode"])

except Exception:
LOG.exception(
"Exception encountered while trying to serve s3-website at %s", request.url
LOG.error(
"Exception encountered while trying to serve s3-website at %s",
request.url,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return Response(_create_500_error_string(), status=500)

Expand Down
4 changes: 2 additions & 2 deletions localstack-core/localstack/services/ses/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def emit_send_event(
Subject="Amazon SES Email Event Notification",
)
except ClientError:
LOGGER.exception("sending SNS message")
LOGGER.error("sending SNS message", exc_info=LOGGER.isEnabledFor(logging.DEBUG))

def emit_delivery_event(self, payload: SNSPayload, sns_topic_arn: str):
now = datetime.now(tz=UTC)
Expand Down Expand Up @@ -665,7 +665,7 @@ def emit_delivery_event(self, payload: SNSPayload, sns_topic_arn: str):
Subject="Amazon SES Email Event Notification",
)
except ClientError:
LOGGER.exception("sending SNS message")
LOGGER.error("sending SNS message", exc_info=LOGGER.isEnabledFor(logging.DEBUG))

@staticmethod
def _client_for_topic(topic_arn: str) -> "SNSClient":
Expand Down
11 changes: 9 additions & 2 deletions localstack-core/localstack/services/sns/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def _worker(work_queue: queue.Queue):
del work_item

except Exception:
LOG.exception("Exception in worker")
LOG.error(
"Exception in worker",
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


class _WorkItem:
Expand All @@ -31,7 +34,11 @@ def run(self):
try:
self.fn(*self.args, **self.kwargs)
except Exception:
LOG.exception("Unhandled Exception in while running %s", self.fn.__name__)
LOG.error(
"Unhandled Exception in while running %s",
self.fn.__name__,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)


class TopicPartitionedThreadPoolExecutor:
Expand Down
11 changes: 8 additions & 3 deletions localstack-core/localstack/services/sns/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ def publish(self, context: SnsPublishContext, subscriber: SnsSubscription):
try:
self._publish(context=context, subscriber=subscriber)
except Exception:
LOG.exception(
LOG.error(
"An internal error occurred while trying to send the SNS message %s",
context.message,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return

Expand Down Expand Up @@ -147,9 +148,10 @@ def publish(self, context: SnsPublishContext, endpoint: str):
try:
self._publish(context=context, endpoint=endpoint)
except Exception:
LOG.exception(
LOG.error(
"An internal error occurred while trying to send the SNS message %s",
context.message,
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return

Expand Down Expand Up @@ -295,7 +297,10 @@ def _publish(self, context: SnsPublishContext, subscriber: SnsSubscription):
)
kwargs = self.get_sqs_kwargs(msg_context=message_context, subscriber=subscriber)
except Exception:
LOG.exception("An internal error occurred while trying to format the message for SQS")
LOG.error(
"An internal error occurred while trying to format the message for SQS",
exc_info=LOG.isEnabledFor(logging.DEBUG),
)
return
try:
queue_url: str = sqs_queue_url_for_arn(subscriber["Endpoint"])
Expand Down
Loading
Loading