@@ -59,18 +59,24 @@ def __str__(self) -> str:
5959}
6060
6161
62+ # Sentinel value for an unset parent_span to be able to distinguish it from
63+ # a None set by the user
64+ _DEFAULT_PARENT_SPAN = object ()
65+
66+
6267def start_span (
6368 name : str ,
6469 attributes : "Optional[Attributes]" = None ,
65- parent_span : "Optional[StreamedSpan]" = None ,
70+ parent_span : "Optional[StreamedSpan]" = _DEFAULT_PARENT_SPAN ,
6671 active : bool = True ,
6772) -> "StreamedSpan" :
6873 """
6974 Start a span.
7075
7176 The span's parent, unless provided explicitly via the `parent_span` argument,
7277 will be the current active span, if any. If there is none, this span will
73- become the root of a new span tree.
78+ become the root of a new span tree. If you explicitly want this span to be
79+ top-level without a parent, set `parent_span=None`.
7480
7581 `start_span()` can either be used as context manager or you can use the span
7682 object it returns and explicitly end it via `span.end()`. The following is
@@ -102,7 +108,8 @@ def start_span(
102108
103109 :param parent_span: A span instance that the new span should consider its
104110 parent. If not provided, the parent will be set to the currently active
105- span, if any.
111+ span, if any. If set to `None`, this span will become a new root-level
112+ span.
106113 :type parent_span: "Optional[StreamedSpan]"
107114
108115 :param active: Controls whether spans started while this span is running
0 commit comments