Skip to content

Commit 75bed24

Browse files
authored
chore: clarify usage and wording for current_root_span (#11764)
Following up on #9758, our current definition of current_root_span is a bit misleading. This attempts to clarify the definition since in a distributed trace, you can't actually use this to grab the root span. (The only thing it consistently returns is "local root"). ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 6c61f40 commit 75bed24

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ddtrace/_trace/tracer.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -940,18 +940,23 @@ def trace(
940940
)
941941

942942
def current_root_span(self) -> Optional[Span]:
943-
"""Returns the root span of the current execution.
943+
"""Returns the local root span of the current execution/process.
944944
945-
This is useful for attaching information related to the trace as a
946-
whole without needing to add to child spans.
945+
Note: This cannot be used to access the true root span of the trace
946+
in a distributed tracing setup if the actual root span occurred in
947+
another execution/process.
948+
949+
This is useful for attaching information to the local root span
950+
of the current execution/process, which is often also service
951+
entry span.
947952
948953
For example::
949954
950-
# get the root span
951-
root_span = tracer.current_root_span()
955+
# get the local root span
956+
local_root_span = tracer.current_root_span()
952957
# set the host just once on the root span
953-
if root_span:
954-
root_span.set_tag('host', '127.0.0.1')
958+
if local_root_span:
959+
local_root_span.set_tag('host', '127.0.0.1')
955960
"""
956961
span = self.current_span()
957962
if span is None:

0 commit comments

Comments
 (0)