Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def is_valid(self) -> bool:
"""Get whether this `SpanContext` is valid.
A `SpanContext` is said to be invalid if its trace ID or span ID is
invalid (i.e. ``0``).
Returns:
True if the `SpanContext` is valid, false otherwise.
"""
return (
self.trace_id != INVALID_TRACE_ID
and self.span_id != INVALID_SPAN_ID
)
class DefaultSpan(Span):
"""The default Span that is used when no Span implementation is available.
All operations are no-op except context propagation.
"""
def __init__(self, context: "SpanContext") -> None:
self._context = context
def get_context(self) -> "SpanContext":
return self._context
def is_recording_events(self) -> bool:
return False
INVALID_SPAN_ID = 0x0000000000000000
instrumenting library. Usually this should be the same as
``pkg_resources.get_distribution(instrumenting_library_name).version``.
"""
return Tracer()
class Tracer:
"""Handles span creation and in-process context propagation.
This class provides methods for manipulating the context, creating spans,
and controlling spans' lifecycles.
"""
# Constant used to represent the current span being used as a parent.
# This is the default behavior when creating spans.
CURRENT_SPAN = Span()
def get_current_span(self) -> "Span":
"""Gets the currently active span from the context.
If there is no current span, return a placeholder span with an invalid
context.
Returns:
The currently active :class:`.Span`, or a placeholder span with an
invalid :class:`.SpanContext`.
"""
# pylint: disable=no-self-use
return INVALID_SPAN
def start_span(
self,