Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/instana/span/readable_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __init__(
parent_id: Optional[str] = None,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
attributes: types.Attributes = {},
events: Sequence[Event] = [],
attributes: Optional[types.Attributes] = None,
events: Optional[Sequence[Event]] = None,
status: Optional[Status] = Status(StatusCode.UNSET),
stack: Optional[List] = None,
kind: SpanKind = SpanKind.INTERNAL,
Expand All @@ -68,8 +68,8 @@ def __init__(
if self._start_time and self._end_time
else None
)
self._attributes = attributes if attributes else {}
self._events = events
self._attributes = dict(attributes) if attributes is not None else {}
self._events = list(events) if events is not None else []
self._parent_id = parent_id
self._status = status
self.stack = stack
Expand Down
4 changes: 2 additions & 2 deletions src/instana/span/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __init__(
parent_id: Optional[str] = None,
start_time: Optional[int] = None,
end_time: Optional[int] = None,
attributes: types.Attributes = {},
events: Sequence[Event] = [],
attributes: Optional[types.Attributes] = None,
events: Optional[Sequence[Event]] = None,
status: Optional[Status] = Status(StatusCode.UNSET),
kind: SpanKind = SpanKind.INTERNAL,
) -> None:
Expand Down
30 changes: 28 additions & 2 deletions tests/span/test_span.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class TestSpan:
def _resource(self) -> Generator[None, None, None]:
self.span = None
yield
if isinstance(self.span, InstanaSpan):
self.span.events.clear()

def test_span_default(
self,
Expand Down Expand Up @@ -928,3 +926,31 @@ def test_span_duration(
assert isinstance(self.span.duration, int)
assert self.span.duration > 0
assert self.span.duration == (timestamp_end - self.span.start_time)

def test_spans_do_not_share_events_list(
self,
span_context: SpanContext,
span_processor: StanRecorder,
) -> None:
span_a = InstanaSpan("span-a", span_context, span_processor)
span_b = InstanaSpan("span-b", span_context, span_processor)

span_a.add_event(name="event-a", attributes={"message": "msg"})

assert len(span_a.events) == 1
assert len(span_b.events) == 0
assert span_a.events is not span_b.events

def test_spans_do_not_share_attributes(
self,
span_context: SpanContext,
span_processor: StanRecorder,
) -> None:
span_a = InstanaSpan("span-a", span_context, span_processor)
span_b = InstanaSpan("span-b", span_context, span_processor)

span_a.set_attribute("key_a", "val_a")

assert "key_a" in span_a.attributes
assert "key_a" not in span_b.attributes
assert span_a.attributes is not span_b.attributes
2 changes: 0 additions & 2 deletions tests/span/test_span_stack_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class TestSpanStackTrace:
def _resource(self) -> Generator[None, None, None]:
self.span = None
yield
if isinstance(self.span, InstanaSpan):
self.span.events.clear()

def test_add_stack_hard_limit(
self,
Expand Down
Loading