Skip to content

Commit f452f03

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

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

temporalio/workflow.py

Lines changed: 23 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,14 @@ class UpdateInfo:
500500
name: str
501501
"""Update type name."""
502502

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

504512
class _Runtime(ABC):
505513
@staticmethod
@@ -1205,6 +1213,10 @@ class LoggerAdapter(logging.LoggerAdapter):
12051213
dictionary value will be added to the ``extra`` dictionary with some
12061214
workflow info, making it present on the ``LogRecord.__dict__`` for
12071215
use by others. Default is True.
1216+
update_info_on_extra: Boolean for whether a ``temporal_update``
1217+
dictionary value will be added to the ``extra`` dictionary with some
1218+
update info, making it present on the ``LogRecord.__dict__`` for use
1219+
by others. Default is True.
12081220
full_workflow_info_on_extra: Boolean for whether a ``workflow_info``
12091221
value will be added to the ``extra`` dictionary with the entire
12101222
workflow info, making it present on the ``LogRecord.__dict__`` for
@@ -1224,6 +1236,7 @@ def __init__(
12241236
super().__init__(logger, extra or {})
12251237
self.workflow_info_on_message = True
12261238
self.workflow_info_on_extra = True
1239+
self.update_info_on_extra = True
12271240
self.full_workflow_info_on_extra = False
12281241
self.log_during_replay = False
12291242

@@ -1234,10 +1247,11 @@ def process(
12341247
if (
12351248
self.workflow_info_on_message
12361249
or self.workflow_info_on_extra
1250+
or self.update_info_on_extra
12371251
or self.full_workflow_info_on_extra
12381252
):
1239-
extra = {}
1240-
msg_extra = {}
1253+
extra: Dict[str, Any] = {}
1254+
msg_extra: Dict[str, Any] = {}
12411255
runtime = _Runtime.maybe_current()
12421256
if runtime:
12431257
if self.workflow_info_on_message:
@@ -1246,6 +1260,12 @@ def process(
12461260
extra["temporal_workflow"] = runtime.logger_details
12471261
if self.full_workflow_info_on_extra:
12481262
extra["workflow_info"] = runtime.workflow_info()
1263+
update_info = current_update_info()
1264+
if update_info:
1265+
if self.update_info_on_extra:
1266+
extra["temporal_update"] = asdict(update_info)
1267+
if self.workflow_info_on_message:
1268+
msg_extra.update(update_info.logger_details)
12491269

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

0 commit comments

Comments
 (0)