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.