From d2853b4a0e7995b812423f12ec4e2d54b0162054 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Fri, 7 Nov 2025 14:51:09 -0500 Subject: [PATCH 1/2] chore(tracing): deprecate Span.finished setter and Span.finish_with_ancestors() --- ddtrace/_trace/span.py | 17 ++++++++++++++++- ddtrace/contrib/internal/aws_lambda/patch.py | 2 +- ...-finish-with-ancestors-c75633a9baaa9463.yaml | 6 ++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml diff --git a/ddtrace/_trace/span.py b/ddtrace/_trace/span.py index ea14e40a42a..caafc96bfbf 100644 --- a/ddtrace/_trace/span.py +++ b/ddtrace/_trace/span.py @@ -282,6 +282,12 @@ def finished(self, value: bool) -> None: If the span is already finished and a truthy value is provided no action will occur. """ + deprecate( + prefix="The finished setter is deprecated", + message="""Use the finish() method to finish a span.""", + category=DDTraceDeprecationWarning, + removal_version="4.0.0", + ) if value: if not self.finished: self.duration_ns = Time.time_ns() - self.start_ns @@ -820,7 +826,7 @@ def _set_link_or_append_pointer(self, link: Union[SpanLink, _SpanPointer]) -> No except ValueError: self._links.append(link) - def finish_with_ancestors(self) -> None: + def _finish_with_ancestors(self) -> None: """Finish this span along with all (accessible) ancestors of this span. This method is useful if a sudden program shutdown is required and finishing @@ -831,6 +837,15 @@ def finish_with_ancestors(self) -> None: span.finish() span = span._parent + @removals.remove(removal_version="4.0.0") + def finish_with_ancestors(self) -> None: + """Finish this span along with all (accessible) ancestors of this span. + + This method is useful if a sudden program shutdown is required and finishing + the trace is desired. + """ + self._finish_with_ancestors() + def __enter__(self) -> "Span": return self diff --git a/ddtrace/contrib/internal/aws_lambda/patch.py b/ddtrace/contrib/internal/aws_lambda/patch.py index a7aa0c0515b..1f2840de1f4 100644 --- a/ddtrace/contrib/internal/aws_lambda/patch.py +++ b/ddtrace/contrib/internal/aws_lambda/patch.py @@ -103,7 +103,7 @@ def _crash_flush(self, _, __): current_span = tracer.current_span() if current_span is not None: - current_span.finish_with_ancestors() + current_span._finish_with_ancestors() def _remove_alarm_signal(self): """Removes the handler set for the signal `SIGALRM`.""" diff --git a/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml b/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml new file mode 100644 index 00000000000..091aa147317 --- /dev/null +++ b/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml @@ -0,0 +1,6 @@ +--- +deprecations: + - | + tracing: ``Span.finished`` setter is deprecated, use ``Span.finish()`` method instead. + - | + tracing: ``Span.finished_with_ancestors()`` is deprecated with no alternative. From 9476b3146c63ff99225584cbf6606c17bb6d28d2 Mon Sep 17 00:00:00 2001 From: Brett Langdon Date: Mon, 10 Nov 2025 14:38:31 -0500 Subject: [PATCH 2/2] Update releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml Co-authored-by: Yun Kim <35776586+Yun-Kim@users.noreply.github.com> --- ...te-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml b/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml index 091aa147317..9c04bbe07c5 100644 --- a/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml +++ b/releasenotes/notes/deprecate-span-finished-finish-with-ancestors-c75633a9baaa9463.yaml @@ -3,4 +3,4 @@ deprecations: - | tracing: ``Span.finished`` setter is deprecated, use ``Span.finish()`` method instead. - | - tracing: ``Span.finished_with_ancestors()`` is deprecated with no alternative. + tracing: ``Span.finish_with_ancestors()`` is deprecated with no alternative.