diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 38ecf1c316c..35fefc3e3f2 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -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, @@ -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: diff --git a/opentelemetry-sdk/tests/trace/test_trace.py b/opentelemetry-sdk/tests/trace/test_trace.py index 0a5c2d349ca..6b9d68e42ba 100644 --- a/opentelemetry-sdk/tests/trace/test_trace.py +++ b/opentelemetry-sdk/tests/trace/test_trace.py @@ -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