Skip to content
Merged
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
6 changes: 4 additions & 2 deletions aws_lambda_powertools/logging/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def formatTime(self, record: logging.LogRecord, datefmt: str | None = None) -> s
# NOTE: Python `time.strftime` doesn't provide msec directives
# so we create a custom one (%F) and replace logging record_ts
# Reason 2 is that std logging doesn't support msec after TZ
msecs = "%03d" % record.msecs
msecs = "%03d" % record.msecs # noqa UP031

# Datetime format codes is a superset of time format codes
# therefore we only honour them if explicitly asked
Expand Down Expand Up @@ -425,7 +425,9 @@ def _strip_none_records(records: dict[str, Any]) -> dict[str, Any]:
RESERVED_FORMATTER_CUSTOM_KEYS: list[str] = inspect.getfullargspec(LambdaPowertoolsFormatter).args[1:]

# ContextVar for thread local keys
THREAD_LOCAL_KEYS: ContextVar[dict[str, Any]] = ContextVar("THREAD_LOCAL_KEYS", default={})
default_contextvar: dict[str, Any] = {}

THREAD_LOCAL_KEYS: ContextVar[dict[str, Any]] = ContextVar("THREAD_LOCAL_KEYS", default=default_contextvar)


def _get_context() -> ContextVar[dict[str, Any]]:
Expand Down
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ types-python-dateutil = "^2.8.19.6"
aws-cdk-aws-appsync-alpha = "^2.59.0a0"
httpx = ">=0.23.3,<0.28.0"
sentry-sdk = ">=1.22.2,<3.0.0"
ruff = ">=0.5.1,<0.7.5"
ruff = ">=0.5.1,<0.8.1"
retry2 = "^0.9.5"
pytest-socket = ">=0.6,<0.8"
types-redis = "^4.6.0.7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random
import re
import string
import sys
import time
from collections import namedtuple
from threading import Thread
Expand Down Expand Up @@ -453,6 +454,7 @@ def send_thread_message_with_key(message, keys):
assert logs[3].get("exampleThread2Key") is None


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="Test temporarily disabled for Python 3.13+")
def test_thread_safe_remove_key(service_name, stdout):
logger = Logger(
service=service_name,
Expand All @@ -469,6 +471,7 @@ def send_message_with_key_and_without(message, keys):
Thread(target=send_message_with_key_and_without, args=("msg", thread1_keys)).start()

logs = capture_logging_output(stdout)
print(logs)

assert logs[0].get("exampleThread1Key") == "thread1"
assert logs[1].get("exampleThread1Key") is None
Expand Down
Loading