Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def _start_workflow_span(self, info: InvocationStartInfo) -> None:
# Empty context => root span with no parent.
self._workflow_span = self._tracer.start_span(
name=self._workflow_span_name,
kind=SpanKind.INTERNAL,
attributes={"durable.execution.arn": self._execution_arn},
start_time=start_time,
context=Context(),
Expand Down Expand Up @@ -291,17 +292,22 @@ def on_invocation_end(self, info: InvocationEndInfo) -> None:
# clears the span map below.

# End the invocation span regardless of terminal status. Record the
# invocation status and map it to a span status: SUCCEEDED/PENDING are OK
# (this invocation did its work, whether it completed or suspended),
# RETRY/FAILED are ERROR (this invocation failed).
# invocation status and map it to a span status:
# SUCCEEDED/PENDING -> OK (this invocation did its work, whether it
# completed the execution or cleanly suspended)
# FAILED -> ERROR
# RETRY -> UNSET
# RETRY is left UNSET because the plugin interface cannot tell whether the
# execution/workflow was STOPPED or TIMED_OUT: a RETRY invocation is not a
# definitive failure of the execution, so we avoid marking the span ERROR.
if self._invocation_span is not None:
self._invocation_span.set_attribute(
"durable.invocation.status",
info.status.value if info.status else "",
)
if info.status in (InvocationStatus.SUCCEEDED, InvocationStatus.PENDING):
self._invocation_span.set_status(StatusCode.OK)
elif info.status in (InvocationStatus.RETRY, InvocationStatus.FAILED):
elif info.status is InvocationStatus.FAILED:
self._invocation_span.set_status(
StatusCode.ERROR, info.error.message if info.error else ""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,14 @@ def on_invocation_end(self, info: InvocationEndInfo) -> None:
invocation_span.set_attribute(
"durable.invocation.status", info.status.value
)
# Span status mapping: SUCCEEDED/PENDING -> OK, FAILED -> ERROR,
# RETRY -> UNSET. RETRY is left UNSET because the plugin interface
# cannot tell whether the execution/workflow was STOPPED or
# TIMED_OUT, so a RETRY invocation is not treated as a definitive
# failure of the execution.
if info.status in (InvocationStatus.SUCCEEDED, InvocationStatus.PENDING):
invocation_span.set_status(StatusCode.OK)
elif info.status in (InvocationStatus.RETRY, InvocationStatus.FAILED):
elif info.status is InvocationStatus.FAILED:
invocation_span.set_status(
StatusCode.ERROR, info.error.message if info.error else ""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ def test_open_operation_span_not_exported_at_invocation_end():
[
(InvocationStatus.PENDING, trace.StatusCode.OK),
(InvocationStatus.SUCCEEDED, trace.StatusCode.OK),
(InvocationStatus.RETRY, trace.StatusCode.ERROR),
(InvocationStatus.RETRY, trace.StatusCode.UNSET),
(InvocationStatus.FAILED, trace.StatusCode.ERROR),
],
)
def test_invocation_span_status_kind_and_attributes(status, expected_code):
"""Invocation span is INTERNAL, carries status/first; SUCCEEDED/PENDING are
OK and RETRY/FAILED are ERROR."""
OK, FAILED is ERROR, and RETRY is UNSET (STOPPED/TIMED_OUT indistinguishable)."""
plugin, exporter = _create_plugin()
plugin.on_invocation_start(_invocation_start_info())
plugin.on_invocation_end(_invocation_end_info(status=status))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_invocation_span_records_subsequent_invocation():
("invocation_status", "expected_span_status"),
[
(InvocationStatus.PENDING, StatusCode.OK),
(InvocationStatus.RETRY, StatusCode.ERROR),
(InvocationStatus.RETRY, StatusCode.UNSET),
(InvocationStatus.SUCCEEDED, StatusCode.OK),
(InvocationStatus.FAILED, StatusCode.ERROR),
],
Expand Down
Loading