Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadableSpan events and links now return a tuple #2215

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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