Skip to content

Commit 63a72e7

Browse files
committed
Move logger
1 parent 7422438 commit 63a72e7

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

temporalio/nexus/__init__.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import logging
2-
from typing import (
3-
Any,
4-
Mapping,
5-
MutableMapping,
6-
Optional,
7-
)
8-
91
from ._decorators import workflow_run_operation as workflow_run_operation
102
from ._operation_context import Info as Info
113
from ._operation_context import (
@@ -19,29 +11,11 @@
1911
)
2012
from ._operation_context import client as client
2113
from ._operation_context import info as info
14+
from ._operation_context import logger as logger
2215
from ._operation_handlers import cancel_operation as cancel_operation
2316
from ._token import WorkflowHandle as WorkflowHandle
2417

2518

26-
class LoggerAdapter(logging.LoggerAdapter):
27-
def __init__(self, logger: logging.Logger, extra: Optional[Mapping[str, Any]]):
28-
super().__init__(logger, extra or {})
29-
30-
def process(
31-
self, msg: Any, kwargs: MutableMapping[str, Any]
32-
) -> tuple[Any, MutableMapping[str, Any]]:
33-
extra = dict(self.extra or {})
34-
if tctx := _temporal_operation_context.get(None):
35-
extra["service"] = tctx.nexus_operation_context.service
36-
extra["operation"] = tctx.nexus_operation_context.operation
37-
extra["task_queue"] = tctx.info().task_queue
38-
kwargs["extra"] = extra | kwargs.get("extra", {})
39-
return msg, kwargs
40-
41-
42-
logger = LoggerAdapter(logging.getLogger(__name__), None)
43-
"""Logger that emits additional data describing the current Nexus operation."""
44-
4519
# TODO(nexus-prerelease) WARN temporal_sdk_core::worker::nexus: Failed to parse nexus timeout header value '9.155416ms'
4620
# 2025-06-25T12:58:05.749589Z WARN temporal_sdk_core::worker::nexus: Failed to parse nexus timeout header value '9.155416ms'
4721
# 2025-06-25T12:58:05.763052Z WARN temporal_sdk_core::worker::nexus: Nexus task not found on completion. This may happen if the operation has already been cancelled but completed anyway. details=Status { code: NotFound, message: "Nexus task not found or already expired", details: b"\x08\x05\x12'Nexus task not found or already expired\x1aB\n@type.googleapis.com/temporal.api.errordetails.v1.NotFoundFailure", metadata: MetadataMap { headers: {"content-type": "application/grpc"} }, source: None }

temporalio/nexus/_operation_context.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
SelfType,
3131
)
3232

33-
logger = logging.getLogger(__name__)
3433

3534
_temporal_operation_context: ContextVar[_TemporalNexusOperationContext] = ContextVar(
3635
"temporal-operation-context"
@@ -367,3 +366,23 @@ def _nexus_link_to_workflow_event(
367366
run_id=urllib.parse.unquote(groups["run_id"]),
368367
event_ref=event_ref,
369368
)
369+
370+
371+
class _LoggerAdapter(logging.LoggerAdapter):
372+
def __init__(self, logger: logging.Logger, extra: Optional[Mapping[str, Any]]):
373+
super().__init__(logger, extra or {})
374+
375+
def process(
376+
self, msg: Any, kwargs: MutableMapping[str, Any]
377+
) -> tuple[Any, MutableMapping[str, Any]]:
378+
extra = dict(self.extra or {})
379+
if tctx := _temporal_operation_context.get(None):
380+
extra["service"] = tctx.nexus_operation_context.service
381+
extra["operation"] = tctx.nexus_operation_context.operation
382+
extra["task_queue"] = tctx.info().task_queue
383+
kwargs["extra"] = extra | kwargs.get("extra", {})
384+
return msg, kwargs
385+
386+
387+
logger = _LoggerAdapter(logging.getLogger("temporalio.nexus"), None)
388+
"""Logger that emits additional data describing the current Nexus operation."""

0 commit comments

Comments
 (0)