|
30 | 30 | created as children of the currently active span, and the newly-created span
|
31 | 31 | can optionally become the new active span::
|
32 | 32 |
|
33 |
| - from opentelemetry.trace import tracer |
| 33 | + from opentelemetry import trace |
34 | 34 |
|
35 | 35 | # Create a new root span, set it as the current span in context
|
36 |
| - with tracer.start_as_current_span("parent"): |
| 36 | + with trace.tracer().start_as_current_span("parent"): |
37 | 37 | # Attach a new child and update the current span
|
38 | 38 | with tracer.start_as_current_span("child"):
|
39 | 39 | do_work():
|
|
43 | 43 | When creating a span that's "detached" from the context the active span doesn't
|
44 | 44 | change, and the caller is responsible for managing the span's lifetime::
|
45 | 45 |
|
46 |
| - from opentelemetry.api.trace import tracer |
| 46 | + from opentelemetry import trace |
47 | 47 |
|
48 | 48 | # Explicit parent span assignment
|
49 |
| - span = tracer.create_span("child", parent=parent) as child: |
| 49 | + child = trace.tracer().start_span("child", parent=parent) |
50 | 50 |
|
51 |
| - # The caller is responsible for starting and ending the span |
52 |
| - span.start() |
53 | 51 | try:
|
54 | 52 | do_work(span=child)
|
55 | 53 | finally:
|
56 |
| - span.end() |
| 54 | + child.end() |
57 | 55 |
|
58 | 56 | Applications should generally use a single global tracer, and use either
|
59 | 57 | implicit or explicit context propagation consistently throughout.
|
@@ -147,16 +145,6 @@ class SpanKind(enum.Enum):
|
147 | 145 | class Span:
|
148 | 146 | """A span represents a single operation within a trace."""
|
149 | 147 |
|
150 |
| - def start(self, start_time: typing.Optional[int] = None) -> None: |
151 |
| - """Sets the current time as the span's start time. |
152 |
| -
|
153 |
| - Each span represents a single operation. The span's start time is the |
154 |
| - wall time at which the operation started. |
155 |
| -
|
156 |
| - Only the first call to `start` should modify the span, and |
157 |
| - implementations are free to ignore or raise on further calls. |
158 |
| - """ |
159 |
| - |
160 | 148 | def end(self, end_time: int = None) -> None:
|
161 | 149 | """Sets the current time as the span's end time.
|
162 | 150 |
|
@@ -204,8 +192,7 @@ def add_lazy_event(self, event: Event) -> None:
|
204 | 192 | def update_name(self, name: str) -> None:
|
205 | 193 | """Updates the `Span` name.
|
206 | 194 |
|
207 |
| - This will override the name provided via :func:`Tracer.create_span` |
208 |
| - or :func:`Tracer.start_span`. |
| 195 | + This will override the name provided via :func:`Tracer.start_span`. |
209 | 196 |
|
210 | 197 | Upon this update, any sampling behavior based on Span name will depend
|
211 | 198 | on the implementation.
|
@@ -404,6 +391,7 @@ def start_span(
|
404 | 391 | kind: SpanKind = SpanKind.INTERNAL,
|
405 | 392 | attributes: typing.Optional[types.Attributes] = None,
|
406 | 393 | links: typing.Sequence[Link] = (),
|
| 394 | + start_time: typing.Optional[int] = None, |
407 | 395 | ) -> "Span":
|
408 | 396 | """Starts a span.
|
409 | 397 |
|
@@ -434,6 +422,7 @@ def start_span(
|
434 | 422 | meaningful even if there is no parent.
|
435 | 423 | attributes: The span's attributes.
|
436 | 424 | links: Links span to other spans
|
| 425 | + start_time: Sets the start time of a span |
437 | 426 |
|
438 | 427 | Returns:
|
439 | 428 | The newly-created span.
|
@@ -494,51 +483,6 @@ def start_as_current_span(
|
494 | 483 | # pylint: disable=unused-argument,no-self-use
|
495 | 484 | yield INVALID_SPAN
|
496 | 485 |
|
497 |
| - def create_span( |
498 |
| - self, |
499 |
| - name: str, |
500 |
| - parent: ParentSpan = CURRENT_SPAN, |
501 |
| - kind: SpanKind = SpanKind.INTERNAL, |
502 |
| - attributes: typing.Optional[types.Attributes] = None, |
503 |
| - links: typing.Sequence[Link] = (), |
504 |
| - ) -> "Span": |
505 |
| - """Creates a span. |
506 |
| -
|
507 |
| - Creating the span does not start it, and should not affect the tracer's |
508 |
| - context. To start the span and update the tracer's context to make it |
509 |
| - the currently active span, see :meth:`use_span`. |
510 |
| -
|
511 |
| - By default the current span will be used as parent, but an explicit |
512 |
| - parent can also be specified, either a Span or a SpanContext. |
513 |
| - If the specified value is `None`, the created span will be a root |
514 |
| - span. |
515 |
| -
|
516 |
| - Applications that need to create spans detached from the tracer's |
517 |
| - context should use this method. |
518 |
| -
|
519 |
| - with tracer.start_as_current_span(name) as span: |
520 |
| - do_work() |
521 |
| -
|
522 |
| - This is equivalent to:: |
523 |
| -
|
524 |
| - span = tracer.create_span(name) |
525 |
| - with tracer.use_span(span): |
526 |
| - do_work() |
527 |
| -
|
528 |
| - Args: |
529 |
| - name: The name of the span to be created. |
530 |
| - parent: The span's parent. Defaults to the current span. |
531 |
| - kind: The span's kind (relationship to parent). Note that is |
532 |
| - meaningful even if there is no parent. |
533 |
| - attributes: The span's attributes. |
534 |
| - links: Links span to other spans |
535 |
| -
|
536 |
| - Returns: |
537 |
| - The newly-created span. |
538 |
| - """ |
539 |
| - # pylint: disable=unused-argument,no-self-use |
540 |
| - return INVALID_SPAN |
541 |
| - |
542 | 486 | @contextmanager # type: ignore
|
543 | 487 | def use_span(
|
544 | 488 | self, span: "Span", end_on_exit: bool = False
|
|
0 commit comments