Skip to content

Commit

Permalink
ReadableSpan events and links now return a tuple (#2215)
Browse files Browse the repository at this point in the history
* ReadableSpan events and links now return a tuple

Removed MappingProxy since events and links are not mappings

Signed-off-by: Ted Kern <tkern@arnatious.com>

* fix lint

Signed-off-by: Ted Kern <tkern@arnatious.com>

* fix lint

* fix lint

Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
Co-authored-by: Leighton Chen <lechen@microsoft.com>
  • Loading branch information
3 people committed Oct 22, 2021
1 parent 67d65ba commit a002f7a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.6.1-0.25b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.6.1-0.25b1) - 2021-10-18

- 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
23 changes: 23 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,29 @@ 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 a002f7a

Please sign in to comment.