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

Signed-off-by: Ted Kern <[email protected]>
  • Loading branch information
Arnatious committed Oct 18, 2021
1 parent ea00608 commit 48faadb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



- Fix ReadableSpan property types attempting to create a mapping from a list
([#2215](https://github.com/open-telemetry/opentelemetry-python/pull/2215))
- Upgrade GRPC/protobuf related dependency and regenerate otlp protobufs
([#2201](https://github.com/open-telemetry/opentelemetry-python/pull/2201))
- Propagation: only warn about oversized baggage headers when headers exist
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 48faadb

Please sign in to comment.