Skip to content

Commit 621525c

Browse files
committed
DEV: xray activation
1 parent 8c471d3 commit 621525c

File tree

3 files changed

+612
-295
lines changed

3 files changed

+612
-295
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"nexus-rpc>=1.1.0",
1515
"protobuf>=3.20,<6",
1616
"python-dateutil>=2.8.2,<3 ; python_version < '3.11'",
17+
"temporalio-xray",
1718
"types-protobuf>=3.20",
1819
"typing-extensions>=4.2.0,<5",
1920
]
@@ -233,3 +234,4 @@ package = false
233234

234235
[tool.uv.sources]
235236
nexus-rpc = { git = "https://github.com/nexus-rpc/sdk-python.git", rev = "35f574c711193a6e2560d3e6665732a5bb7ae92c" }
237+
temporalio-xray = { path = "../xray/sdks/python" }

temporalio/worker/_workflow_instance.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
)
4545

4646
import nexusrpc.handler
47+
import xray
48+
from google.protobuf.json_format import MessageToJson
4749
from nexusrpc import InputT, OutputT
4850
from typing_extensions import Self, TypeAlias, TypedDict
4951

@@ -355,10 +357,30 @@ def get_thread_id(self) -> Optional[int]:
355357
# "_make_workflow_input", all other calls are "_apply_" + the job field
356358
# name.
357359

360+
# The commented code below had line numbers, which are now removed.
361+
358362
def activate(
359363
self, act: temporalio.bridge.proto.workflow_activation.WorkflowActivation
360364
) -> temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion:
361-
print("activate -------------------------------------------------------------")
365+
with xray.start_as_current_span(
366+
actor=xray.Actor.WORKFLOW_USER,
367+
workflow_id=self._info.workflow_id,
368+
name="handle_activation",
369+
request_payload=MessageToJson(act),
370+
) as span:
371+
print(
372+
f">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WFT {self._info.workflow_id}\n"
373+
)
374+
375+
completion = self._activate(act)
376+
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
377+
if span:
378+
span.set_attribute("sdk.response.payload", MessageToJson(completion))
379+
return completion
380+
381+
def _activate(
382+
self, act: temporalio.bridge.proto.workflow_activation.WorkflowActivation
383+
) -> temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion:
362384
# Reset current completion, time, and whether replaying
363385
self._current_completion = (
364386
temporalio.bridge.proto.workflow_completion.WorkflowActivationCompletion()

0 commit comments

Comments
 (0)