Skip to content

Commit 3e0d650

Browse files
committed
Add update info to logging extra
1 parent d7f2e9f commit 3e0d650

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

temporalio/workflow.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings
1212
from abc import ABC, abstractmethod
1313
from contextlib import contextmanager
14-
from dataclasses import dataclass
14+
from dataclasses import asdict, dataclass
1515
from datetime import datetime, timedelta, timezone
1616
from enum import Enum, IntEnum
1717
from functools import partial
@@ -500,6 +500,16 @@ class UpdateInfo:
500500
name: str
501501
"""Update type name."""
502502

503+
@property
504+
def logger_details(self) -> Mapping[str, Any]:
505+
"""
506+
Data to be included in string appended to default logging output.
507+
"""
508+
return {
509+
"update_id": self.id,
510+
"update_name": self.name,
511+
}
512+
503513

504514
class _Runtime(ABC):
505515
@staticmethod
@@ -1205,6 +1215,10 @@ class LoggerAdapter(logging.LoggerAdapter):
12051215
dictionary value will be added to the ``extra`` dictionary with some
12061216
workflow info, making it present on the ``LogRecord.__dict__`` for
12071217
use by others. Default is True.
1218+
update_info_on_extra: Boolean for whether a ``temporal_update``
1219+
dictionary value will be added to the ``extra`` dictionary with some
1220+
update info, making it present on the ``LogRecord.__dict__`` for use
1221+
by others. Default is True.
12081222
full_workflow_info_on_extra: Boolean for whether a ``workflow_info``
12091223
value will be added to the ``extra`` dictionary with the entire
12101224
workflow info, making it present on the ``LogRecord.__dict__`` for
@@ -1224,6 +1238,7 @@ def __init__(
12241238
super().__init__(logger, extra or {})
12251239
self.workflow_info_on_message = True
12261240
self.workflow_info_on_extra = True
1241+
self.update_info_on_extra = True
12271242
self.full_workflow_info_on_extra = False
12281243
self.log_during_replay = False
12291244

@@ -1234,10 +1249,11 @@ def process(
12341249
if (
12351250
self.workflow_info_on_message
12361251
or self.workflow_info_on_extra
1252+
or self.update_info_on_extra
12371253
or self.full_workflow_info_on_extra
12381254
):
1239-
extra = {}
1240-
msg_extra = {}
1255+
extra: Dict[str, Any] = {}
1256+
msg_extra: Dict[str, Any] = {}
12411257
runtime = _Runtime.maybe_current()
12421258
if runtime:
12431259
if self.workflow_info_on_message:
@@ -1246,6 +1262,12 @@ def process(
12461262
extra["temporal_workflow"] = runtime.logger_details
12471263
if self.full_workflow_info_on_extra:
12481264
extra["workflow_info"] = runtime.workflow_info()
1265+
update_info = current_update_info()
1266+
if update_info:
1267+
if self.update_info_on_extra:
1268+
extra["temporal_update"] = asdict(update_info)
1269+
if self.workflow_info_on_message:
1270+
msg_extra.update(update_info.logger_details)
12491271

12501272
kwargs["extra"] = {**extra, **(kwargs.get("extra") or {})}
12511273
if msg_extra:

0 commit comments

Comments
 (0)