Skip to content

Commit

Permalink
ReadableSpan events and links now return a tuple
Browse files Browse the repository at this point in the history
Removed MappingProxy since events and links are not mappings
  • Loading branch information
Arnatious committed Oct 16, 2021
1 parent 18b5cb0 commit dd49d29
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Expand Up @@ -350,7 +350,7 @@ def __init__(
parent: Optional[trace_api.SpanContext] = None,
resource: Resource = Resource.create({}),
attributes: types.Attributes = None,
events: Sequence[Event] = None,
events: Sequence[Event] = (),
links: Sequence[trace_api.Link] = (),
kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL,
instrumentation_info: InstrumentationInfo = None,
Expand Down Expand Up @@ -426,11 +426,11 @@ def attributes(self) -> types.Attributes:

@property
def events(self) -> Sequence[Event]:
return MappingProxyType(self._events)
return tuple(event for event in self._events)

@property
def links(self) -> Sequence[trace_api.Link]:
return MappingProxyType(self._links)
return tuple(link for link in self._links)

@property
def resource(self) -> Resource:
Expand Down
26 changes: 26 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Expand Up @@ -569,6 +569,32 @@ def test_surplus_span_attributes(self):
self.assertEqual(len(root.attributes), max_attrs)


class TestReadableSpan(unittest.TestCase):
def test_links(self):
span = trace.ReadableSpan()
self.assertEqual(span.links, ())

span = trace.ReadableSpan(
links=[trace_api.Link(context=trace_api.INVALID_SPAN_CONTEXT)] * 2,
)
self.assertEqual(len(span.links), 2)
for link in span.links:
self.assertFalse(link.context.is_valid)

def test_events(self):
span = trace.ReadableSpan()
self.assertEqual(span.events, ())

events = [
trace.Event('foo1', {'bar1': 'baz1'}),
trace.Event('foo2', {'bar2': 'baz2'}),
]
span = trace.ReadableSpan(
events=events
)
self.assertEqual(span.events, tuple(events))


class TestSpan(unittest.TestCase):
# pylint: disable=too-many-public-methods

Expand Down

0 comments on commit dd49d29

Please sign in to comment.