Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a71d383

Browse files
authored
docs: updating trace API docstrings (open-telemetry#1170)
The current docstrings were not factually correct, and different wording provided better clarity: - start_as_current_span shoudl return the current span back to the previous current span in the context, rather than the parent span. This is the behavior of the SDK. - There is not "tracer context", simply the "context" object. So renaming references there.
1 parent f4521fd commit a71d383

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

opentelemetry-api/src/opentelemetry/trace/__init__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,15 @@ def start_span(
237237
"""Starts a span.
238238
239239
Create a new span. Start the span without setting it as the current
240-
span in this tracer's context.
240+
span in the context. To start the span and use the context in a single
241+
method, see :meth:`start_as_current_span`.
241242
242-
By default the current span will be used as parent, but an explicit
243-
parent can also be specified, either a `Span` or a `opentelemetry.trace.SpanContext`. If
244-
the specified value is `None`, the created span will be a root span.
243+
By default the current span in the context will be used as parent, but an
244+
explicit parent can also be specified, either a `Span` or a `opentelemetry.trace.SpanContext`.
245+
If the specified value is `None`, the created span will be a root span.
245246
246-
The span can be used as context manager. On exiting, the span will be
247-
ended.
247+
The span can be used as a context manager. On exiting the context manager,
248+
the span's end() method will be called.
248249
249250
Example::
250251
@@ -253,9 +254,6 @@ def start_span(
253254
with tracer.start_span("one") as child:
254255
child.add_event("child's event")
255256
256-
Applications that need to set the newly created span as the current
257-
instance should use :meth:`start_as_current_span` instead.
258-
259257
Args:
260258
name: The name of the span to be created.
261259
parent: The span's parent. Defaults to the current span.
@@ -287,8 +285,9 @@ def start_as_current_span(
287285
"""Context manager for creating a new span and set it
288286
as the current span in this tracer's context.
289287
290-
On exiting the context manager stops the span and set its parent as the
291-
current span.
288+
Exiting the context manager will call the span's end method,
289+
as well as return the current span to it's previous value by
290+
returning to the previous context.
292291
293292
Example::
294293
@@ -330,7 +329,9 @@ def start_as_current_span(
330329
def use_span(
331330
self, span: "Span", end_on_exit: bool = False
332331
) -> typing.Iterator[None]:
333-
"""Context manager for controlling a span's lifetime.
332+
"""Context manager for setting the passed span as the
333+
current span in the context, as well as resetting the
334+
context back upon exiting the context manager.
334335
335336
Set the given span as the current span in this tracer's context.
336337

0 commit comments

Comments
 (0)