Skip to content

Commit

Permalink
Rename DefaultSpan to NonRecordingSpan (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Mar 2, 2021
1 parent dc59139 commit 74e2441
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: 8a367be397a77bd3b09226260f345abf885297b9
CONTRIB_REPO_SHA: 3ceaa0ec08801a8efccee328a805c038f9a7648e

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed `BatchExportSpanProcessor` to `BatchSpanProcessor` and `SimpleExportSpanProcessor` to
`SimpleSpanProcessor`
([#1656])(https://github.com/open-telemetry/opentelemetry-python/pull/1656)
- Rename `DefaultSpan` to `NonRecordingSpan`
([#1661])(https://github.com/open-telemetry/opentelemetry-python/pull/1661)

## [0.18b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.18b0) - 2021-02-16

Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
the operation.
This module provides abstract (i.e. unimplemented) classes required for
tracing, and a concrete no-op :class:`.DefaultSpan` that allows applications
tracing, and a concrete no-op :class:`.NonRecordingSpan` that allows applications
to use the API package alone without a supporting implementation.
To get a tracer, you need to provide the package name from which you are
Expand Down Expand Up @@ -93,7 +93,7 @@
INVALID_SPAN_CONTEXT,
INVALID_SPAN_ID,
INVALID_TRACE_ID,
DefaultSpan,
NonRecordingSpan,
Span,
SpanContext,
TraceFlags,
Expand Down Expand Up @@ -227,7 +227,7 @@ class Tracer(ABC):

# Constant used to represent the current span being used as a parent.
# This is the default behavior when creating spans.
CURRENT_SPAN = DefaultSpan(INVALID_SPAN_CONTEXT)
CURRENT_SPAN = NonRecordingSpan(INVALID_SPAN_CONTEXT)

@abstractmethod
def start_span(
Expand Down Expand Up @@ -473,7 +473,7 @@ def get_tracer_provider() -> TracerProvider:
"INVALID_SPAN_CONTEXT",
"INVALID_SPAN_ID",
"INVALID_TRACE_ID",
"DefaultSpan",
"NonRecordingSpan",
"DefaultTracer",
"DefaultTracerProvider",
"Link",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def extract(
trace_state=tracestate,
)
return trace.set_span_in_context(
trace.DefaultSpan(span_context), context
trace.NonRecordingSpan(span_context), context
)

def inject(
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-api/src/opentelemetry/trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def __repr__(self) -> str:
)


class DefaultSpan(Span):
"""The default Span that is used when no Span implementation is available.
class NonRecordingSpan(Span):
"""The Span that is used when no Span implementation is available.
All operations are no-op except context propagation.
"""
Expand Down Expand Up @@ -532,7 +532,7 @@ def record_exception(
pass

def __repr__(self) -> str:
return "DefaultSpan({!r})".format(self._context)
return "NonRecordingSpan({!r})".format(self._context)


INVALID_SPAN_ID = 0x0000000000000000
Expand All @@ -544,7 +544,7 @@ def __repr__(self) -> str:
trace_flags=DEFAULT_TRACE_OPTIONS,
trace_state=DEFAULT_TRACE_STATE,
)
INVALID_SPAN = DefaultSpan(INVALID_SPAN_CONTEXT)
INVALID_SPAN = NonRecordingSpan(INVALID_SPAN_CONTEXT)


def format_trace_id(trace_id: int) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_propagation(self):
self.assertEqual(span_context.trace_id, self.TRACE_ID)
self.assertEqual(span_context.span_id, self.SPAN_ID)

span = trace.DefaultSpan(span_context)
span = trace.NonRecordingSpan(span_context)
ctx = baggage.set_baggage("key3", "val3")
ctx = baggage.set_baggage("key4", "val4", context=ctx)
ctx = set_span_in_context(span, context=ctx)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/test_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ def test_span(self):
trace.Span() # type:ignore

def test_default_span(self):
span = trace.DefaultSpan(trace.INVALID_SPAN_CONTEXT)
span = trace.NonRecordingSpan(trace.INVALID_SPAN_CONTEXT)
self.assertEqual(span.get_span_context(), trace.INVALID_SPAN_CONTEXT)
self.assertIs(span.is_recording(), False)
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_headers_with_tracestate(self):
)
self.assertTrue(span_context.is_remote)
output = {} # type:typing.Dict[str, str]
span = trace.DefaultSpan(span_context)
span = trace.NonRecordingSpan(span_context)

ctx = trace.set_span_in_context(span)
FORMAT.inject(dict.__setitem__, output, ctx)
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_no_send_empty_tracestate(self):
empty tracestate headers but SHOULD avoid sending them.
"""
output = {} # type:typing.Dict[str, str]
span = trace.DefaultSpan(
span = trace.NonRecordingSpan(
trace.SpanContext(self.TRACE_ID, self.SPAN_ID, is_remote=False)
)
ctx = trace.set_span_in_context(span)
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/trace/test_defaultspan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from opentelemetry import trace


class TestDefaultSpan(unittest.TestCase):
class TestNonRecordingSpan(unittest.TestCase):
def test_ctor(self):
context = trace.SpanContext(
1,
Expand All @@ -26,7 +26,7 @@ def test_ctor(self):
trace_flags=trace.DEFAULT_TRACE_OPTIONS,
trace_state=trace.DEFAULT_TRACE_STATE,
)
span = trace.DefaultSpan(context)
span = trace.NonRecordingSpan(context)
self.assertEqual(context, span.get_span_context())

def test_invalid_span(self):
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/trace/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_get_current_span(self):
be retrievable via get_current_span
"""
self.assertEqual(trace.get_current_span(), trace.INVALID_SPAN)
span = trace.DefaultSpan(trace.INVALID_SPAN_CONTEXT)
span = trace.NonRecordingSpan(trace.INVALID_SPAN_CONTEXT)
ctx = trace.set_span_in_context(span)
token = context.attach(ctx)
try:
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/trace/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_start_as_current_span(self):
self.assertIsInstance(span, trace.Span)

def test_use_span(self):
span = trace.DefaultSpan(trace.INVALID_SPAN_CONTEXT)
span = trace.NonRecordingSpan(trace.INVALID_SPAN_CONTEXT)
with self.tracer.use_span(span):
pass

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def start_span( # pylint: disable=too-many-locals
)
span.start(start_time=start_time, parent_context=context)
else:
span = trace_api.DefaultSpan(context=span_context)
span = trace_api.NonRecordingSpan(context=span_context)
return span

@contextmanager
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/trace/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def _create_parent(
@staticmethod
def _create_parent_span(
trace_flags: trace.TraceFlags, is_remote=False
) -> trace.DefaultSpan:
return trace.DefaultSpan(
) -> trace.NonRecordingSpan:
return trace.NonRecordingSpan(
trace.SpanContext(
0xDEADBEEF,
0xDEADBEF0,
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/trace/test_span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def create_multi_span_processor(
@staticmethod
def create_default_span() -> trace_api.Span:
span_context = trace_api.SpanContext(37, 73, is_remote=False)
return trace_api.DefaultSpan(span_context)
return trace_api.NonRecordingSpan(span_context)

def test_on_start(self):
multi_processor = self.create_multi_span_processor()
Expand Down
10 changes: 6 additions & 4 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ def test_use_span_exception(self):
class TestUseSpanException(Exception):
pass

default_span = trace_api.DefaultSpan(trace_api.INVALID_SPAN_CONTEXT)
default_span = trace_api.NonRecordingSpan(
trace_api.INVALID_SPAN_CONTEXT
)
tracer = new_tracer()
with self.assertRaises(TestUseSpanException):
with tracer.use_span(default_span):
Expand Down Expand Up @@ -182,9 +184,9 @@ def test_sampler_no_sampling(self):
# decides not to sampler
root_span = tracer.start_span(name="root span", context=None)
ctx = trace_api.set_span_in_context(root_span)
self.assertIsInstance(root_span, trace_api.DefaultSpan)
self.assertIsInstance(root_span, trace_api.NonRecordingSpan)
child_span = tracer.start_span(name="child span", context=ctx)
self.assertIsInstance(child_span, trace_api.DefaultSpan)
self.assertIsInstance(child_span, trace_api.NonRecordingSpan)
self.assertEqual(
root_span.get_span_context().trace_flags,
trace_api.TraceFlags.DEFAULT,
Expand All @@ -208,7 +210,7 @@ def test_sampler_with_env(self):

root_span = tracer.start_span(name="root span", context=None)
# Should be no-op
self.assertIsInstance(root_span, trace_api.DefaultSpan)
self.assertIsInstance(root_span, trace_api.NonRecordingSpan)

@mock.patch.dict(
"os.environ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def extract(
options |= trace.TraceFlags.SAMPLED

return trace.set_span_in_context(
trace.DefaultSpan(
trace.NonRecordingSpan(
trace.SpanContext(
# trace an span ids are encoded in hex, so must be converted
trace_id=trace_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def test_inject_empty_context():

@staticmethod
def test_default_span():
"""Make sure propagator does not crash when working with DefaultSpan"""
"""Make sure propagator does not crash when working with NonRecordingSpan"""

class CarrierGetter(DictGetter):
def get(self, carrier, key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def extract(
):
return trace.set_span_in_context(trace.INVALID_SPAN, context)

span = trace.DefaultSpan(
span = trace.NonRecordingSpan(
trace.SpanContext(
trace_id=int(trace_id, 16),
span_id=int(span_id, 16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
from opentelemetry.propagate import get_global_textmap
from opentelemetry.shim.opentracing_shim import util
from opentelemetry.shim.opentracing_shim.version import __version__
from opentelemetry.trace import INVALID_SPAN_CONTEXT, DefaultSpan, Link
from opentelemetry.trace import INVALID_SPAN_CONTEXT, Link, NonRecordingSpan
from opentelemetry.trace import SpanContext as OtelSpanContext
from opentelemetry.trace import Tracer as OtelTracer
from opentelemetry.trace import (
Expand Down Expand Up @@ -633,7 +633,7 @@ def start_span(
# use a `None` parent, which triggers the creation of a new trace.
parent = child_of.unwrap() if child_of else None
if isinstance(parent, OtelSpanContext):
parent = DefaultSpan(parent)
parent = NonRecordingSpan(parent)

parent_span_context = set_span_in_context(parent)

Expand Down Expand Up @@ -684,7 +684,7 @@ def inject(self, span_context, format: object, carrier: object):

propagator = get_global_textmap()

ctx = set_span_in_context(DefaultSpan(span_context.unwrap()))
ctx = set_span_in_context(NonRecordingSpan(span_context.unwrap()))
propagator.inject(type(carrier).__setitem__, carrier, context=ctx)

def extract(self, format: object, carrier: object):
Expand Down
2 changes: 1 addition & 1 deletion tests/util/src/opentelemetry/test/mock_textmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def extract(
return trace.set_span_in_context(trace.INVALID_SPAN)

return trace.set_span_in_context(
trace.DefaultSpan(
trace.NonRecordingSpan(
trace.SpanContext(
trace_id=int(trace_id_list[0]),
span_id=int(span_id_list[0]),
Expand Down

0 comments on commit 74e2441

Please sign in to comment.