Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clarify usage and wording for current_root_span #11764

Merged
merged 5 commits into from
Jan 8, 2025
Merged
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
19 changes: 12 additions & 7 deletions ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,18 +940,23 @@ def trace(
)

def current_root_span(self) -> Optional[Span]:
"""Returns the root span of the current execution.
"""Returns the local root span of the current execution/process.

This is useful for attaching information related to the trace as a
whole without needing to add to child spans.
Note: This cannot be used to access the true root span of the trace
in a distributed tracing setup if the actual root span occurred in
another execution/process.

This is useful for attaching information to the local root span
of the current execution/process, which is often also service
entry span.

For example::

# get the root span
root_span = tracer.current_root_span()
# get the local root span
local_root_span = tracer.current_root_span()
# set the host just once on the root span
if root_span:
root_span.set_tag('host', '127.0.0.1')
if local_root_span:
local_root_span.set_tag('host', '127.0.0.1')
"""
span = self.current_span()
if span is None:
Expand Down
Loading