Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a002f7a

Browse files
Arnatiousocelotllzchen
authored
ReadableSpan events and links now return a tuple (open-telemetry#2215)
* ReadableSpan events and links now return a tuple Removed MappingProxy since events and links are not mappings Signed-off-by: Ted Kern <[email protected]> * fix lint Signed-off-by: Ted Kern <[email protected]> * fix lint * fix lint Co-authored-by: Diego Hurtado <[email protected]> Co-authored-by: Leighton Chen <[email protected]>
1 parent 67d65ba commit a002f7a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

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

14+
- Fix ReadableSpan property types attempting to create a mapping from a list
15+
([#2215](https://github.com/open-telemetry/opentelemetry-python/pull/2215))
1416
- Upgrade GRPC/protobuf related dependency and regenerate otlp protobufs
1517
([#2201](https://github.com/open-telemetry/opentelemetry-python/pull/2201))
1618
- Propagation: only warn about oversized baggage headers when headers exist

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(
350350
parent: Optional[trace_api.SpanContext] = None,
351351
resource: Resource = Resource.create({}),
352352
attributes: types.Attributes = None,
353-
events: Sequence[Event] = None,
353+
events: Sequence[Event] = (),
354354
links: Sequence[trace_api.Link] = (),
355355
kind: trace_api.SpanKind = trace_api.SpanKind.INTERNAL,
356356
instrumentation_info: InstrumentationInfo = None,
@@ -426,11 +426,11 @@ def attributes(self) -> types.Attributes:
426426

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

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

435435
@property
436436
def resource(self) -> Resource:

opentelemetry-sdk/tests/trace/test_trace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,29 @@ def test_surplus_span_attributes(self):
569569
self.assertEqual(len(root.attributes), max_attrs)
570570

571571

572+
class TestReadableSpan(unittest.TestCase):
573+
def test_links(self):
574+
span = trace.ReadableSpan()
575+
self.assertEqual(span.links, ())
576+
577+
span = trace.ReadableSpan(
578+
links=[trace_api.Link(context=trace_api.INVALID_SPAN_CONTEXT)] * 2,
579+
)
580+
self.assertEqual(len(span.links), 2)
581+
for link in span.links:
582+
self.assertFalse(link.context.is_valid)
583+
584+
def test_events(self):
585+
span = trace.ReadableSpan()
586+
self.assertEqual(span.events, ())
587+
events = [
588+
trace.Event("foo1", {"bar1": "baz1"}),
589+
trace.Event("foo2", {"bar2": "baz2"}),
590+
]
591+
span = trace.ReadableSpan(events=events)
592+
self.assertEqual(span.events, tuple(events))
593+
594+
572595
class TestSpan(unittest.TestCase):
573596
# pylint: disable=too-many-public-methods
574597

0 commit comments

Comments
 (0)